How can I change the start address on flash?

只愿长相守 提交于 2020-05-15 03:59:06

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/56896375/how-can-i-change-the-start-address-on-flash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!