1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-24 16:55:36 +03:00

Move EEPROM configuration space to Flash Sector 1 for all F7 targets

Add correct flash layout for STM32F722
Remove obsolete CONFIG_START_FLASH_ADDRESS definition
This commit is contained in:
Michael Jakob 2017-02-22 19:43:16 +01:00
parent ff40e8c844
commit 32a6409fc4
24 changed files with 216 additions and 76 deletions

View file

@ -26,41 +26,12 @@
extern uint8_t __config_start; // configured via linker script when building binaries.
extern uint8_t __config_end;
#if !defined(FLASH_PAGE_SIZE)
// F1
# if defined(STM32F10X_MD)
# define FLASH_PAGE_SIZE (0x400)
# elif defined(STM32F10X_HD)
# define FLASH_PAGE_SIZE (0x800)
// F3
# elif defined(STM32F303xC)
# define FLASH_PAGE_SIZE (0x800)
// F4
# elif defined(STM32F40_41xxx)
# define FLASH_PAGE_SIZE ((uint32_t)0x20000)
# elif defined (STM32F411xE)
# define FLASH_PAGE_SIZE ((uint32_t)0x20000)
# elif defined(STM32F427_437xx)
# define FLASH_PAGE_SIZE ((uint32_t)0x20000) // 128K sectors
# elif defined (STM32F446xx)
# define FLASH_PAGE_SIZE ((uint32_t)0x20000)
// F7
#elif defined(STM32F722xx)
# define FLASH_PAGE_SIZE ((uint32_t)0x20000)
# elif defined(STM32F745xx)
# define FLASH_PAGE_SIZE ((uint32_t)0x40000)
# elif defined(STM32F746xx)
# define FLASH_PAGE_SIZE ((uint32_t)0x40000)
# elif defined(UNIT_TEST)
# define FLASH_PAGE_SIZE (0x400)
# else
# error "Flash page size not defined for target."
# endif
#endif
uint32_t FlashPageSize;
void config_streamer_init(config_streamer_t *c)
{
memset(c, 0, sizeof(*c));
FlashPageSize = (uint32_t)&__config_end - (uint32_t)&__config_start;
}
void config_streamer_start(config_streamer_t *c, uintptr_t base, int size)
@ -93,7 +64,7 @@ void config_streamer_start(config_streamer_t *c, uintptr_t base, int size)
c->err = 0;
}
#if defined(STM32F7)
#if defined(STM32F745xx) || defined(STM32F746xx)
/*
Sector 0 0x08000000 - 0x08007FFF 32 Kbytes
Sector 1 0x08008000 - 0x0800FFFF 32 Kbytes
@ -130,6 +101,43 @@ static uint32_t getFLASHSectorForEEPROM(void)
}
}
#elif defined(STM32F722xx)
/*
Sector 0 0x08000000 - 0x08003FFF 16 Kbytes
Sector 1 0x08004000 - 0x08007FFF 16 Kbytes
Sector 2 0x08008000 - 0x0800BFFF 16 Kbytes
Sector 3 0x0800C000 - 0x0800FFFF 16 Kbytes
Sector 4 0x08010000 - 0x0801FFFF 64 Kbytes
Sector 5 0x08020000 - 0x0803FFFF 128 Kbytes
Sector 6 0x08040000 - 0x0805FFFF 128 Kbytes
Sector 7 0x08060000 - 0x0807FFFF 128 Kbytes
*/
static uint32_t getFLASHSectorForEEPROM(void)
{
if ((uint32_t)&__config_start <= 0x08003FFF)
return FLASH_SECTOR_0;
if ((uint32_t)&__config_start <= 0x08007FFF)
return FLASH_SECTOR_1;
if ((uint32_t)&__config_start <= 0x0800BFFF)
return FLASH_SECTOR_2;
if ((uint32_t)&__config_start <= 0x0800FFFF)
return FLASH_SECTOR_3;
if ((uint32_t)&__config_start <= 0x0801FFFF)
return FLASH_SECTOR_4;
if ((uint32_t)&__config_start <= 0x0803FFFF)
return FLASH_SECTOR_5;
if ((uint32_t)&__config_start <= 0x0805FFFF)
return FLASH_SECTOR_6;
if ((uint32_t)&__config_start <= 0x0807FFFF)
return FLASH_SECTOR_7;
// Not good
while (1) {
failureMode(FAILURE_FLASH_WRITE_FAILED);
}
}
#elif defined(STM32F4)
/*
Sector 0 0x08000000 - 0x08003FFF 16 Kbytes
@ -186,7 +194,7 @@ static int write_word(config_streamer_t *c, uint32_t value)
return c->err;
}
#if defined(STM32F7)
if (c->address % FLASH_PAGE_SIZE == 0) {
if (c->address % FlashPageSize == 0) {
FLASH_EraseInitTypeDef EraseInitStruct = {
.TypeErase = FLASH_TYPEERASE_SECTORS,
.VoltageRange = FLASH_VOLTAGE_RANGE_3, // 2.7-3.6V
@ -204,7 +212,7 @@ static int write_word(config_streamer_t *c, uint32_t value)
return -2;
}
#else
if (c->address % FLASH_PAGE_SIZE == 0) {
if (c->address % FlashPageSize == 0) {
#if defined(STM32F4)
const FLASH_Status status = FLASH_EraseSector(getFLASHSectorForEEPROM(), VoltageRange_3); //0x08080000 to 0x080A0000
#else

View file

@ -23,8 +23,6 @@
#define HW_PIN PC13
#define BRUSHED_ESC_AUTODETECT
#define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8)
#define USBD_PRODUCT_STRING "AlienFlight F4"
#define LED0 PC12

View file

@ -19,8 +19,6 @@
#define TARGET_BOARD_IDENTIFIER "ANY7"
#define CONFIG_START_FLASH_ADDRESS (0x080C0000)
#define USBD_PRODUCT_STRING "AnyFCF7"
#define USE_DSHOT

View file

@ -21,8 +21,6 @@
#define TARGET_VALIDATECONFIG
#define TARGET_PREINIT
#define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8)
#define USBD_PRODUCT_STRING "BlueJayF4"
#define USE_HARDWARE_REVISION_DETECTION

View file

@ -19,8 +19,6 @@
#define TARGET_BOARD_IDENTIFIER "COLI"
#define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8)
#define USBD_PRODUCT_STRING "Colibri"
#ifdef OPBL
#define USBD_SERIALNUMBER_STRING "0x8020000"

View file

@ -18,7 +18,6 @@
#pragma once
#define TARGET_BOARD_IDENTIFIER "ELL0"
#define CONFIG_START_FLASH_ADDRESS 0x08080000 //0x08080000 to 0x080A0000 (FLASH_Sector_8)
#define TARGET_XTAL_MHZ 25
#define USBD_PRODUCT_STRING "Elle0"

View file

@ -18,8 +18,6 @@
#pragma once
#define TARGET_BOARD_IDENTIFIER "F4BY"
#define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8)
#define USBD_PRODUCT_STRING "Swift-Flyer F4BY"
#define LED0 PE3 // Blue LED

View file

@ -18,7 +18,6 @@
#pragma once
#define TARGET_BOARD_IDENTIFIER "FDF4"
#define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8)
#define USBD_PRODUCT_STRING "FishDroneF4"

View file

@ -18,7 +18,6 @@
#pragma once
#define TARGET_BOARD_IDENTIFIER "FYF4"
#define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8)
#define USBD_PRODUCT_STRING "FuryF4"

View file

@ -19,8 +19,6 @@
#define TARGET_BOARD_IDENTIFIER "FYF7"
#define CONFIG_START_FLASH_ADDRESS (0x080C0000)
#define USBD_PRODUCT_STRING "FuryF7"
#define USE_DSHOT

View file

@ -18,8 +18,6 @@
#pragma once
#define TARGET_BOARD_IDENTIFIER "KTV1"
#define CONFIG_START_FLASH_ADDRESS 0x08080000 //0x08080000 to 0x080A0000 (FLASH_Sector_8)
#define USBD_PRODUCT_STRING "KakuteF4-V1"
#define LED0 PB5

View file

@ -18,7 +18,6 @@
#pragma once
#define TARGET_BOARD_IDENTIFIER "KIWI"
#define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8)
#define USBD_PRODUCT_STRING "KIWIF4"

View file

@ -18,8 +18,6 @@
#pragma once
#define TARGET_BOARD_IDENTIFIER "NERO"
#define CONFIG_START_FLASH_ADDRESS (0x08060000)
#define USBD_PRODUCT_STRING "NERO"
#define HW_PIN PB2

View file

@ -19,8 +19,6 @@
#define TARGET_BOARD_IDENTIFIER "NUC7"
#define CONFIG_START_FLASH_ADDRESS (0x080C0000)
#define USBD_PRODUCT_STRING "NucleoF7"
//#define USE_DSHOT

View file

@ -21,8 +21,6 @@
#define TARGET_BOARD_IDENTIFIER "OBF4"
#endif
#define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8)
#define USBD_PRODUCT_STRING "OmnibusF4"
#ifdef OPBL
#define USBD_SERIALNUMBER_STRING "0x8020000"

View file

@ -17,8 +17,6 @@
#pragma once
#define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8)
#if defined(AIRBOTF4)
#define TARGET_BOARD_IDENTIFIER "AIR4"
#define USBD_PRODUCT_STRING "AirbotF4"

View file

@ -18,8 +18,6 @@
#pragma once
#define TARGET_BOARD_IDENTIFIER "REVN"
#define CONFIG_START_FLASH_ADDRESS (0x08060000) //0x08060000 to 0x08080000 (FLASH_Sector_7)
#define USBD_PRODUCT_STRING "Revo Nano"
#ifdef OPBL
#define USBD_SERIALNUMBER_STRING "0x8010000"

View file

@ -18,8 +18,6 @@
#pragma once
#define TARGET_BOARD_IDENTIFIER "SPK2"
#define CONFIG_START_FLASH_ADDRESS 0x08080000 //0x08080000 to 0x080A0000 (FLASH_Sector_8)
#define USBD_PRODUCT_STRING "Sparky 2.0"
#ifdef OPBL
#define USBD_SERIALNUMBER_STRING "0x8020000"

View file

@ -18,7 +18,6 @@
#pragma once
#define TARGET_BOARD_IDENTIFIER "VRRA"
#define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8)
#define USBD_PRODUCT_STRING "VRRACE"

View file

@ -18,8 +18,6 @@
#pragma once
#define TARGET_BOARD_IDENTIFIER "YPF4"
#define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8)
#define USBD_PRODUCT_STRING "YupiF4"
#define LED0 PB6

View file

@ -0,0 +1,162 @@
/*
*****************************************************************************
**
** File : stm32_flash_f7.ld
**
** Abstract : Common linker script for STM32 devices.
**
*****************************************************************************
*/
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = ORIGIN(STACKRAM) + LENGTH(STACKRAM); /* end of RAM */
/* Base address where the config is stored. */
__config_start = ORIGIN(FLASH_CONFIG);
__config_end = ORIGIN(FLASH_CONFIG) + LENGTH(FLASH_CONFIG);
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0; /* required amount of heap */
_Min_Stack_Size = 0x800; /* required amount of stack */
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
PROVIDE (isr_vector_table_base = .);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH1
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(.fini_array*))
KEEP (*(SORT(.fini_array.*)))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
.pg_registry :
{
PROVIDE_HIDDEN (__pg_registry_start = .);
KEEP (*(.pg_registry))
KEEP (*(SORT(.pg_registry.*)))
PROVIDE_HIDDEN (__pg_registry_end = .);
} >FLASH
.pg_resetdata :
{
PROVIDE_HIDDEN (__pg_resetdata_start = .);
KEEP (*(.pg_resetdata))
PROVIDE_HIDDEN (__pg_resetdata_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = .;
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(SORT_BY_ALIGNMENT(.bss*))
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
/* User_heap_stack section, used to check that there is enough RAM left */
_heap_stack_end = ORIGIN(STACKRAM)+LENGTH(STACKRAM) - 8; /* 8 bytes to allow for alignment */
_heap_stack_begin = _heap_stack_end - _Min_Stack_Size - _Min_Heap_Size;
. = _heap_stack_begin;
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >STACKRAM = 0xa5
/* MEMORY_bank1 section, code must be located here explicitly */
/* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
.memory_b1_text :
{
*(.mb1text) /* .mb1text sections (code) */
*(.mb1text*) /* .mb1text* sections (code) */
*(.mb1rodata) /* read-only data (constants) */
*(.mb1rodata*)
} >MEMORY_B1
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}

View file

@ -15,8 +15,9 @@ ENTRY(Reset_Handler)
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 384K
FLASH_CONFIG (r) : ORIGIN = 0x08060000, LENGTH = 128K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 16K
FLASH_CONFIG (r) : ORIGIN = 0x08004000, LENGTH = 16K
FLASH1 (rx) : ORIGIN = 0x08008000, LENGTH = 480K
TCM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
RAM (rwx) : ORIGIN = 0x20010000, LENGTH = 192K
@ -26,4 +27,4 @@ MEMORY
/* note TCM could be used for stack */
REGION_ALIAS("STACKRAM", TCM)
INCLUDE "stm32_flash.ld"
INCLUDE "stm32_flash_f7.ld"

View file

@ -15,8 +15,9 @@ ENTRY(Reset_Handler)
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 768K
FLASH_CONFIG (r) : ORIGIN = 0x080C0000, LENGTH = 256K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K
FLASH_CONFIG (r) : ORIGIN = 0x08008000, LENGTH = 32K
FLASH1 (rx) : ORIGIN = 0x08010000, LENGTH = 960K
TCM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
RAM (rwx) : ORIGIN = 0x20010000, LENGTH = 256K
@ -25,4 +26,4 @@ MEMORY
/* note CCM could be used for stack */
REGION_ALIAS("STACKRAM", TCM)
INCLUDE "stm32_flash.ld"
INCLUDE "stm32_flash_f7.ld"

View file

@ -15,8 +15,9 @@ ENTRY(Reset_Handler)
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 768K
FLASH_CONFIG (r) : ORIGIN = 0x080C0000, LENGTH = 256K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K
FLASH_CONFIG (r) : ORIGIN = 0x08008000, LENGTH = 32K
FLASH1 (rx) : ORIGIN = 0x08010000, LENGTH = 960K
TCM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
RAM (rwx) : ORIGIN = 0x20010000, LENGTH = 256K
@ -25,4 +26,4 @@ MEMORY
/* note CCM could be used for stack */
REGION_ALIAS("STACKRAM", TCM)
INCLUDE "stm32_flash.ld"
INCLUDE "stm32_flash_f7.ld"