cancel
Showing results for 
Search instead for 
Did you mean: 

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

toantq3
Associate II
Posted on October 06, 2012 at 04:49

Dear Friends.

I'm using STM32F0 for my project but there is something I don't understand how to program the application flash file into flash memory of STM32F0. I explain my working and my understanding about the flash. 

In my project, i using eeprom emulation with 2 pages.

#define EEPROM_START_ADDRESS  ((uint32_t)0x08002000) // 8K after sector 2

#define PAGE_SIZE             ((uint32_t)0x0400)  /* Page size = 1KByte */

I want to ask all friends that

1) Must i program my application hex file from 0x08002800? 

I understand if I program at address 0x08000000. That means the data I stored in eeprom emulation will be erased every time I program new hex file. Is it right?

2) Address in ST-Link GUI is always 0x08000000, if I want to program at address, i must correct to 0x08002800 before I program. Is it right?

3) Do I need to modify anything in library or start up file STM32F0 to pointer to address 0x08002800? So that every time, application code execute, it will execute from address 0x08002800. Is that right?

4) I'm using Keil. Do i need to modify any thing in Keil to program address at 0x08002800?

I'm really confused how to program the flash area of STM32. All friends understand how to do that. Could you please give me a help? I'm appreciated.

6 REPLIES 6
Posted on October 08, 2012 at 04:59

You have to describe the memory map to the compiler. Nominally through Options -> Target -> IROM1, or a scatter file.

Options -> Output -> Create HEX File will then generate an image at the prescribed address.

Doing this however will not cause the processor to execute it, as this is not the nature start address for code execution. You need to place code, or at least vectors to it, at the 0x08000000 address where it is expecting to find it.

Keil should also be able to program the part directly, either via the Debug, or Flash options, so the need for the ST-LINK utility in this process is somewhat unclear. Generally you want to make sure it has the correct algorithm selected, and that it is only set to erase/program the sectors/pages required for the application code.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
toantq3
Associate II
Posted on October 08, 2012 at 05:34

Dear Clive1

Could you explain more about how to do ''least vectors to it''? Beside, I also do something to do like that for STM32F05 to test application code.

I use bootloader for STM32F0. In boot loader that jump to address 0x8003000 to execute application code. Beside, I built one application Led indicator only, and configure in KEIL IROM1: 0x08003000. I use terminal to load application code by boot loader. After booting successfully, the application code is still not working.

If it modify IROM1 of KEIL to 0x0800000 and load into STM32F0. Evey thing is ok. Could you kindly give me a advice? It's really confused for me right now.

Thanks and Best Regards,

Toan Thieu

Posted on October 08, 2012 at 05:47

The first two vectors here need to reside at 0x08000000 (mapped to zero), as this is where the processor fetches them from at reset.

They can point anywhere, so the Reset_Handler code itself can be at 0x08003000 if desired, or wherever From startup_stm32f0xx.s

..
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
..

A boot loader placed at 0x08000000 could also make choices about where code flow subsequently goes. The loader would start with a similar vector table, with the body of the code following immediately after it.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
toantq3
Associate II
Posted on October 08, 2012 at 06:06

Dear Clive1

''They can point anywhere, so the Reset_Handler code itself can be at 0x08003000 if desired, or wherever''

If I want to modify as you talk that Reset_Handler can set at 0x08003000. How can I do it? I must modify in source code application or start up file. You can give me real examples about modify in code. I can start it and test immediately. I'm understanding your explanation, but i don't know how to modify and implement that.

Thanks and best regards,

Toan Thieu

Posted on October 08, 2012 at 06:33

You'll need to review your other thread. Code placement is the job of the linker, and controlled either by the GUI Option->Target tab, or via scatter gather files.

You'll need to refer to your Keil documentation, and seek additional assistance via your support contact at Keil.

For general coverage about the Cortex-M0 I'd recommend Joseph Yiu's fine book on the core.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
toantq3
Associate II
Posted on October 08, 2012 at 07:33

Dear Clive1

Thank you so much.

Toan Thieu