29 #define NVMHAL_FFFFFFFF 0xffffffffUL
46 static uint32_t readUnalignedWord(
volatile uint8_t *addr)
49 if (SCB->CCR & SCB_CCR_UNALIGN_TRP_Msk)
68 return (b3 << 24) | (b2 << 16) | (b1 << 8) | b0;
73 return *(uint32_t *)addr;
171 uint8_t *pObjectInt = (uint8_t*) pObject;
176 *pObjectInt = *pAddress;
215 uint8_t *pObjectInt = (uint8_t*)pObject;
221 padLen = (uint32_t) pAddress %
sizeof(tempWord);
226 tempWord = readUnalignedWord((uint8_t *)pObject);
229 tempWord = tempWord << 8 * padLen;
231 tempWord |= NVMHAL_FFFFFFFF >> (8 * (
sizeof(tempWord) - padLen));
234 if (len <
sizeof(tempWord) - padLen)
237 tempWord |= NVMHAL_FFFFFFFF << (8 * (padLen + len));
242 len -=
sizeof(tempWord) - padLen;
247 mscStatus =
MSC_WriteWord((uint32_t *) pAddress, &tempWord,
sizeof(tempWord));
249 pObjectInt +=
sizeof(tempWord) - padLen;
250 pAddress +=
sizeof(tempWord);
255 while ((len >=
sizeof(tempWord)) && (
mscReturnOk == mscStatus))
257 tempWord = readUnalignedWord((uint8_t *)pObjectInt);
258 mscStatus =
MSC_WriteWord((uint32_t *) pAddress, &tempWord,
sizeof(tempWord));
260 pAddress +=
sizeof(tempWord);
261 pObjectInt +=
sizeof(tempWord);
262 len -=
sizeof(tempWord);
269 tempWord = readUnalignedWord((uint8_t *)pObjectInt);
272 tempWord |= NVMHAL_FFFFFFFF << (8 * len);
273 mscStatus =
MSC_WriteWord((uint32_t *) pAddress, &tempWord,
sizeof(tempWord));
277 return returnTypeConvert(mscStatus);
297 return returnTypeConvert(
MSC_ErasePage((uint32_t *) pAddress));
326 uint8_t *pointer = (uint8_t *) pMemory;
327 uint16_t crc = *pChecksum;
331 crc = (crc >> 8) | (crc << 8);
333 crc ^= (crc & 0xf0) >> 4;
334 crc ^= (crc & 0x0f) << 12;
335 crc ^= (crc & 0xff) << 5;
void NVMHAL_Read(uint8_t *pAddress, void *pObject, uint16_t len)
Read data from NVM.
void NVMHAL_Init(void)
Initialize NVM driver.
Ecode_t NVMHAL_PageErase(uint8_t *pAddress)
Erase a page in the NVM.
void MSC_Init(void)
Enables the flash controller for writing.
void MSC_Deinit(void)
Disables the flash controller for writing.
Non-Volatile Memory Wear-Leveling driver API.
Flash controller (MSC) peripheral API.
uint32_t Ecode_t
Typedef for API function error code return values.
void NVMHAL_Checksum(uint16_t *pChecksum, void *pMemory, uint16_t len)
Calculate checksum according to CCITT CRC16.
#define ECODE_EMDRV_NVM_ERROR
General error.
MSC_RAMFUNC_DECLARATOR MSC_Status_TypeDef MSC_WriteWord(uint32_t *address, void const *data, uint32_t numBytes)
Writes data to flash memory. This function is interrupt safe, but slower than MSC_WriteWordFast(), which writes to flash with interrupts disabled. Write data must be aligned to words and contain a number of bytes that is divisable by four.
void NVMHAL_DeInit(void)
De-initialize NVM .
#define ECODE_EMDRV_NVM_ADDR_INVALID
Invalid address.
#define ECODE_EMDRV_NVM_OK
Success return value.
Non-Volatile Memory Wear-Leveling driver HAL.
#define ECODE_EMDRV_NVM_ALIGNMENT_INVALID
Invalid data alignment.
MSC_RAMFUNC_DECLARATOR MSC_Status_TypeDef MSC_ErasePage(uint32_t *startAddress)
Erases a page in flash memory.
Ecode_t NVMHAL_Write(uint8_t *pAddress, void const *pObject, uint16_t len)
Write data to NVM.