标签/分类 "eeprom" 下的文章
STM32L073RZ -EEPROM 踩过的一些坑
代码 uint16_t bsp_eeprom_write (uint32_t WriteAddr, uint8_t *pBuffer, uint16_t NumToWrite) { uint16_t t,err = 0; assert_param( ( DATA_EEPROM_BASE + WriteAddr ) >= DATA_EEPROM_BASE ); assert_param( pBuffer != NULL ); if (HAL_FLASHEx_DATAEEPROM_Unlock()!= HAL_OK) { err |= EEPROM_UNLOCK_ERR; } for (t = 0; t < NumToWrite; t++) { if (HAL_FLASHEx_DATAEEPROM_Program (FLASH_TYPEPROGRAMDATA_BYTE, (DATA_EEPROM_BASE + WriteAddr + t), pBuffer[t])!=HAL_OK) { err |= EEPROM_PROGRAM_ERR; break; } } if (HAL_FLASHEx_DATAEEPROM_Lock() != HAL_OK) { err |= EEPROM_LOCK_ERR; } return err; } //PageRange 0-511 uint16_t bsp_eeprom_easer_page (uint16_t startPage, uint16_t endPage) { uint16_t t,err = 0; for (t = startPage ; t <= endPage; t++) { dbg_printf("-->[data ] DATA_EEPROM_BASE + WriteAddr + t:0X%X\r\n",DATA_EEPROM_BASE + t * 4); if (HAL_FLASHEx_DATAEEPROM_Erase (DATA_EEPROM_BASE + t * 4) !=HAL_OK) { err |= EEPROM_EASER_ERR;