Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ROMSLOT_STM32L1.cpp
00001 // ROMSLOT_STM32L1.cpp 2016/4/9 00002 #if defined(TARGET_STM32L1) 00003 #include "ROMSLOT.h" 00004 00005 ROMSLOT::ROMSLOT() { 00006 base = 0x20000; 00007 } 00008 00009 uint32_t ROMSLOT::New(uint32_t size) { 00010 uint32_t addr = base; 00011 base += (size + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE * FLASH_PAGE_SIZE; 00012 return addr; 00013 } 00014 00015 static bool is_base(uint32_t addr) { 00016 return addr % FLASH_PAGE_SIZE == 0; 00017 } 00018 00019 bool ROMSLOT::Write(uint32_t addr, const uint8_t buf[], uint32_t size) { 00020 uint32_t data; 00021 MBED_ASSERT(addr % sizeof(data) == 0); 00022 MBED_ASSERT(size % sizeof(data) == 0); 00023 if (memcmp((uint8_t*)addr, buf, size) == 0) { // skip ? 00024 return true; 00025 } 00026 HAL_FLASH_Unlock(); 00027 bool result = true; 00028 for(uint32_t n = 0; n < size; n += sizeof(data)) { 00029 if (is_base(addr + n)) { 00030 FLASH_EraseInitTypeDef Erase; 00031 Erase.NbPages = 1; 00032 Erase.TypeErase = TYPEERASEDATA_BYTE; 00033 Erase.PageAddress = addr + n; 00034 uint32_t PageError = 0; 00035 HAL_StatusTypeDef status = HAL_FLASHEx_Erase(&Erase, &PageError); 00036 MBED_ASSERT(status == HAL_OK); 00037 if (status != HAL_OK) { 00038 result = false; 00039 break; 00040 } 00041 } 00042 memcpy(&data, buf + n, sizeof(data)); 00043 HAL_StatusTypeDef status = HAL_FLASH_Program(TYPEPROGRAM_WORD, addr + n, (uint64_t)data); 00044 MBED_ASSERT(status == HAL_OK); 00045 if (status != HAL_OK) { 00046 result = false; 00047 break; 00048 } 00049 } 00050 HAL_FLASH_Lock(); 00051 return result; 00052 } 00053 #endif // TARGET_STM32L1 00054
Generated on Fri Jul 15 2022 00:32:17 by
1.7.2