From c1e32a75df9c07f5625caeef85e931fd0227f5b9 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 11 Jun 2017 22:37:22 +0100 Subject: [PATCH 01/13] initial commit of xDot bootloader --- .../device/TOOLCHAIN_ARM_STD/stm32l151rc.sct | 14 ++++++++++++-- targets/targets.json | 5 +++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_ARM_STD/stm32l151rc.sct b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_ARM_STD/stm32l151rc.sct index 141eb4a827f..f189ccc6264 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_ARM_STD/stm32l151rc.sct +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_ARM_STD/stm32l151rc.sct @@ -1,3 +1,4 @@ +#! armcc -E ; Scatter-Loading Description File ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Copyright (c) 2015, STMicroelectronics @@ -27,10 +28,19 @@ ; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +#if !defined(MBED_APP_START) + #define MBED_APP_START 0x08000000 +#endif + +#if !defined(MBED_APP_SIZE) + #define MBED_APP_SIZE 0x40000 +#endif + + ; STM32L151RC: 256KB FLASH + 32KB SRAM -LR_IROM1 0x08000000 0x40000 { ; load region size_region +LR_IROM1 MBED_APP_START MBED_APP_SIZE { ; load region size_region - ER_IROM1 0x08000000 0x40000 { ; load address = execution address + ER_IROM1 MBED_APP_START MBED_APP_SIZE { ; load address = execution address *.o (RESET, +First) *(InRoot$$Sections) .ANY (+RO) diff --git a/targets/targets.json b/targets/targets.json index fee2445374a..e6f491b32ec 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -1408,9 +1408,10 @@ "default_toolchain": "ARM", "extra_labels_add": ["STM32L1", "STM32L151CC"], "supported_toolchains": ["ARM", "GCC_ARM", "IAR"], - "device_has_add": ["ANALOGOUT"], + "device_has_add": ["ANALOGOUT", "FLASH"], "release_versions": ["5"], - "device_name": "STM32L151CC" + "device_name": "STM32L151CC", + "bootloader_supported": true }, "MOTE_L152RC": { "inherits": ["FAMILY_STM32"], From 18998411d85c9bb1d9ade66b640116fb7a05a6f6 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 12 Jun 2017 17:02:03 +0100 Subject: [PATCH 02/13] added flash algorithm --- .../TARGET_XDOT_L151CC/flash_api.c | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/flash_api.c diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/flash_api.c b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/flash_api.c new file mode 100644 index 00000000000..8b1d0f128ae --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/flash_api.c @@ -0,0 +1,72 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "flash_api.h" +#include "flash_data.h" +#include "platform/mbed_critical.h" + +// This file is automatically generated + +#if DEVICE_FLASH + +// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM +static uint32_t FLASH_ALGO[] = { + 0x4603b510, 0xd0022a01, 0xd1222a02, 0xbf00e000, 0x68004872, 0x6070f440, 0x60204c70, 0x4c6f4870, + 0x60203c0c, 0x6020486f, 0x1d24486f, 0x486f6020, 0x486a6020, 0x68001d00, 0x1f80f410, 0xf245d108, + 0x4c6b5055, 0x20066020, 0xf6406060, 0x60a070ff, 0xbf00bf00, 0xbd102000, 0x29014601, 0x2902d002, + 0xe000d10f, 0x485dbf00, 0x68003814, 0x0002f040, 0x3a144a5a, 0x46106010, 0xf0406800, 0x60100001, + 0xbf00bf00, 0x47702000, 0x48544601, 0x68003814, 0x7000f440, 0x3a144a51, 0x46106010, 0xf0406800, + 0x60100008, 0x60082000, 0xf64ae003, 0x4a5020aa, 0x484a6010, 0xf0106800, 0xd1f60f01, 0x38144847, + 0xf4206800, 0x4a457000, 0x60103a14, 0x68004610, 0x0008f020, 0x20006010, 0x46034770, 0x47702001, + 0x4603b530, 0xf1012480, 0xf02000ff, 0x483b01ff, 0x68003814, 0x6080f440, 0x3d144d38, 0x46286028, + 0xf0406800, 0x60280008, 0xe005bf00, 0x60186810, 0x1d121d1b, 0x1f241f09, 0x2c00b109, 0xe003d1f6, + 0x20aaf64a, 0x60284d32, 0x6800482c, 0x0f01f010, 0x482ad1f6, 0xf4106800, 0xd0076f70, 0x68004827, + 0x6070f440, 0x60284d25, 0xbd302001, 0x38144823, 0xf4206800, 0x4d216080, 0x60283d14, 0x68004628, + 0x0008f020, 0x46286028, 0xf4406800, 0x60286080, 0x68004628, 0x0008f040, 0x24806028, 0x6810e005, + 0x1d1b6018, 0x1f091d12, 0xb1091f24, 0xd1f62c00, 0xf64ae003, 0x4d1620aa, 0x48106028, 0xf0106800, + 0xd1f60f01, 0x6800480d, 0x6f70f410, 0x480bd007, 0xf4406800, 0x4d096070, 0x20016028, 0x4807e7c5, + 0x68003814, 0x6080f420, 0x3d144d04, 0x46286028, 0xf0206800, 0x60280008, 0xe7b62000, 0x40023c18, + 0x89abcdef, 0x02030405, 0x8c9daebf, 0x13141516, 0x40003000, 0x00000000 +}; + +static const flash_algo_t flash_algo_config = { + .init = 0x1, + .uninit = 0x59, + .erase_sector = 0x89, + .program_page = 0xe1, + .static_base = 0x1f4, + .algo_blob = FLASH_ALGO +}; + +static const sector_info_t sectors_info[] = { + {0x8000000, 0x100}, +}; + +static const flash_target_config_t flash_target_config = { + .page_size = 0x100, + .flash_start = 0x8000000, + .flash_size = 0x40000, + .sectors = sectors_info, + .sector_info_count = sizeof(sectors_info) / sizeof(sector_info_t) +}; + +void flash_set_target_config(flash_t *obj) +{ + obj->flash_algo = &flash_algo_config; + obj->target_config = &flash_target_config; +} + +#endif \ No newline at end of file From 0ff055115a7293e1e8c209e710e469872f77ff5d Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 15 Jun 2017 21:16:59 +0100 Subject: [PATCH 03/13] VTOR bootloader aware Attempt to add flash API but not working properly --- .../device/system_stm32l1xx.c | 18 ++- .../TARGET_XDOT_L151CC/flash_api.c | 72 --------- .../TARGET_STM32L1/common_objects.h | 4 + targets/TARGET_STM/TARGET_STM32L1/flash_api.c | 143 ++++++++++++++++++ 4 files changed, 163 insertions(+), 74 deletions(-) delete mode 100644 targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/flash_api.c create mode 100644 targets/TARGET_STM/TARGET_STM32L1/flash_api.c diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/system_stm32l1xx.c b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/system_stm32l1xx.c index b54d115c2f2..9c47ec0101a 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/system_stm32l1xx.c +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/system_stm32l1xx.c @@ -203,11 +203,25 @@ void SystemInit (void) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ - + + +#if defined(__ICCARM__) + #pragma section=".intvec" + #define FLASH_VTOR_BASE ((uint32_t)__section_begin(".intvec")) +#elif defined(__CC_ARM) + extern uint32_t Load$$LR$$LR_IROM1$$Base[]; + #define FLASH_VTOR_BASE ((uint32_t)Load$$LR$$LR_IROM1$$Base) +#elif defined(__GNUC__) + extern uint32_t vectors[]; + #define FLASH_VTOR_BASE ((uint32_t)vectors) +#else + #error "Flash vector address not set for this toolchain" +#endif + #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else - SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ + SCB->VTOR = FLASH_VTOR_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/flash_api.c b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/flash_api.c deleted file mode 100644 index 8b1d0f128ae..00000000000 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/flash_api.c +++ /dev/null @@ -1,72 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2017 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "flash_api.h" -#include "flash_data.h" -#include "platform/mbed_critical.h" - -// This file is automatically generated - -#if DEVICE_FLASH - -// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM -static uint32_t FLASH_ALGO[] = { - 0x4603b510, 0xd0022a01, 0xd1222a02, 0xbf00e000, 0x68004872, 0x6070f440, 0x60204c70, 0x4c6f4870, - 0x60203c0c, 0x6020486f, 0x1d24486f, 0x486f6020, 0x486a6020, 0x68001d00, 0x1f80f410, 0xf245d108, - 0x4c6b5055, 0x20066020, 0xf6406060, 0x60a070ff, 0xbf00bf00, 0xbd102000, 0x29014601, 0x2902d002, - 0xe000d10f, 0x485dbf00, 0x68003814, 0x0002f040, 0x3a144a5a, 0x46106010, 0xf0406800, 0x60100001, - 0xbf00bf00, 0x47702000, 0x48544601, 0x68003814, 0x7000f440, 0x3a144a51, 0x46106010, 0xf0406800, - 0x60100008, 0x60082000, 0xf64ae003, 0x4a5020aa, 0x484a6010, 0xf0106800, 0xd1f60f01, 0x38144847, - 0xf4206800, 0x4a457000, 0x60103a14, 0x68004610, 0x0008f020, 0x20006010, 0x46034770, 0x47702001, - 0x4603b530, 0xf1012480, 0xf02000ff, 0x483b01ff, 0x68003814, 0x6080f440, 0x3d144d38, 0x46286028, - 0xf0406800, 0x60280008, 0xe005bf00, 0x60186810, 0x1d121d1b, 0x1f241f09, 0x2c00b109, 0xe003d1f6, - 0x20aaf64a, 0x60284d32, 0x6800482c, 0x0f01f010, 0x482ad1f6, 0xf4106800, 0xd0076f70, 0x68004827, - 0x6070f440, 0x60284d25, 0xbd302001, 0x38144823, 0xf4206800, 0x4d216080, 0x60283d14, 0x68004628, - 0x0008f020, 0x46286028, 0xf4406800, 0x60286080, 0x68004628, 0x0008f040, 0x24806028, 0x6810e005, - 0x1d1b6018, 0x1f091d12, 0xb1091f24, 0xd1f62c00, 0xf64ae003, 0x4d1620aa, 0x48106028, 0xf0106800, - 0xd1f60f01, 0x6800480d, 0x6f70f410, 0x480bd007, 0xf4406800, 0x4d096070, 0x20016028, 0x4807e7c5, - 0x68003814, 0x6080f420, 0x3d144d04, 0x46286028, 0xf0206800, 0x60280008, 0xe7b62000, 0x40023c18, - 0x89abcdef, 0x02030405, 0x8c9daebf, 0x13141516, 0x40003000, 0x00000000 -}; - -static const flash_algo_t flash_algo_config = { - .init = 0x1, - .uninit = 0x59, - .erase_sector = 0x89, - .program_page = 0xe1, - .static_base = 0x1f4, - .algo_blob = FLASH_ALGO -}; - -static const sector_info_t sectors_info[] = { - {0x8000000, 0x100}, -}; - -static const flash_target_config_t flash_target_config = { - .page_size = 0x100, - .flash_start = 0x8000000, - .flash_size = 0x40000, - .sectors = sectors_info, - .sector_info_count = sizeof(sectors_info) / sizeof(sector_info_t) -}; - -void flash_set_target_config(flash_t *obj) -{ - obj->flash_algo = &flash_algo_config; - obj->target_config = &flash_target_config; -} - -#endif \ No newline at end of file diff --git a/targets/TARGET_STM/TARGET_STM32L1/common_objects.h b/targets/TARGET_STM/TARGET_STM32L1/common_objects.h index ef2e65c75ee..9de43117299 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/common_objects.h +++ b/targets/TARGET_STM/TARGET_STM32L1/common_objects.h @@ -109,6 +109,10 @@ struct i2c_s { uint8_t available_events; #endif }; +struct flash_s { + /* nothing to be stored for now */ + uint32_t dummy; +}; struct dac_s { DACName dac; diff --git a/targets/TARGET_STM/TARGET_STM32L1/flash_api.c b/targets/TARGET_STM/TARGET_STM32L1/flash_api.c new file mode 100644 index 00000000000..68927d56510 --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32L1/flash_api.c @@ -0,0 +1,143 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "flash_api.h" +#include "mbed_critical.h" + +#if DEVICE_FLASH +#include "mbed_assert.h" +#include "cmsis.h" + +/* L1 targets embed 16 pages sectors */ +#define NUM_PAGES_IN_SECTOR 16 + +int32_t flash_init(flash_t *obj) +{ + /* Unlock the Flash to enable the flash control register access *************/ + HAL_FLASH_Unlock(); + return 0; +} + +int32_t flash_free(flash_t *obj) +{ + /* Lock the Flash to disable the flash control register access (recommended + * to protect the FLASH memory against possible unwanted operation) *********/ + HAL_FLASH_Lock(); + return 0; +} + +int32_t flash_erase_sector(flash_t *obj, uint32_t address) +{ + uint32_t FirstPage = 0; + uint32_t PAGEError = 0; + FLASH_EraseInitTypeDef EraseInitStruct; + + if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) { + + return -1; + } + + /* Clear OPTVERR bit set on virgin samples */ + __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR); + + /* MBED HAL erases 1 sector at a time */ + /* Fill EraseInit structure*/ + EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; + EraseInitStruct.PageAddress = address; + EraseInitStruct.NbPages = NUM_PAGES_IN_SECTOR; + + /* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache, + you have to make sure that these data are rewritten before they are accessed during code + execution. If this cannot be done safely, it is recommended to flush the caches by setting the + DCRST and ICRST bits in the FLASH_CR register. */ + + if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK) { + return -1; + } else { + return 0; + } +} + +int32_t flash_program_page(flash_t *obj, uint32_t address, + const uint8_t *data, uint32_t size) +{ + uint32_t StartAddress = 0; + + if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) { + return -1; + } + + if ((size % 4) != 0) { + /* L1 flash devices can only be programmed 32bits/4 bytes at a time */ + return -1; + } + + /* Program the user Flash area word by word */ + StartAddress = address; + + /* HW needs an aligned address to program flash, which data + * parameters doesn't ensure */ + if ((uint32_t) data % 4 != 0) { + volatile uint32_t data32; + while (address < (StartAddress + size)) { + for (uint8_t i =0; i < 4; i++) { + *(((uint8_t *) &data32) + i) = *(data + i); + } + + if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data32) == HAL_OK) { + address = address + 4; + data = data + 4; + } else { + return -1; + } + } + } else { /* case where data is aligned, so let's avoid any copy */ + while (address < (StartAddress + size)) { + if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, *((uint32_t*) data)) == HAL_OK) { + address = address + 4; + data = data + 4; + } else { + return -1; + } + } + } + + return 0; +} + +uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address) { + /* considering 1 sector = 1 page */ + if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) { + return MBED_FLASH_INVALID_SIZE; + } else { + return (NUM_PAGES_IN_SECTOR * FLASH_PAGE_SIZE); + } +} + +uint32_t flash_get_page_size(const flash_t *obj) { + /* considering 1 sector = 1 page */ + return FLASH_PAGE_SIZE; +} + +uint32_t flash_get_start_address(const flash_t *obj) { + return FLASH_BASE; +} + +uint32_t flash_get_size(const flash_t *obj) { + return FLASH_SIZE; +} + +#endif From 802000b0594857f5b8e84d2cfe8af9514457b9ce Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 16 Jun 2017 16:58:10 +0100 Subject: [PATCH 04/13] GCC_ARM VTOR fixed, doesnt fit in the bootloader region though.. --- .../TARGET_XDOT_L151CC/device/system_stm32l1xx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/system_stm32l1xx.c b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/system_stm32l1xx.c index 9c47ec0101a..2ad62cd9df1 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/system_stm32l1xx.c +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/system_stm32l1xx.c @@ -212,8 +212,8 @@ void SystemInit (void) extern uint32_t Load$$LR$$LR_IROM1$$Base[]; #define FLASH_VTOR_BASE ((uint32_t)Load$$LR$$LR_IROM1$$Base) #elif defined(__GNUC__) - extern uint32_t vectors[]; - #define FLASH_VTOR_BASE ((uint32_t)vectors) + extern uint32_t g_pfnVectors[]; + #define FLASH_VTOR_BASE ((uint32_t)g_pfnVectors) #else #error "Flash vector address not set for this toolchain" #endif From 5803bdd7159b2da3586de30541025123851540d6 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 26 Jun 2017 23:08:54 +0100 Subject: [PATCH 05/13] clear additional flags on erase to prevent errors --- targets/TARGET_STM/TARGET_STM32L1/flash_api.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32L1/flash_api.c b/targets/TARGET_STM/TARGET_STM32L1/flash_api.c index 68927d56510..755770d2f33 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/flash_api.c +++ b/targets/TARGET_STM/TARGET_STM32L1/flash_api.c @@ -50,9 +50,7 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address) return -1; } - /* Clear OPTVERR bit set on virgin samples */ - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR); - + __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_PGAERR | FLASH_FLAG_WRPERR); /* MBED HAL erases 1 sector at a time */ /* Fill EraseInit structure*/ EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; From 65ab95572c9a4257e387412c9b773173324095a5 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 26 Jun 2017 23:51:09 +0100 Subject: [PATCH 06/13] added missing FLASH_FLAG_OPTVERR --- targets/TARGET_STM/TARGET_STM32L1/flash_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_STM/TARGET_STM32L1/flash_api.c b/targets/TARGET_STM/TARGET_STM32L1/flash_api.c index 755770d2f33..b6cf57f82c4 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/flash_api.c +++ b/targets/TARGET_STM/TARGET_STM32L1/flash_api.c @@ -50,7 +50,7 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address) return -1; } - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_PGAERR | FLASH_FLAG_WRPERR); + __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR | FLASH_FLAG_EOP | FLASH_FLAG_PGAERR | FLASH_FLAG_WRPERR); /* MBED HAL erases 1 sector at a time */ /* Fill EraseInit structure*/ EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; From ed51bcb1d0cbec5db8a05f9980e08ed0e1e87e23 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 27 Jun 2017 09:40:30 +0100 Subject: [PATCH 07/13] Formatting tidy up. --- targets/TARGET_STM/TARGET_STM32L1/flash_api.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32L1/flash_api.c b/targets/TARGET_STM/TARGET_STM32L1/flash_api.c index b6cf57f82c4..d6e06bfb2f8 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/flash_api.c +++ b/targets/TARGET_STM/TARGET_STM32L1/flash_api.c @@ -116,7 +116,8 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, return 0; } -uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address) { +uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address) +{ /* considering 1 sector = 1 page */ if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) { return MBED_FLASH_INVALID_SIZE; @@ -125,16 +126,19 @@ uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address) { } } -uint32_t flash_get_page_size(const flash_t *obj) { +uint32_t flash_get_page_size(const flash_t *obj) +{ /* considering 1 sector = 1 page */ return FLASH_PAGE_SIZE; } -uint32_t flash_get_start_address(const flash_t *obj) { +uint32_t flash_get_start_address(const flash_t *obj) +{ return FLASH_BASE; } -uint32_t flash_get_size(const flash_t *obj) { +uint32_t flash_get_size(const flash_t *obj) +{ return FLASH_SIZE; } From a4c7a2914484aa5ca662da7d308867a455e9275a Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 27 Jun 2017 20:11:48 +0100 Subject: [PATCH 08/13] uArm Bootloader support --- .../device/TOOLCHAIN_ARM_MICRO/stm32l151rc.sct | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_ARM_MICRO/stm32l151rc.sct b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_ARM_MICRO/stm32l151rc.sct index 141eb4a827f..f189ccc6264 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_ARM_MICRO/stm32l151rc.sct +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_ARM_MICRO/stm32l151rc.sct @@ -1,3 +1,4 @@ +#! armcc -E ; Scatter-Loading Description File ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Copyright (c) 2015, STMicroelectronics @@ -27,10 +28,19 @@ ; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +#if !defined(MBED_APP_START) + #define MBED_APP_START 0x08000000 +#endif + +#if !defined(MBED_APP_SIZE) + #define MBED_APP_SIZE 0x40000 +#endif + + ; STM32L151RC: 256KB FLASH + 32KB SRAM -LR_IROM1 0x08000000 0x40000 { ; load region size_region +LR_IROM1 MBED_APP_START MBED_APP_SIZE { ; load region size_region - ER_IROM1 0x08000000 0x40000 { ; load address = execution address + ER_IROM1 MBED_APP_START MBED_APP_SIZE { ; load address = execution address *.o (RESET, +First) *(InRoot$$Sections) .ANY (+RO) From 82a33b2a7028fc5ed5642eb95e38095c72ab9be0 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 27 Jun 2017 20:43:58 +0100 Subject: [PATCH 09/13] IAR Bootloader support --- .../device/TOOLCHAIN_IAR/stm32l152xc.icf | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_IAR/stm32l152xc.icf b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_IAR/stm32l152xc.icf index aed878fb05b..ebf7478802d 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_IAR/stm32l152xc.icf +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_IAR/stm32l152xc.icf @@ -1,7 +1,9 @@ +if (!isdefinedsymbol(MBED_APP_START)) { define symbol MBED_APP_START = 0x08000000; } +if (!isdefinedsymbol(MBED_APP_SIZE)) { define symbol MBED_APP_SIZE = 0x40000; } /* [ROM = 256kb = 0x40000] */ -define symbol __intvec_start__ = 0x08000000; -define symbol __region_ROM_start__ = 0x08000000; -define symbol __region_ROM_end__ = 0x0803FFFF; +define symbol __intvec_start__ = MBED_APP_START; +define symbol __region_ROM_start__ = MBED_APP_START; +define symbol __region_ROM_end__ = MBED_APP_START + MBED_APP_SIZE - 1; /* [RAM = 32kb = 0x8000] Vector table dynamic copy: 73 vectors = 292 bytes (0x124) to be reserved in RAM */ define symbol __NVIC_start__ = 0x20000000; From 8484467fdd33b317669565966577236f9f438676 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 27 Jun 2017 20:44:32 +0100 Subject: [PATCH 10/13] GCC Bootloader support --- .../device/TOOLCHAIN_GCC_ARM/STM32L151XC.ld | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_GCC_ARM/STM32L151XC.ld b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_GCC_ARM/STM32L151XC.ld index af8cddd4a14..17d63638e65 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_GCC_ARM/STM32L151XC.ld +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_GCC_ARM/STM32L151XC.ld @@ -1,11 +1,17 @@ /* Linker script to configure memory regions. */ +#if !defined(MBED_APP_START) + #define MBED_APP_START 0x08000000 +#endif +#if !defined(MBED_APP_SIZE) + #define MBED_APP_SIZE 256k +#endif MEMORY { /* 256KB FLASH, 32KB RAM, Reserve up till 0x13C. There are 0x73 vectors = 292 * bytes (0x124) in RAM. But all GCC scripts seem to require BootRAM @0x138 */ - FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256k + FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE RAM (rwx) : ORIGIN = 0x2000013C, LENGTH = 0x8000-0x13C } From e59c059d3f67b6b2237390978d39b63220d16187 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 28 Jun 2017 09:32:39 +0100 Subject: [PATCH 11/13] Incorrect comments removed. --- targets/TARGET_STM/TARGET_STM32L1/flash_api.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32L1/flash_api.c b/targets/TARGET_STM/TARGET_STM32L1/flash_api.c index d6e06bfb2f8..e41289ec2e0 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/flash_api.c +++ b/targets/TARGET_STM/TARGET_STM32L1/flash_api.c @@ -118,7 +118,6 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address) { - /* considering 1 sector = 1 page */ if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) { return MBED_FLASH_INVALID_SIZE; } else { @@ -128,7 +127,6 @@ uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address) uint32_t flash_get_page_size(const flash_t *obj) { - /* considering 1 sector = 1 page */ return FLASH_PAGE_SIZE; } From a516dcac843eb417e83bec39ee798b5f1fdcbd18 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 30 Jun 2017 22:20:34 +0100 Subject: [PATCH 12/13] Code tidy --- targets/TARGET_STM/TARGET_STM32L1/flash_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_STM/TARGET_STM32L1/flash_api.c b/targets/TARGET_STM/TARGET_STM32L1/flash_api.c index e41289ec2e0..86572e619d4 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/flash_api.c +++ b/targets/TARGET_STM/TARGET_STM32L1/flash_api.c @@ -50,7 +50,7 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address) return -1; } - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR | FLASH_FLAG_EOP | FLASH_FLAG_PGAERR | FLASH_FLAG_WRPERR); + __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR | FLASH_FLAG_EOP | FLASH_FLAG_PGAERR | FLASH_FLAG_WRPERR); /* MBED HAL erases 1 sector at a time */ /* Fill EraseInit structure*/ EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; From 2a2d904b9159cf4f6332f346cbab538b72f50aed Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 30 Jun 2017 22:31:21 +0100 Subject: [PATCH 13/13] Tidy from rebase --- targets/TARGET_STM/TARGET_STM32L1/common_objects.h | 1 + 1 file changed, 1 insertion(+) diff --git a/targets/TARGET_STM/TARGET_STM32L1/common_objects.h b/targets/TARGET_STM/TARGET_STM32L1/common_objects.h index 9de43117299..844e0f5b25b 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/common_objects.h +++ b/targets/TARGET_STM/TARGET_STM32L1/common_objects.h @@ -109,6 +109,7 @@ struct i2c_s { uint8_t available_events; #endif }; + struct flash_s { /* nothing to be stored for now */ uint32_t dummy;