Hello,
I am having trouble entering sleep mode with the STM32F103 and RL-RTX. I am expecting the processor to halt indefinitely when I call the following code:
printf("calling __WFI();\r\n"); // enter low power mode: Request Wait For System Interrupt to wake uC up __wfi(); printf("Exiting sleep mode\r\n");
The problem is that after "__wfi();" is called is automatically goes to the next statement: "printf("Exiting sleep mode\r\n");".
It almost seems like something is waking the processor from sleep mode right away or it is not going into sleep.
I would expect that the CPU halts at __wfi() until an interrupt is triggered.
If your printouts are interrupt-driven, then you will get interrupts when the UART is ready for more data - so your printf() calls will make the sleep attempt fail.
The UART is polled. It is taken from the example of Retarget.c
int sendchar (int c) { if (c == '\n') { while (!(USARTx->SR & USART_FLAG_TXE)); USARTx->DR = 0x0D; } while (!(USARTx->SR & USART_FLAG_TXE)); USARTx->DR = (c & 0x1FF); return (c); }
This basically means that the __WFI(); instruction will not get called until all characters are sent out.