cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 and IAP

jowakar122
Associate III

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. 

8 REPLIES 8

Have you seen Application note AN4657, STM32 in-application programming (IAP) using the USART:

https://www.st.com/resource/en/application_note/an4657-stm32-inapplication-programming-iap-using-the-usart-stmicroelectronics.pdf

 

@Andrew Neil  

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.

 

 

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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. Annotation 2024-12-21 110733.png

 

Pavel A.
Evangelist III

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.

 

What I changed was the UART. Earlier I used USART2 and later on I wanted to use USART1, so made that changes in my code accordingly but neither did it worked with USART1 nor with USART2 afterwards. 

About your suggestion, I will certainly work on that.

Any suggestion regarding this would be great help. I have made the changes so that the flash is not touched but every time I am trying to receive the file the code gets stuck in the while loop. 

the code gets stuck in the while loop

Check for UART RX overrun. Disable it in initialization if the U(S)ART supports this. 

Make a small test for the UART only.