From bdaa4a457d1021ee695aad98245907633a13e8da Mon Sep 17 00:00:00 2001 From: Henrik Persson Date: Thu, 16 Jun 2022 16:05:34 +0200 Subject: [PATCH 1/2] Make STM32F412xE targets build Trying to inherit the STM32F412xE target makes the linker fail, since __CRASH_DATA_RAM_START__ is not present. Comparing LD scripts with the STM32F412xG (which has active targets) it seems that the xE variant has missed some updates somewhere. Since the LD scripts are otherwise identical, copying the (working) ones from STM32F412xG seems to do the trick. Also added flash_data.h which was missing and needed here and there (copied from xG and updated to fit the xE flash layout). --- .../TOOLCHAIN_ARM/stm32f412xe.sct | 17 +++++- .../TOOLCHAIN_GCC_ARM/stm32f412xe.ld | 14 +++++ .../TOOLCHAIN_IAR/stm32f412xe.icf | 9 ++- .../TARGET_STM32F412xE/flash_data.h | 55 +++++++++++++++++++ 4 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/flash_data.h diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_ARM/stm32f412xe.sct b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_ARM/stm32f412xe.sct index 7aff08bc288..827b6a92d91 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_ARM/stm32f412xe.sct +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_ARM/stm32f412xe.sct @@ -37,6 +37,14 @@ /* Round up VECTORS_SIZE to 8 bytes */ #define VECTORS_SIZE (((NVIC_NUM_VECTORS * 4) + 7) AND ~7) +#define MBED_CRASH_REPORT_RAM_SIZE 0x100 + +#define MBED_IRAM1_START (MBED_RAM_START + VECTORS_SIZE + MBED_CRASH_REPORT_RAM_SIZE) +#define MBED_IRAM1_SIZE (MBED_RAM_SIZE - VECTORS_SIZE - MBED_CRASH_REPORT_RAM_SIZE) + + +#define RAM_FIXED_SIZE (MBED_CONF_TARGET_BOOT_STACK_SIZE + VECTORS_SIZE + MBED_CRASH_REPORT_RAM_SIZE) + LR_IROM1 MBED_APP_START MBED_APP_SIZE { ER_IROM1 MBED_APP_START MBED_APP_SIZE { @@ -45,11 +53,14 @@ LR_IROM1 MBED_APP_START MBED_APP_SIZE { .ANY (+RO) } - RW_IRAM1 (MBED_RAM_START + VECTORS_SIZE) { ; RW data - .ANY (+RW +ZI) + RW_m_crash_data (MBED_RAM_START + VECTORS_SIZE) EMPTY MBED_CRASH_REPORT_RAM_SIZE { ; RW data + } + + RW_IRAM1 MBED_IRAM1_START MBED_IRAM1_SIZE { ; RW data + .ANY (+RW +ZI) } - ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (MBED_RAM_START + MBED_RAM_SIZE - MBED_CONF_TARGET_BOOT_STACK_SIZE - AlignExpr(ImageLimit(RW_IRAM1), 16)) { ; Heap growing up + ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (MBED_IRAM1_START + MBED_RAM_SIZE - RAM_FIXED_SIZE - AlignExpr(ImageLimit(RW_IRAM1), 16)) { ; Heap growing up } ARM_LIB_STACK (MBED_RAM_START + MBED_RAM_SIZE) EMPTY -MBED_CONF_TARGET_BOOT_STACK_SIZE { ; Stack region growing down diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_GCC_ARM/stm32f412xe.ld b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_GCC_ARM/stm32f412xe.ld index 5f479936c85..7acf3c6bc3d 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_GCC_ARM/stm32f412xe.ld +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_GCC_ARM/stm32f412xe.ld @@ -35,6 +35,8 @@ /* Round up VECTORS_SIZE to 8 bytes */ #define VECTORS_SIZE (((NVIC_NUM_VECTORS * 4) + 7) & 0xFFFFFFF8) +M_CRASH_DATA_RAM_SIZE = 0x100; + MEMORY { FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE @@ -114,6 +116,18 @@ SECTIONS __etext = .; _sidata = .; + .crash_data_ram : + { + . = ALIGN(8); + __CRASH_DATA_RAM__ = .; + __CRASH_DATA_RAM_START__ = .; /* Create a global symbol at data start */ + KEEP(*(.keep.crash_data_ram)) + *(.m_crash_data_ram) /* This is a user defined section */ + . += M_CRASH_DATA_RAM_SIZE; + . = ALIGN(8); + __CRASH_DATA_RAM_END__ = .; /* Define a global symbol at data end */ + } > RAM + .data : AT (__etext) { __data_start__ = .; diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_IAR/stm32f412xe.icf b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_IAR/stm32f412xe.icf index 6a3021d3bf3..940f6ced874 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_IAR/stm32f412xe.icf +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_IAR/stm32f412xe.icf @@ -39,8 +39,13 @@ if (!isdefinedsymbol(MBED_CONF_TARGET_BOOT_STACK_SIZE)) { /* Round up VECTORS_SIZE to 8 bytes */ define symbol VECTORS_SIZE = ((VECTORS * 4) + 7) & ~7; -define symbol RAM_REGION_START = MBED_RAM_START + VECTORS_SIZE; -define symbol RAM_REGION_SIZE = MBED_RAM_SIZE - VECTORS_SIZE; + +define symbol CRASH_DATA_START = MBED_RAM_START + VECTORS_SIZE; +define symbol CRASH_DATA_SIZE = 0x100; +define exported symbol __CRASH_DATA_RAM_START__ = CRASH_DATA_START; + +define symbol RAM_REGION_START = CRASH_DATA_START + CRASH_DATA_SIZE; +define symbol RAM_REGION_SIZE = MBED_RAM_SIZE - VECTORS_SIZE - CRASH_DATA_SIZE; define memory mem with size = 4G; define region ROM_region = mem:[from MBED_APP_START size MBED_APP_SIZE]; diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/flash_data.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/flash_data.h new file mode 100644 index 00000000000..6fca0192c4d --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/flash_data.h @@ -0,0 +1,55 @@ +/* mbed Microcontroller Library + ******************************************************************************* + * Copyright (c) 2016, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************* + */ +#ifndef MBED_FLASH_DATA_H +#define MBED_FLASH_DATA_H + +#include "device.h" +#include + +#if DEVICE_FLASH + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Exported macro ------------------------------------------------------------*/ +/* Flash size */ +#define FLASH_SIZE (uint32_t) 0x80000 // 512 KB + +/* Base address of the Flash sectors Bank 1 */ +#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */ +#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */ + +#endif +#endif From 684181c40bcb9de4ba5393fb5ecc3bc6923196ab Mon Sep 17 00:00:00 2001 From: Henrik Persson Date: Mon, 20 Jun 2022 17:09:02 +0200 Subject: [PATCH 2/2] Add targets.json definition for STM32F412xE --- targets/targets.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/targets/targets.json b/targets/targets.json index cb6fb14a88d..4b8e5009644 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -1914,6 +1914,22 @@ "0320" ] }, + "MCU_STM32F412xE": { + "inherits": [ + "MCU_STM32F4" + ], + "public": false, + "extra_labels_add": [ + "STM32F412xE" + ], + "macros_add": [ + "STM32F412Zx" + ], + "device_has_add": [ + "CAN", + "TRNG" + ] + }, "MCU_STM32F412xG": { "inherits": [ "MCU_STM32F4"