Hello everyone,I'm fiddling with the RP2040 in bare metal for fun and study. I have implemented a simple function that prints a message on the openocd terminal via semihosting:
void semihosting_write(const char *string, uint16_t len) { uint32_t args[3] = {1, (uint32_t)string, len}; invoke_semihosting(SYS_WRITE, args); } static void invoke_semihosting(uint32_t reason, uint32_t *args) { asm volatile("mov r0, %[reason] \n" "mov r1, %[args]\n" "bkpt 0xAB \n" : /* outputs */ : [reason] "r"(reason), [args] "r"(args) /* inputs */ : "r0", "r1" /* clobber */ ); }
My issue is that this code works as long as the optimization level is either `-O0` or `-Og`; as soon as I raise it to `-O1` the messages aren't delivered anymore. The application keeps going, but no log is shown on openocd.I've stepped through the assembly code and in both cases `bkpt` is executed with the correct code and the right parameters in `r0` and `r1`. What could be the issue?