Skip to content

Commit

Permalink
fix(BLE,Build): Fix default PAL_NVM_SIZE, add compiler checks for NVM…
Browse files Browse the repository at this point in the history
… erase functions (#776)
  • Loading branch information
EdwinFairchild authored Oct 24, 2023
1 parent d6eb11c commit 7b3ad24
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Libraries/Cordio/platform/targets/maxim/build/cordio.mk
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ PLATFORM := maxim
RTOS ?= baremetal

# Used for storing pairing/bonding information
PAL_NVM_SIZE ?= 0x2000
PAL_NVM_SIZE ?= 0x4000

CFG_DEV := BT_VER=$(BT_VER)
CFG_DEV += SCH_CHECK_LIST_INTEGRITY=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void PalFlashWrite(void *pBuf, uint32_t size, uint32_t dstAddr)
/*!
* \brief Erase sector.
*
* \param[in] size Data size in bytes to be erased.
* \param[in] size Data size in sectors to be erased.
* \param[in] startAddr Word aligned address.
*
* \return None.
Expand All @@ -195,18 +195,25 @@ void PalFlashWrite(void *pBuf, uint32_t size, uint32_t dstAddr)
void PalFlashEraseSector(uint32_t size, uint32_t startAddr)
{
if(!PAL_NVM_IS_SECTOR_ALIGNED(startAddr)) {
WSF_ASSERT(FALSE);
PalSysAssertTrap();
}

/* Offset the address into flash */
#if defined (__GNUC__)
startAddr += (uint32_t)&__pal_nvm_db_start__;
#elif defined (__CC_ARM)
startAddr += (uint32_t)__pal_nvm_db_start__;
#elif defined (__ICCARM__)
startAddr += (uint32_t)__pal_nvm_db_start__;
#endif

while(size) {
WsfCsEnter();
MXC_FLC_PageErase(startAddr);
WsfCsExit();

startAddr += MXC_FLASH_PAGE_SIZE;
size -= MXC_FLASH_PAGE_SIZE;
size --;
}
}

Expand All @@ -221,15 +228,26 @@ void PalFlashEraseChip(void)
{
uint32_t startAddr, size;

#if defined (__GNUC__)
/* Offset the address into flash */
startAddr = (uint32_t)&__pal_nvm_db_start__;
size = (uint32_t)&__pal_nvm_db_end__ - (uint32_t)&__pal_nvm_db_start__;
#elif defined (__CC_ARM)
/* Offset the address into flash */
startAddr = (uint32_t)__pal_nvm_db_start__;
size = (uint32_t)__pal_nvm_db_end__ - (uint32_t)__pal_nvm_db_start__;
#elif defined (__ICCARM__)
/* Offset the address into flash */
startAddr = (uint32_t)__pal_nvm_db_start__;
size = (uint32_t)__pal_nvm_db_end__ - (uint32_t)__pal_nvm_db_start__ -1;
#endif

while(size) {
WsfCsEnter();
MXC_FLC_PageErase(startAddr);
WsfCsExit();

startAddr += MXC_FLASH_PAGE_SIZE;
size -= MXC_FLASH_PAGE_SIZE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,19 @@ void PalFlashEraseSector(uint32_t size, uint32_t startAddr)
}

/* Offset the address into flash */
#if defined (__GNUC__)
startAddr += (uint32_t)&__pal_nvm_db_start__;
#elif defined (__CC_ARM)
startAddr += (uint32_t)__pal_nvm_db_start__;
#elif defined (__ICCARM__)
startAddr += (uint32_t)__pal_nvm_db_start__;
#endif

while(size) {
WsfCsEnter();
MXC_FLC_PageErase(startAddr);
WsfCsExit();

startAddr += MXC_FLASH_PAGE_SIZE;
size --;
}
Expand All @@ -217,12 +226,25 @@ void PalFlashEraseChip(void)
{
uint32_t startAddr, size;

#if defined (__GNUC__)
/* Offset the address into flash */
startAddr = (uint32_t)&__pal_nvm_db_start__;
size = (uint32_t)&__pal_nvm_db_end__ - (uint32_t)&__pal_nvm_db_start__;
#elif defined (__CC_ARM)
/* Offset the address into flash */
startAddr = (uint32_t)__pal_nvm_db_start__;
size = (uint32_t)__pal_nvm_db_end__ - (uint32_t)__pal_nvm_db_start__;
#elif defined (__ICCARM__)
/* Offset the address into flash */
startAddr = (uint32_t)__pal_nvm_db_start__;
size = (uint32_t)__pal_nvm_db_end__ - (uint32_t)__pal_nvm_db_start__ -1;
#endif

while(size) {
WsfCsEnter();
MXC_FLC_PageErase(startAddr);
WsfCsExit();

startAddr += MXC_FLASH_PAGE_SIZE;
size -= MXC_FLASH_PAGE_SIZE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void PalFlashWrite(void *pBuf, uint32_t size, uint32_t dstAddr)
/*!
* \brief Erase sector.
*
* \param[in] size Data size in bytes to be erased.
* \param[in] size Data size in sectors to be erased.
* \param[in] startAddr Word aligned address.
*
* \return None.
Expand All @@ -246,7 +246,7 @@ void PalFlashEraseSector(uint32_t size, uint32_t startAddr)
WsfCsExit();

startAddr += MXC_FLASH_PAGE_SIZE;
size -= MXC_FLASH_PAGE_SIZE;
size --;
}
}

Expand Down

0 comments on commit 7b3ad24

Please sign in to comment.