Fix program upload not working properly after first upload

This commit is contained in:
shylie 2026-05-26 06:51:30 -04:00
parent 034122ed92
commit b82b1311f4
Signed by: shylie
GPG Key ID: 20C8D70580687D9D
4 changed files with 22 additions and 40 deletions

View File

@ -4,13 +4,15 @@ int main(void)
{
uint8_t value = 0;
card_os_put_rect((card_os_rect){ 0, 0, 0, 0, 0, 240, 320 });
card_os_put_rect((card_os_rect){
.r = 0xFF, .g = 0xFF, .b = 0xFF, .x = 60, .y = 80, .w = 120, .h = 160 });
while (value < 250)
{
card_os_put_rect((card_os_rect){
.r = value++, .g = 0, .b = 0, .x = 0, .y = 0, .w = 240, .h = 320 });
card_os_put_rect((card_os_rect){
.r = 0xFF, .g = 0xFF, .b = 0xFF, .x = 60, .y = 80, .w = 60, .h = 60 });
.r = value++, .g = 0, .b = 0, .x = 0, .y = 0, .w = 60, .h = 60 });
}
return 0;

View File

@ -5,7 +5,6 @@
typedef enum
{
OS_CMD_TERMINATE_PROGRAM,
OS_CMD_SBRK,
OS_CMD_DRAW_RECT
} os_command;

View File

@ -13,13 +13,7 @@ ssize_t _read(int file, void* ptr, size_t len) { return 0; }
ssize_t _write(int file, const void* ptr, size_t len) { return len; }
void _exit(int status)
{
oscall(&(os_message){ .command = OS_CMD_TERMINATE_PROGRAM, .data = NULL });
while (1)
{
}
}
void _exit(int status) {}
void* _sbrk(ptrdiff_t incr)
{
@ -37,12 +31,12 @@ extern uint8_t __bss_start__;
extern uint8_t __bss_end__;
int main(void);
__attribute__((section(".start"))) void _start(void)
__attribute__((section(".start"))) int _start(void)
{
for (uint8_t* p = &__bss_start__; p < &__bss_end__; p++)
{
*p = 0;
}
_exit(main());
return main();
}

View File

@ -89,14 +89,15 @@ void tud_vendor_rx_cb(uint8_t itf, const uint8_t* buffer, uint16_t bufsize)
case RECV_LOW8_LENGTH:
program_length |= buffer[bufidx];
recv_status = RECV_PROGRAM;
memset(&__user_ram_start, 0, 0x10000);
break;
case RECV_PROGRAM:
(&__user_ram_start)[program_write_index++] = buffer[bufidx];
if (program_write_index == program_length)
{
__dmb();
user_program = (user_program_fn)((uintptr_t)&__user_ram_start | 1);
__dmb();
__sev();
recv_status = RECV_WAITING;
}
@ -113,25 +114,19 @@ static volatile os_ring_buffer core1_buffer
void core1_entry(void)
{
while (!user_program)
{
__wfe();
}
user_program();
// send message to terminate core 1
int index = -1;
while (index < 0)
{
index = os_ring_buffer_write(&core1_buffer,
&(os_message){ .command = 1, .data = NULL });
}
multicore_fifo_push_blocking(index);
// stall until reset
while (true)
{
while (!user_program)
{
__wfe();
}
user_program_fn copied = user_program;
user_program = NULL;
__dmb();
__sev();
int retrval = copied();
}
}
@ -191,14 +186,6 @@ void os_handle_message(const os_message* msg, os_message* out)
{
switch (msg->command)
{
case OS_CMD_TERMINATE_PROGRAM:
multicore_fifo_drain();
multicore_reset_core1();
__dmb();
user_program = NULL;
__sev();
multicore_launch_core1(core1_entry);
break;
case OS_CMD_SBRK:
os_sbrk(msg->data, &out->data);
break;