.

Committer:
va009039
Date:
Fri Apr 08 06:47:00 2016 +0900
Revision:
1:dee9fae0c0c4
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 1:dee9fae0c0c4 1 // ROMSLOT_STM32.cpp 2016/4/7
va009039 1:dee9fae0c0c4 2 #if defined(TARGET_STM)
va009039 1:dee9fae0c0c4 3 #include "ROMSLOT.h"
va009039 1:dee9fae0c0c4 4
va009039 1:dee9fae0c0c4 5 bool ROMSLOT::Write(uint32_t addr, const uint8_t buf[], uint32_t size) {
va009039 1:dee9fae0c0c4 6 MBED_ASSERT(addr%FLASH_PAGE_SIZE == 0);
va009039 1:dee9fae0c0c4 7 MBED_ASSERT(size%FLASH_PAGE_SIZE == 0);
va009039 1:dee9fae0c0c4 8 if (memcmp((uint8_t*)addr, buf, size) == 0) { // skip ?
va009039 1:dee9fae0c0c4 9 return true;
va009039 1:dee9fae0c0c4 10 }
va009039 1:dee9fae0c0c4 11 HAL_FLASH_Unlock();
va009039 1:dee9fae0c0c4 12 bool result = true;
va009039 1:dee9fae0c0c4 13 for(uint32_t n = 0; n < size; n += sizeof(uint32_t)) {
va009039 1:dee9fae0c0c4 14 if (n % FLASH_PAGE_SIZE == 0) {
va009039 1:dee9fae0c0c4 15 FLASH_EraseInitTypeDef Erase;
va009039 1:dee9fae0c0c4 16 Erase.NbPages = 1;
va009039 1:dee9fae0c0c4 17 Erase.TypeErase = TYPEERASEDATA_BYTE;
va009039 1:dee9fae0c0c4 18 Erase.PageAddress = addr + n;
va009039 1:dee9fae0c0c4 19 uint32_t PageError = 0;
va009039 1:dee9fae0c0c4 20 HAL_StatusTypeDef status = HAL_FLASHEx_Erase(&Erase, &PageError);
va009039 1:dee9fae0c0c4 21 MBED_ASSERT(status == HAL_OK);
va009039 1:dee9fae0c0c4 22 if (status != HAL_OK) {
va009039 1:dee9fae0c0c4 23 result = false;
va009039 1:dee9fae0c0c4 24 break;
va009039 1:dee9fae0c0c4 25 }
va009039 1:dee9fae0c0c4 26 }
va009039 1:dee9fae0c0c4 27 uint32_t data = buf[n]|buf[n+1]<<8|buf[n+2]<<16|buf[n+3]<<24;
va009039 1:dee9fae0c0c4 28 HAL_StatusTypeDef status = HAL_FLASH_Program(TYPEPROGRAM_WORD, addr + n, (uint64_t)data);
va009039 1:dee9fae0c0c4 29 MBED_ASSERT(status == HAL_OK);
va009039 1:dee9fae0c0c4 30 if (status != HAL_OK) {
va009039 1:dee9fae0c0c4 31 result = false;
va009039 1:dee9fae0c0c4 32 break;
va009039 1:dee9fae0c0c4 33 }
va009039 1:dee9fae0c0c4 34 }
va009039 1:dee9fae0c0c4 35 HAL_FLASH_Lock();
va009039 1:dee9fae0c0c4 36 return result;
va009039 1:dee9fae0c0c4 37 }
va009039 1:dee9fae0c0c4 38 #endif // TARGET_STM
va009039 1:dee9fae0c0c4 39