cancel
Showing results for 
Search instead for 
Did you mean: 

Remote Firmware Upgrade ... any help?

al-fayez-bs
Associate II
Posted on April 20, 2011 at 15:35

Remote Firmware Upgrade ... any help?

11 REPLIES 11
trevor23
Associate III
Posted on May 17, 2011 at 14:32

Hi, You need to study IAP application note AN2557. Most of what you need is explained there.

Posted on May 17, 2011 at 14:32

You'll need to write a small bootloader, with a SPI driver, and the flashing code. You'll pull the data out of the SPI chip in a similar fashion to the way you put data there in the first place, and then write data to the flash within the STM32 at least 16-bits at a time.

Personally, I've used GSM to pull a firmware over the air using HTTP, storing the new copy in a high region of the STM32's flash memory, and had the part reboot and reprogram the application portion of my device.

I would concur with Trevor. First learn how others do it, then reimplement it in a manner suitable for your project. I would also suggests reviewing the flash programming manual/app note.

ST maintains a list of consultants that can do these kinds of things.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
al-fayez-bs
Associate II
Posted on May 17, 2011 at 14:32

Thank you Trevor & Clive for your fast response.

actually, I did 2 small applications:
  •     App1: turns LED1 on, and programmed at address 0x0800 0000
  •     App2: turns LED2 on, and programmed at address 0x0800 6000

when I run the code it start with app1 and turns LED1, jumping successfully to app2 and turns LED2.

what I want to do is:

 

at address 0x0800 0000: I will implement my bootloader to check for the ReadyFlag.
  • if the flag is 0, I will do nothing. i.e. jump directly to address 0x0800 6000 which actuaclly contains the current firmware.
  • if the flag is 1, I want to copy from SPI to address 0x0800 6000 , reset flag and restart.

My question is how to do what is written in read.

(I'll start reading Trevor's reference and see if I can do something)

Thanks & sorry for bothering you.
Posted on May 17, 2011 at 14:32

The ''Copy'' you talk about is a two step process, you must read data from your SPI device, and then you must write it to the flash memory in the STM32. Before you can write to the flash, you must erase pages of flash first. You must implement code to do this.

Now typically, you'd have a flash routine that can take a block of data in RAM, and write that into FLASH. If the available space is short you might do this repetitively in 32 or 128 byte blocks.

This could also be done by reading 16-bits at a time from an SPI flash device as a source, but probably not very efficiently.

Earlier versions of the ST Firmware library (on IAR/Keil installs) has example code for interfacing with the SPI bus.

Learn how to read from your SPI device.

Learn how to program the STM32 flash.

Combine this knowledge.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
trevor23
Associate III
Posted on May 17, 2011 at 14:32

Which SPI flash are you using? When you refer to ''flag'' what exactly is this? I do something very similar. I have a firmware header which contains a magic number in the first few bytes. This makes it very quick for my bootloader to check if firmware is ''waiting'' in SPI flash to be loaded to STM32 flash i.e. if the first few bytes are the magic number I continue to validate firmware in SPI flash and then load it to STM32 flash if valid (header CRC used to validate). Once loaded to STM32 flash (and CRC checked) I zero the firmware header in SPI flash (and thus the magic number is now invalid) and jump to the new application code.

al-fayez-bs
Associate II
Posted on May 17, 2011 at 14:32

Back ...

clive .. thank you for your support.

Now I can read from SPI whatever I need & write it to STM32 Flash after erasing pages.

Now .. I want to read data I've wrote in STM32 Flash for validation .. How can I perfom a read operation from flash? 

Trevor .. I'm using M25PE20 SPI Flash.

& the flag I'm talking about is to determine whether I need to do my upgrade and start the copy process or just boot from my current firmware. (flag = 1 if I have the image ready in SPI and the time&date occured for the upgrade process). Regarding you firmware header, I may use your method or use the optional bytes in the STM32 flash.

May be I can ask you how to read data from STM32 flash?

Thank you for your kind support.

Best Regards,
Posted on May 17, 2011 at 14:32

''how to read data from STM32 flash?''

 

You just read it!

Set a pointer to the address you want to read, and read it!

al-fayez-bs
Associate II
Posted on May 17, 2011 at 14:32

Thank you Andrew.

I just found a post from Clive:

------

Reading is just like any other memory, set a pointer to it and read, nothing magic.

u32 *mem = (u32 *)0x08002000;

printf(''%08X\n'', *mem);

Thank you all for your assisstence .. I'll see what I can do :)
trevor23
Associate III
Posted on May 17, 2011 at 14:32

@saf I was wondering more where this ''flag'' exists? In RAM, battery backed RAM, flash, SPI flash etc. ?