nimaltd / ee24

24xx EEPROM library for stm32 HAL
GNU General Public License v3.0
149 stars 41 forks source link

Erase chip function has a problem #7

Closed SMotlaq closed 4 years ago

SMotlaq commented 4 years ago

In this function:

bool ee24_eraseChip(I2C_HandleTypeDef* i2c)
{
  const uint8_t eraseData[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF\
    , 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  uint32_t bytes = 0;
  while ( bytes < (_EEPROM_SIZE_KBIT / 8) * 1024)
  {
    if (ee24_write(i2c, bytes, (uint8_t*)eraseData, sizeof(eraseData), 100) == false)
      return false;
    bytes += sizeof(eraseData);           
  }
  return true;  
}

If _EEPROM_SIZE_KBIT was less than 8, the while condition will be always false because for example 2 divided by 8 is 0 in non-floating values. I think the condition should be like this: while ( bytes < (_EEPROM_SIZE_KBIT * 256))

Also I didn't find out what does this condition mean 🤔. Anyway, thanks for your attention 🙏🏻

(I made a little changes in inputs and I2C handler pointer, but it isn't the problem 😅)

nimaltd commented 4 years ago

I dont think si. Ee24_write automatically write any lenght data

SMotlaq commented 4 years ago

I mean the while will never run. Because ( bytes < (_EEPROM_SIZE_KBIT / 8) * 1024) is always false. My EEPROM is 2K. 2/8 is 0, the "bytes" variable is greater than (or equal to) 0 everytime.

nimaltd commented 4 years ago

oh . okay. I got it. thanks.