S32DS踩坑日记三-使用EEPROM

这个片子的EEPROM是用普通的flash模拟的,所以配置比较复杂。需要先增加flash,然后再配置模拟EEPROM那块的电路。

这个模拟的大概意思是这样:片子内置一块用于数据存储的flash,叫D-flash,大小是64K,起始地址为0x1000-0000。还有一片用来模拟EEPROM的内存,大小是4K,位置是0x1400-0000。这两样东西正常情况下就是它原本的用途。但是经过配置FlexNVM里面的电路后,就可以在写内存的时候,自动把数据写到D-flash里面。不知道这种设计的背景是什么,大概就是这么个东西。

S32DS踩坑日记三-使用EEPROM_第1张图片

初始化:比较复杂,整个D-flash都配置成EEPROM了,配置后大小是4K。
flash_ssd_config_t SSDConfig;
/* Flash初始化,这个比较复杂,因为EEEFlash(flash模拟EEPROM)的原因。 /
{
INT_SYS_DisableIRQGlobal();
status_t ret;
do
{
ret = FLASH_DRV_Init(&Flash1_InitConfig0, &SSDConfig);
}
while(ret != STATUS_SUCCESS);
if (SSDConfig.EEESize == 0u)
{
/
Configure FlexRAM as EEPROM and FlexNVM as EEPROM backup region,
* DEFlashPartition will be failed if the IFR region isn’t blank.
* Refer to the device document for valid EEPROM Data Size Code
* and FlexNVM Partition Code. For example on S32K144:
* - EEEDataSizeCode = 0x02u: EEPROM size = 4 Kbytes
* - DEPartitionCode = 0x08u: EEPROM backup size = 64 Kbytes */
ret = FLASH_DRV_DEFlashPartition(&SSDConfig, 0x02u, 0x08u, 0x0u, false, true);
DEV_ASSERT(STATUS_SUCCESS == ret);

	        /* Re-initialize the driver to update the new EEPROM configuration */
	        ret = FLASH_DRV_Init(&Flash1_InitConfig0, &SSDConfig);
	        DEV_ASSERT(STATUS_SUCCESS == ret);

	        /* Make FlexRAM available for EEPROM */
	        ret = FLASH_DRV_SetFlexRamFunction(&SSDConfig, EEE_ENABLE, 0x00u, NULL);
	        DEV_ASSERT(STATUS_SUCCESS == ret);
	    }
	    else    /* FLexRAM is already configured as EEPROM */
	    {
	        /* Make FlexRAM available for EEPROM, make sure that FlexNVM and FlexRAM
	         * are already partitioned successfully before */
	        ret = FLASH_DRV_SetFlexRamFunction(&SSDConfig, EEE_ENABLE, 0x00u, NULL);
	        DEV_ASSERT(STATUS_SUCCESS == ret);
	    }
	INT_SYS_EnableIRQGlobal();
}

读写这个假的EEPROM:
{
status_t ret;
uint32_t address;
uint32_t size;
uint8_t sourceBuffer[sizeof(uint32_t)];
uint32_t rbval;

if (SSDConfig.EEESize != 0u)
{
    address = SSDConfig.EERAMBase;
    size = sizeof(uint32_t);
    sourceBuffer[0] = 0x11;
    sourceBuffer[1] = 0x22;
    sourceBuffer[2] = 0x33;
    sourceBuffer[3] = 0x44;
    ret = FLASH_DRV_EEEWrite(&SSDConfig, address, size, sourceBuffer);
    DEV_ASSERT(STATUS_SUCCESS == ret);

    do
    {
    	rbval = *((uint32_t *)address);
    }
    while(rbval != 0x44332211);
}

}

你可能感兴趣的:(单片机)