cancel
Showing results for 
Search instead for 
Did you mean: 

[L476RG]could not assign flash memory address to functions for the purpose of upgrade firmware

adam.wu
Associate II

In the firmware we have some upgrade functions/data, if we want to update the firmware, we have to make sure those upgrade functions/data will not be erased . So I edit Debug_STM32L476RG_FLASH.ld file, and change

FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1024K
  RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 96K
  RAM2 (rw)       : ORIGIN = 0x10000000, LENGTH = 32K
  MEMORY_B1 (rx)  : ORIGIN = 0x60000000, LENGTH = 0K

to

FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 768K
  UPGRADE_VAR (rx) : ORIGIN = 0x080C0000, LENGTH = 128K 
  UPGRADE_FUN (rx): ORIGIN = 0x080E0000, LENGTH = 128K  
  RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 96K
  RAM2 (rw)       : ORIGIN = 0x10000000, LENGTH = 32K
  MEMORY_B1 (rx)  : ORIGIN = 0x60000000, LENGTH = 0K

, I just inserted two memory regions for the upgrade use.

then I also added the following sections in this file.

.crc_table :
  {
    PROVIDE_HIDDEN (__crc_table_start = .);
    KEEP (*(SORT(.crc_table.*)))
    KEEP (*(.crc_table*))
    PROVIDE_HIDDEN (__crc_table_end = .);
  } >UPGRADE_VAR
  
  
  .upgrade :
  {
      PROVIDE_HIDDEN (__upgrade_start = .);
    KEEP (*(SORT(.upgrade.*)))
    KEEP (*(.upgrade*))
    PROVIDE_HIDDEN (__upgrade_end = .);
  
  } > UPGRADE_FUN

also, in my firmware I added attribute for this flash memory distribution:

__attribute__((section(".crc_table"))) static const unsigned int crctable[]={
...
}
__attribute__((section(".upgrade"))) unsigned int crc_cal(unsigned int msg[],int len){
...
}
__attribute__((section(".upgrade"))) short upgrade_firmware(__uint8_t *input){
...
}

Now the problem is: the build on Atollic TrueStudio is succesfull: please see the following build analyzer results0690X000009Z4OiQAK.png

However, when you run the firmware code on TrueStudio, it will show you :

Failure at line:13 in 'Target Software Startup Scripts'. Please edit the debug configuration setting.

I googled and some people mentioned it is a version problem, https://forum.atollic.com/viewtopic.php?t=1382, I downgraded TrueStudio to 9.0.0 tried this but it has "error in initializing st-link device" error.....

3 REPLIES 3

>>Failure at line:13 in 'Target Software Startup Scripts'. Please edit the debug configuration setting.

And what's that script look like?

I'm not sure how the mechanics of the update/upgrade work. You'd probably do better partitioning the memory so the linker doesn't know about the loader, and putting a loader in the front of the flash where it can check/validate the firmware images before jumping to them, and providing a recovery method when it can't.

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

thanks, we temporary eliminated this problem, in  https://www.st.com/resource/en/datasheet/stm32l476rg.pdf, Chap 3.4, it mentions"The Flash memory is divided into two banks allowing readwhile-write operations. This feature allows to perform a read operation from one bank while an erase or program operation is performed to the other bank. ", here the flash use bank1&bank2 (each bank is 512k), it is possible flash do read/ erase at bank2 while upgrade_var & upgrade_fun is also doing bank2 with different operations (such as flash does reading but upgrad_var doing erasing) ? so we limit flash into bank1 only, and this run error disappear.

This makes me worried about my firmware, it is also possible my upgrad_var does reading while upgrade_fun does erasing!!!!!!!!!!!!, anbody has a final solution for this? thanks

Well reading simply blocks while any erase/write occurs within the same bank.

Like I said I don't really get the functionality you have in these small FUN/VAR areas. I tend to keep configuration pages, loader and application completely separate, and don't let the linker touch them. You can avoid stalling by having your update routines (as associated call tree and interrupts, etc) in RAM

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