STM32F103 IAP

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
kdsouza
Posts: 14
Joined: Thu Jul 02, 2015 3:26 pm
Has thanked: 1 time

STM32F103 IAP

Post by kdsouza »

I have an STM32F103RG with 1Mb Flash Size.
I have a UART Communication modem connected to it.
Can i send a firmware (.HEX or .BIN) to the MicroController via the radio and verify check-sum & integrity, on sucess the microcontroller saves the file into a SD Card(via SPI) or internal flash and then restarts itself and updates the user-space code by flashing itself reading from the flash location or the sD card?

Can something like this be done or an external MCU is required to carry out the flashing?

The purpose is the microcontroller and radio will be sitting at a remote location and i need a way to change the microcontroller's firmware by sending it a firmware update file remotely. So i can send the file via the radio, the uC saves the file sets an internal flag and reboots into a special mode where it replaces its internal firmware with the new one ( read from SD card or internal flash).

My code size is 100kb and flash size of the controller is 1mb.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F103 IAP

Post by Giovanni »

Very complex because:

1) Flashing requires to execute from RAM.
2) While executing from RAM all IRQs must be disabled because vectors point to flash.
3) Disabling IRQs creates problems to the driver and the RTOS, so drivers must be stopped.
4) You don't have the whole image in RAM so you need to enter and exit the RAM code repeatedly, starting/stopping drivers each time.

An external RAM able to hold the whole image to be programmed would help greatly.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F103 IAP

Post by Giovanni »

Another solution would be creating a bootloader that moves itself entirely in RAM, it could use ChibiOS too.

Giovanni
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: STM32F103 IAP

Post by mobyfab »

Giovanni wrote:Very complex because:

1) Flashing requires to execute from RAM.
2) While executing from RAM all IRQs must be disabled because vectors point to flash.
3) Disabling IRQs creates problems to the driver and the RTOS, so drivers must be stopped.
4) You don't have the whole image in RAM so you need to enter and exit the RAM code repeatedly, starting/stopping drivers each time.

An external RAM able to hold the whole image to be programmed would help greatly.

Giovanni


Hi,

I do IAP over USB from flash, works fine. (on an F303)
You can have all the code in flash and the data in a ram buffer.
I don't disable any IRQ.

I only moved some routines to ram to speed things up a little.
Vectors table being in flash is not a problem either.

This assumes you have a bootloader, or are writing somewhere else than the current program like an SD card.
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: STM32F103 IAP

Post by rew »

There are two parts to this question.

Can you download stuff over the radio, check it and save it to a local SD card? Yes, absolutely!

The other problem is flashing the image now that it's on local SD card. IMHO, that shouldn't be too much of a problem either.

The one thing that you don't want however is that your system in the field gets "stuck". I would for sure build a "bootloader" kind of application that would do the reflashing. IF you can't run that from say "the first 64k of flash", You'll have to write a bootloader-booter. copy the first 64K to RAM, set the IRQ vectors to use RAM, and jump to RAM. Then: read-sdcard, write-data-to-flash. Repeat.

On the processors where I tried writing to flash, the chip specifies that the CPU will halt if it does something with the flash that the flash can't handle while writing new data. That might throw chibios timing a bit off, but I don't think that things would crash.

The "unable to relocate vector table" problem applies to Cortex-M0 devices. That's F0 and probably L0 as well. But F1xx is cortex M3 and as far as I know, that has the VTOR register (0xe000ed08. http://infocenter.arm.com/help/index.js ... eijba.html )
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F103 IAP

Post by Giovanni »

L0 is an M0+, it can relocate the table.

Giovanni
Post Reply