2012-06-26 07:26 AM
Hi,
My microcontroller is a STM32F103CB.I followed the AN2557 to do an IAP in my software. Everything works fine but now I would like to do something like a dual bank features.I can flash two firmwares at two different address in flash (for example, one @0x8003000 and the second @0x8006000) but when my IAP software starts (@0x800 0000), if I do the classical test ( if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000) ) the first bank will be still OK, so I never start the firmware in the second flash.Is there a way to set an option to know which ''bank'' is activated?Is there a way to modify by software the start address (modify the 0x800 0000 address)?I hope my request is enought clear!!Regards, #flash #groundhog-day #start-address #iap #stm322012-06-26 07:47 AM
No, not really. You can change the BOOTx pins to change whether is boots from different addresses, ie FLASH (0x08000000), ROM (0x1FFFF000) or RAM (0x20000000)
You can just add a very small amount of code in your boot loader to vector to whatever block or bank of code you want. Typically a boot loader would try to validate code before jumping to it. I'd put this stuff in the Reset_Vector code path.2012-06-27 12:27 AM
Thanks for the answer. I will see how I can do this. What do you mean exactly by : ''I'd put this stuff in the Reset_Vector code path''. Where can I find this code?
''You can just add a very small amount of code in your boot loader'' : That's what I try to do but I need to have the information of the ''bank'' to use even if a reset is done or the power supply is switched off/on. Can I keep in ROM this information (for example : int valideBank = 0 or 1)?2012-06-27 04:00 AM
The reset code is typically in the startup_stm32fxxx.s file, or equivalent.
If you have multiple applications you'd need to store which in an area of FLASH or EEPROM. To validate an image as you boot you'd typically place a couple of signatures/markers in the image which the boot loader can check, and a checksum/crc at the end which confirms the image is complete and correct. This will catch if it was written/received properly, and if the flash array fails over time.2012-06-28 01:11 AM
I'm sorry but I don't known how I can add a signature in the firmware (image) to be read by the bootloader. Can you help me?
2012-06-30 06:57 AM
You will have three partitions
1st bootloader2nd Firmware Version A3rd Firmware Version BEach partition starts with the vector table __Vectors (see startup_stm32fxxx.s).Append direct behind the vector table a signature, EXPORT __Vectors__Vectors.........__Vectors_End EXPORT _Signature_Signature DCB ''...'',0Now the check is simpleextern uint32_t *__Vectors, _Signature;uint32_t * FirmwareASignature = StartAdressFirmwareA + (_Signature - _Vectors);uint32_t * FirmwareBSignature = StartAdressFirmwareB + (_Signature - _Vectors);if (FirmwareASignature > FirmwareBSignature) Start FirmwareAelse Start FirmwareBHolger2012-06-30 07:31 AM
I'm sorry but I don't known how I can add a signature in the firmware (image) to be read by the bootloader. Can you help me?
You could use empty vectors to provide pointers or sizes, ideally permitting a fixed location the boot loader can easily find. You could also search for strings/structures. static const char sig[] = ''Foo Bar Corp.''; You can add things via the linker script, or definition files. You might also need to consider post link processing to handle and repackage a hex/bin image into a consistent form, adding sizing, signature and checksumming data. This might also include making the image a fixed size, and defining a fill character. This step could also potentially search the image for some special structures, encrypt or sign various components, and doing anything beyond the scope/capabilities of the linker. I'd consider this to be some basic ''stdio'' file handling and manipulation, but you'd need to grasp the representation of the code/data, and how the CPU and boot loader interact with it.2012-07-03 01:44 AM
Thanks for your answer. I will try it.
I also added at the beginning of the generated binary firmware a fixed bytes sized with the name, the date and the version of the firmware with a script.I modify the vector_table address to take in account these information datas at the beginning.It works fine at the moment.2012-07-18 01:17 AM
I testing AN 2557 to use it update Firmware from FPT Server. I load Bin file into address 0x0800300 ok (see by STM32 ST-LINK Utility). And I set VECT_TAB_OFFSET 0x3000 .But when I run, new Firmware not work. I also tested wirh NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x08003000) .
Please help me.thank you verry much!Regards.
2012-07-18 04:24 AM
If the code is built/linked for the wrong address it will not work. You will need to insure that the linker script or scatter file reflect the address where you plan to place the code.