3
votes

Now I'm trying to understand boot sequence of STM32F103x. As you already know this is based on cortex-m3. So I was trying to find this concept of boot such as STM32F103x.. But I can't find anywhere in document Where can I find boot sequence as STM32 on ARM memory map?

Because I want to know what does system memory work actually?

Currently. I'm trying to understand about system memory in cortex m3 address map. most examples are said "there are 2 area such as 0x08000000 Flash memory area and 0x1FFFF000 System memory area.

and I understood that Flash memory area is saving for the execute file and System memory is saving for bootloader.

for example, I can make one hex binary file from build which is using startup_CMSDK_CM3.s and startup_CMSDK_CM3.c in Keil uVision. Then I put one hex binary file into the STM32 MCU by using JTEG to 0x0800_0000 of flash memory area not system memory area.

I'm not sure the difference between system memory a flash memory and I want to know "What does system memory and area actually work?"

2
Forget about system memory. It is the area with the factory bootloader. For you is just enough to remember that you can boot in the bootloader mode, and flash your program. Anything else it is too early for you I suppose.0___________

2 Answers

10
votes

old_timer answer is good, so I just elaborate more on the STM32 part:

From here we can see the different boot pin for STM32:

https://electronics.stackexchange.com/questions/206521/how-to-use-external-st-link-to-debug-program-stm32f103-mcu

enter image description here

The bootloader for STM32 system memory is described in depth here:

http://www.st.com/content/ccc/resource/technical/document/application_note/b9/9b/16/3a/12/1e/40/0c/CD00167594.pdf/files/CD00167594.pdf/jcr:content/translations/en.CD00167594.pdf

In particular the location of bootloader firmware (for STM32F1xxx, page 54):

enter image description here

And the boot sequence (page 55):

enter image description here

And this is implementing the bootloader in Flash memory mode (F103):

http://blog.myelectronics.com.ua/stm32-usb-mass-storage-bootloader/

And I find this useful (start 1.40):

https://www.youtube.com/watch?v=3brOzLJmeek

enter image description here

4
votes

If you read the arm documents you will see where the vector table is and what the contents are. the bare minimum is at address 0x00000004 you need the (thumb) ADDRESS of the reset handler.

If you read the stm32 documents you will see that based on the boot pins various things happen, the typical use case is 0x08000000 which is the flash that contains your program, is mapped to 0x00000000. You can choose to link for 0x00000000 or you can choose to link for 0x08000000 as most folks do, the (thumb) address at offset 0x00000004 (and 0x00000008 and so on) would then point to somewhere in 0x08000000.

Memory is just for read write stuff, instructions, .text, is read only you dont need to write, and for a microcontroller you need the application to be in non volatile storage, and they are designed to run code out of the flash (these days this isnt a good idea except for purpose built flashes like these).

So your program .text, and any other read only data goes in flash. Any .data you have is kept in flash but the bootstrap copies it to ram and the bootstrap zeros .bss, then once booted and into your entry point in C (often main() but that is just an arbitrary function name) the typical use case is your program is in read only flash and your data is in read/write ram. As it should be.

Granted as the programmer you are responsible for all of the above, the vector table, the bootstrap, the linking, as well as writing the program to do things.

The cortex-m boot scheme is very typical, the two most common are just run at some address, or have a vector table of addresses where the handlers live. The full sized arms are the run from this address, the cortex-m's are a list of addresses, a vector table.

When you read up on an nxp or an atmel samd or other implementations of cortex-ms you will find that they all place your flash in the boot space as they should, but may do it in different ways. Some have factory bootloaders that can be invoked in various ways and the core doesnt magically change they simply map the factory bootloader into the zero address space of the cortex-m.

its all there in the arm and st and nxp and atmel and other documents.

EDIT

system memory is for your data, read/write items, variables, data structures that change, etc. if you choose not to use the already built in bootloader, then you can choose to write your own as part of your application and as a bootloader you are welcome and in fact pretty much have to download the new program into ram, but that doesnt mean you have to run it from there (you can despite the word harvard being tossed around) or more likely you just use that as a holding area to burn it to flash. The typical purpose of a microcontroller is to run the firmware on flash and use sram for any read/write data that may change. Clock radios, toasters, remote controls, and a myriad of other things.