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.

Hans
  • 398
  • 2
  • 4
  • 14

3 Answers3

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

  • 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. – Hans Jul 07 '19 at 23:43
  • 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) – Hans Jul 07 '19 at 23:51
  • 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. – shrewmouse Jul 26 '23 at 18:14
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.

yldzmuhammed
  • 35
  • 3
  • 12
-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

0___________
  • 60,014
  • 4
  • 34
  • 74