Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions drivers/eeprom/eeprom_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static int eeprom_stm32_write(const struct device *dev, off_t offset,
{
const struct eeprom_stm32_config *config = dev->config;
const uint8_t *pbuf = buf;
HAL_StatusTypeDef ret = HAL_OK;
HAL_StatusTypeDef ret;

if (!len) {
return 0;
Expand All @@ -70,17 +70,22 @@ static int eeprom_stm32_write(const struct device *dev, off_t offset,

k_mutex_lock(&lock, K_FOREVER);

HAL_FLASHEx_DATAEEPROM_Unlock();
ret = HAL_FLASHEx_DATAEEPROM_Unlock();
if (ret != HAL_OK) {
return -EIO;
}

while (len) {
ret = HAL_FLASHEx_DATAEEPROM_Program(
FLASH_TYPEPROGRAMDATA_BYTE,
config->addr + offset, *pbuf);
if (ret) {
ret = HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE,
config->addr + offset, *pbuf);
if (ret != HAL_OK) {
LOG_ERR("failed to write to EEPROM (err %d)", ret);
HAL_FLASHEx_DATAEEPROM_Lock();
ret = HAL_FLASHEx_DATAEEPROM_Lock();
if (ret != HAL_OK) {
LOG_ERR("failed to lock to EEPROM (err %d)", ret);
}
Comment on lines +83 to +86
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HAL_FLASHEx_DATAEEPROM_Lock only implemented on L0/L1 and does not perform error checking.
I'm fine to perform the error checking, but LOG_ERR with value report seems overkill.

k_mutex_unlock(&lock);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seomthing's wrong in the 1st commit. EEPROM should be locked back. I'll fix.

return ret;
return -EIO;
}

pbuf++;
Expand All @@ -89,13 +94,15 @@ static int eeprom_stm32_write(const struct device *dev, off_t offset,
}

ret = HAL_FLASHEx_DATAEEPROM_Lock();
if (ret) {
LOG_ERR("failed to lock EEPROM (err %d)", ret);
}

k_mutex_unlock(&lock);

return ret;
if (ret != HAL_OK) {
LOG_ERR("failed to lock EEPROM (err %d)", ret);
return -EIO;
}

return 0;
}

static size_t eeprom_stm32_size(const struct device *dev)
Expand Down