cancel
Showing results for 
Search instead for 
Did you mean: 

How to make program start from a customized address?

song
Associate II
Posted on January 08, 2015 at 04:51

I understand this question has been asked before. I searched the forum and view these three threads: 

''How to program the application flash file (hex file) in chosen flash area by using ST-LINK for STM32F0''

''Flash Address setting to write main program starting from specific address''

''How start running STM32 firmware from IROM2 ?''

However, I still have some doubts. For STM32F407, there are 12 flash sectors. If I define the IROM1 address to be 0x080E0000, which is the 12th sector, can I then store data in the first 11 sectors, including sector 0 starting from 0x08000000? From the threads, it seems that I can't because some vectors are located in sector 0. Does it mean I can only use sector 1~11?

#know-your-tools #flash #boot #stm32f4
13 REPLIES 13
Posted on January 08, 2015 at 15:54

Thing is, the processor loads the initial SP and PC from address ZERO, 0x08000000 is mapped there via the BOOTx pins. Sector 0 would need to have 32-bit words committed to getting the processor going, you could use the rest, although honestly I'd use the 16KB for a boot loader so I wouldn't brick the processor.

The reason to use the 16K and 64K sectors is the erase speed. If you need to store lots of data the 128K ones would be fine.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
song
Associate II
Posted on January 13, 2015 at 03:38

Hi, clivel, thanks for the info. I understand sector0 should be preserved for system usage, so it only leaves the question how to save the program to a customized starting address. I am using Keil, so is it true that I only need to define the IROM1 address to be 0x080E0000? Do I also need to set ST-Link Debugger -> Settings -> Flash download?

Posted on January 13, 2015 at 04:31

Correct you'd change the IROM location and size, either via the GUI, or a scatter file. This will define how the linker places the code generated by the compiler. The debugger will take and flash whatever memory it is directed to use.

Some examples to look at would the the IAP (In Application Programming) ones.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
song
Associate II
Posted on January 13, 2015 at 04:54

Hi, clivel, I just did some test. If I keep default address settings, the debugging works normal. However, when I change IROM1 to 0x80E000 and size to 0x20000 (128K), the debugging failed to jump to main entry. I captured the screen and you can see almost all debugging buttons are greyed out. Any idea why and how to solve it?

LR_IROM1 0x080E0000 0x00020000  {    ; load region size_region

  ER_IROM1 0x080E0000 0x00020000  {  ; load address = execution address

   *.o (RESET, +First)

   *(InRoot$$Sections)

   .ANY (+RO)

  }

  RW_IRAM1 0x20000000 0x00020000  {  ; RW data

   .ANY (+RW +ZI)

  }

}

0690X00000602wgQAA.jpg

Posted on January 13, 2015 at 06:31

Yes, you'd need code, or vector entries, at the base of the flash to transfer control to new location.

From the debugger perspective you could assign SP and PC to the appropriate values you could get these from the vectors at the base of your image. You code in SystemInit() would also want to set the vector table address (SCB->VTOR) to point to the new base address.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
song
Associate II
Posted on January 13, 2015 at 08:55

From the post ''How to program the application flash file (hex file) in chosen flash area by using ST-LINK for STM32F0'' and ''Need advices for separating flash memory for STM32F0 and STM32F1'', I understand the code placement is the job of linker. In the linker setting of Keil project, I check ''Use memory layout from Target Dialog''. So other than this, do I need to manually add code to any source file? If yes, would you please advise how to do it? 

Posted on January 13, 2015 at 15:09

And you've probably changed the address in the linker, check the .MAP file to confirm the placement.

The linker address doesn't magically change the silicon in the processor. It does very specific things when it starts, and unless you have to code or table to direct execution to your new location it's not going to go there.

Suggest you brush up on you microprocessor basics, with perhaps one of Joseph Yiu's Cortex-Mx books, and the concepts of compilers, linkers and loaders.

Review the IAP examples which provide a Loader + Application model, where the application code is placed at a higher address.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
childresss
Associate II
Posted on January 14, 2015 at 05:44

Or more competitively at

http://www.abebooks.com/servlet/BookDetailsPL?bi=12422234816&searchurl=tn%3Dcortex-m4%26sts%3Dt

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