2024-12-20 04:49 AM - last edited on 2024-12-20 04:50 AM by SofLit
Hello,
I have been trying to implement IAP in my device. But my code gets stuck in "UART_WaitOnFlagUntilTimeout". For once I was able to transfer the binary file of the new user application but later whenever I am trying to send the binary file it is getting stuck. It doesn't even show any debug error message.
I took reference from this: https://github.com/stm32-hotspot/STM32G0xx_IAP/tree/main
I have kept the IAP main at starting address which is 0x08000000 and my user application at 0x08008000.
2024-12-20 04:56 AM
Have you seen Application note AN4657, STM32 in-application programming (IAP) using the USART:
2024-12-20 05:01 AM
Yes I have referred the application note. But how it is suppose to help me with the problem. Moreover, I have made sure multiple times about the basic things need for IAP.
2024-12-20 08:29 AM - edited 2024-12-20 08:34 AM
The Cortex-M0+ has a SCB->VTOR, double check code in SystemInit() points to the same compiled basis as the binary image was linked for. i tend to prefer using linker symbols over defines.
Don't disable_irq() at transfer, the other end doesn't enable them. It could, but the MCU doesn't start with them disabled.
Don't transfer control from an IRQHandler or related HAL callbacks from interrupt context, the MCU/NVIC context won't un-stack properly if you just jump off to a new image and not return. Net result will be blocked interrupts at current premption level
Preferably explictly load the new SP at Reset_Handler, or use assembler for control transfer. Watch for local/auto variables holding data or entry points when you change the stack frame / context. Inspect generated code, or make some simple vectoring code in startup.s
Don't have a bunch of peripherals up and firing interrupts, none of this context is handled across the transition.
Instrument Error_Handler() and HardFault_Handler(), silent death in a while(1) is unhelpful for any technical support efforts.
2024-12-20 09:38 PM
As I am storing the user application at 0x08008000 I have made the necessary changes in the system_stm32g0xx.c file regarding vector offset address, I have kept is 0x00008000. Initially when my device resets there is no instance of transferring control as I have store the IAP at starting address.
2024-12-21 04:50 PM - edited 2024-12-21 04:51 PM
If something worked before but does not work now: find what has changed, roll back, compare, move by small steps.
> my code gets stuck in "UART_WaitOnFlagUntilTimeout"
Divide and conquer. First, test only receiving the file, without touching the flash. Verify it works well (use CRC or something better)
Once the UART part is working, test write to the flash from preloaded data (in other flash location or RAM).
Once both parts are working, combine them together.