Skip to main content
JBond.1
Senior
January 2, 2021
Question

IAP for STM32F103C8T6

  • January 2, 2021
  • 1 reply
  • 2010 views

Hi, does library example of in-application programming (IAP) for STM32F103C8T6 exist?

I would like to load software updates from MicroSD card.

Also as I understand I will need 2 projects? One as bootloader to load software and another as application which will be executed. But in such case how is it possible to debug Application? Is it possible to avoid losing debugging code feature with Keil?

This topic has been closed for replies.

1 reply

Tesla DeLorean
Guru
January 2, 2021

Pretty sure the HAL and SPL had IAP examples of various forms. The Nucleo BSP has SPI code for SDCard on the Adafruit shield, if not for the F1 definitely others that would port.

Debugging is going to be a little more challenging, Keil can step through the transition, and the disassembly view can be used to understand what's happening. The application can be debugged provided the loader is functioning, it will "Run to main()" so should still work. The loader can also be debugged so it works properly. Write code robustly, and output telemetry to understand what's happening without sticking your fingers in the gears. Debug one thing at the source level at a time.

Have effective output on Hard Fault and Error Handlers so you can understand why things die or fail.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
JBond.1
JBond.1Author
Senior
January 3, 2021

Its interesting that no one did this already. STM32F103 is quite popular chip. Anyway here is my attempt do to it. I am trying to port it from original ST example.

Bootloader project:

https://github.com/JuMalIO/STM32F103-IAP-Bootloader

Application project:

https://github.com/JuMalIO/STM32F103-IAP-Application

Bootloader seems to work and writes "update.bin" from MicroSD card correctly. After writing application to flash it executes it. Application should blink PC13 LED with TIM2, but LED lights up and never blinks, I guess application crashes? How to debug it?

I guess my problem is that I need somehow free all resources which bootloader uses (SPI1, FAT_FS ram)? How to do that?

In other bootloader examples I see NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x3800); function. Maybe I need to execute it too? But I cant find this function in new STM32 HAL drivers.

Any ideas?

Tesla DeLorean
Guru
January 3, 2021

>>Its interesting that no one did this already.

That's a particularly shallow interpretation of things. These parts are over 12 years old, most professional programmers just get the job done and move on, and stuff isn't pushed on to public repositories.

>>I guess my problem is that I need somehow free all resources which bootloader uses (SPI1, FAT_FS ram)? How to do that?

The RAM gets reallocated by the linker the app should be freestanding in that regard.

It will however inherit the peripheral and interrupt mess you leave. You should put the peripherals into a safe state, by disabling individual interrupts, especially things like SysTick.

If the clocks and RCC/PLL are already up there's no need to tear these down and do-over.

To debug the app, have the loader transfer control immediately, and have Keil run to main()

Have the loader check the app integrity, and don't update it unless the image is corrupt, or you have a user initiated update, ie a button, or a special reset from the app flagging a request to update.

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