How can I change the start address on flash?
Asked Answered
M

3

11

I'm using STM32F746ZG and FreeRTOS. The start address of flash is 0x08000000. But I want to change it to 0x08040000. I've searched this issue through google but I didn't find the solution.

I changed the linker script like the following.

MEMORY
{
RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 320K
/* FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 1024K */
FLASH (rx)      : ORIGIN = 0x8040000, LENGTH = 768K
}

If I only change it and run the debugger, it has the problem. If I change the VECT_TAB_OFFSET from 0x00 to 0x4000, it works fine.

/* #define VECT_TAB_SRAM */
#define VECT_TAB_OFFSET  0x40000  /* 0x00 */

SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; 

But if I don't use debugger, it doesn't work anything. It means it only works when using ST-Linker.

Please let me know if you know the solution. Thank you for in advance of your reply.

Maillot answered 5/7, 2019 at 3:58 Comment(2)
The question is why do you want to change the start address.Skittish
You could have a standalone bootloader sitting in the first flash pages. Thats the usual Use Case.Aspire
S
7

The boot address can be set in the option bytes.

You can set any address in the flash with 16k increments. There are two 16 bit registers in the option bytes area, one is used when the boot pin is low at reset, the other when the pin is high. Write the desired address shifted right by 14 bits, i.e. divided by 16384.

To boot from 0x08040000, write 0x2010 into the register as described in the Option bytes programming chapter of the reference manual.

enter image description here

Skittish answered 5/7, 2019 at 11:33 Comment(3)
Hi berendi, Thank you very much for your reply. I resolved this issue your suggestion. I've changed the option byte from 0x0080 to 0x2010, then it works fine. For write option byte, I did the like the following. 1. Execute STM32 ST-Link Utility. 2. Menu -> Target -> Option Bytes... --> Boot address option bytes.Maillot
The following is default value. BOOT_ADD0 (H) 0x0080 Boot from (H) 0x00200000 ---> BOOT_ADD0 (H) 0x2010 Boot from (H) 0x08040000 3. Apply So, I've changed 3 parts for changing the start address of flash and it works fine. 1. Linker script (0x08000000 --> 0x08040000) 2. System_stemf7xx.c (VECT_TAB_OFFSET 0x00 --> 0x40000) 3. Option byte (0x80 --> 0x2010)Maillot
Well not any address. You the LSB 16 bits cannot be set to anything other than 0x0000. So you can only address in increments of 0x10000. In other words you can't boot from 0x08020400; the closest valid addresses would be 0x08020000 and 0x08030000.Miry
D
2

You could also write a bootloader. Bootloader sits on the 0x0800 0000 address and loads your application firmware meaning jumps to it.

This is the other way to do it.

Disorderly answered 11/9, 2020 at 11:9 Comment(0)
D
-1

You need to place 8 bytes at the original beginning of the FLASH. Stm32 boots always from the address 0x00000000 which is aliased to the one of the memories (depending on the boot pins and options).

The first word contains the stack pointer the second one your reset handler. You never get to your code as it boots always from the same address.

You will need to modify your linker script and the startup files where vectors are defined

Diarmit answered 5/7, 2019 at 6:48 Comment(5)
Unfortunately none of this applies to the STM32F7.Skittish
Good description of general stm32 (or even arm cortex microcontroller) case, but it seems stm32f7 actually supports this, as @berendi answered.Pemba
@berendi Of course it applies if the goal is to write the custom boot loader. Oh changing the address is rather pointlessDiarmit
@P__J__ There is always RAM at address 0 on the F7, it can't remap anyting else there. Read the reference manual.Skittish
@berendi with this modification of course for this familyDiarmit

© 2022 - 2024 — McMap. All rights reserved.