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
37 changes: 23 additions & 14 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 hal_ret;

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

k_mutex_lock(&lock, K_FOREVER);

HAL_FLASHEx_DATAEEPROM_Unlock();
hal_ret = HAL_FLASHEx_DATAEEPROM_Unlock();
if (hal_ret != HAL_OK) {
LOG_ERR("failed to unlock to EEPROM");
Copy link
Member

Choose a reason for hiding this comment

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

LOG_ERR still feels overkill but ok

goto out;
}

while (len) {
ret = HAL_FLASHEx_DATAEEPROM_Program(
FLASH_TYPEPROGRAMDATA_BYTE,
config->addr + offset, *pbuf);
if (ret) {
LOG_ERR("failed to write to EEPROM (err %d)", ret);
HAL_FLASHEx_DATAEEPROM_Lock();
k_mutex_unlock(&lock);
return ret;
hal_ret = HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE,
config->addr + offset, *pbuf);
if (hal_ret != HAL_OK) {
LOG_ERR("failed to write to EEPROM (err %d)", hal_ret);
if (HAL_FLASHEx_DATAEEPROM_Lock() != HAL_OK) {
LOG_ERR("failed to lock to EEPROM");
}
goto out;
}

pbuf++;
offset++;
len--;
}

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

out:
k_mutex_unlock(&lock);

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

return 0;
}

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