SPRADL4 January 2025 F29H850TU , F29H859TU-Q1
The EEPROM_Config_Check() function provides general error-checking and configures Write/Erase protection masks required by the Flash API. This function should be called before programming or reading from the emulated EEPROM Unit(s).
First, the function verifies that the Flash Bank selected for EEPROM Emulation is valid. Only the data bank is a valid selection on F29x.
if (FLASH_BANK_SELECT != C29FlashBankFR4RP0StartAddress)
{
return 0xFFFF;
}
Second, the validity of Flash Sectors selected for emulation is examined. This function checks for:
uint32_t NUM_EEPROM_SECTORS_1 = FIRST_AND_LAST_SECTOR[0][1] - FIRST_AND_LAST_SECTOR[0][0] + 1;
uint32_t NUM_EEPROM_SECTORS_2 = FIRST_AND_LAST_SECTOR[1][1] - FIRST_AND_LAST_SECTOR[1][0] + 1;
if (NUM_EEPROM_SECTORS_1 != NUM_EEPROM_SECTORS_2)
{
return 0xEEEE;
}if (NUM_EEPROM_SECTORS > NUM_FLASH_SECTORS || NUM_EEPROM_SECTORS == 0)
{
return 0xEEEE;
}if (NUM_EEPROM_SECTORS > 1)
{
if (FIRST_AND_LAST_SECTOR[0][1] <= FIRST_AND_LAST_SECTOR[0][0])
{
return 0xEEEE;
}
if (FIRST_AND_LAST_SECTOR[1][1] <= FIRST_AND_LAST_SECTOR[1][0])
{
return 0xEEEE;
}
if (FIRST_AND_LAST_SECTOR[0][1] > NUM_FLASH_SECTORS - 1 || FIRST_AND_LAST_SECTOR[0][1] < 1)
{
return 0xEEEE;
}
if (FIRST_AND_LAST_SECTOR[1][1] > NUM_FLASH_SECTORS - 1 || FIRST_AND_LAST_SECTOR[1][1] < 1)
{
return 0xEEEE;
}
}
else if (FIRST_AND_LAST_SECTOR[0][0] > NUM_FLASH_SECTORS - 1 ||
FIRST_AND_LAST_SECTOR[1][0] > NUM_FLASH_SECTORS - 1)
{
return 0xEEEE;
}if (FIRST_AND_LAST_SECTOR[0][0] <= FIRST_AND_LAST_SECTOR[1][1] &&
FIRST_AND_LAST_SECTOR[1][0] <= FIRST_AND_LAST_SECTOR[0][1])
{
return 0xEEEE;
}
Bank_Size = WRITE_SIZE_BYTES*2 +
((EEPROM_PAGE_DATA_SIZE + WRITE_SIZE_BYTES*2) * NUM_EEPROM_PAGES);
uint32_t Available_Words = NUM_EEPROM_SECTORS * FLASH_SECTOR_SIZE;
if (Bank_Size * NUM_EEPROM_BANKS > Available_Words)
{
return 0xCCCC;
}uint64_t WE_Protection_AB_Sectors_Unit_0 = Configure_Protection_Masks(FIRST_AND_LAST_SECTOR[0],
NUM_EEPROM_SECTORS);
uint64_t WE_Protection_AB_Sectors_Unit_1 = Configure_Protection_Masks(FIRST_AND_LAST_SECTOR[1],
NUM_EEPROM_SECTORS);
if (WE_Protection_AB_Sectors_Unit_0 & WE_Protection_AB_Sectors_Unit_1)
{
return 0xEEEE;
}
If one of the following nonfatal conditions is detected, a warning is issued. Each flag corresponds to a bit in the return value of the function:
if (Available_Words - (Bank_Size * NUM_EEPROM_BANKS ) >= Bank_Size)
{
Warning_Flags += 1;
}if (EEPROM_PAGE_DATA_SIZE <= WRITE_SIZE_BYTES)
{
Warning_Flags += 2;
}If using sectors in the 32-127 range (for F29H85x devices) and not using all eight sectors allocated to a single bit in the Write/Erase Protection Mask, a warning is issued. Any unused sectors within the eight designed by a single bit cannot be properly be protected from erase. For more information on how the Write/Erase Protection Masks correspond to sectors, see the F29H85x Flash API Reference Guide
uint8_t i;
for (i = 0; i < 2; i++)
{
// If using any sectors > 31
if (FIRST_AND_LAST_SECTOR[i][1] > 31)
{
// If all sectors are > 31 (use protection mask B)
if (FIRST_AND_LAST_SECTOR[i][0] > 31)
{
// If using < 8 sectors (will be clearing more than necessary)
if (NUM_EEPROM_SECTORS < 8)
{
Warning_Flags += 4;
break;
}
// if sector isn't a multiple of 8 (will be clearing more than necessary)
else if ((FIRST_AND_LAST_SECTOR[i][0] % 8) != 0 ||
(FIRST_AND_LAST_SECTOR[i][1] + 1) % 8 != 0)
{
Warning_Flags += 4;
break;
}
}
// if sector isn't a multiple of 8 (will be clearing more than necessary)
else if ((FIRST_AND_LAST_SECTOR[i][1] + 1) % 8 != 0)
{
Warning_Flags += 4;
break;
}
}
}