2015-01-07 07:51 PM
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 #stm32f42015-01-08 06:54 AM
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.2015-01-12 06:38 PM
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?
2015-01-12 07:31 PM
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.2015-01-12 07:54 PM
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) }}2015-01-12 09:31 PM
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.2015-01-12 11:55 PM
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?
2015-01-13 06:09 AM
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.2015-01-13 08:06 PM
2015-01-13 08:44 PM
Or more competitively at
http://www.abebooks.com/servlet/BookDetailsPL?bi=12422234816&searchurl=tn%3Dcortex-m4%26sts%3Dt