Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mass erase new mtd2 #828

Merged
merged 1 commit into from
Nov 29, 2024
Merged
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
44 changes: 19 additions & 25 deletions platforms/nuttx/src/px4/common/px4_24xxxx_mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,34 +603,28 @@ int px4_at24c_initialize(FAR struct i2c_master_s *dev,
priv->perf_errors = perf_alloc(PC_COUNT, "[at24c] eeprom errors");
}

/* attempt to read to validate device is present */
unsigned char buf[5];
uint8_t addrbuf[2] = {0, 0};
/* attempt to read last page to validate device is present */

struct i2c_msg_s msgv[2] = {
{
.frequency = 400000,
.addr = priv->addr,
.flags = 0,
.buffer = &addrbuf[0],
.length = sizeof(addrbuf),
},
{
.frequency = 400000,
.addr = priv->addr,
.flags = I2C_M_READ,
.buffer = &buf[0],
.length = sizeof(buf),
}
};
uint8_t buf[AT24XX_PAGESIZE];
int ret = at24c_bread((FAR struct mtd_dev_s *)priv,
AT24XX_NPAGES - 1,
1,
buf);

BOARD_EEPROM_WP_CTRL(true);
if (ret != 1) {
ferr("Read failed, mass erase, ret %d\n", ret);

at24c_eraseall(&g_at24c[number_of_instances]);

perf_begin(priv->perf_transfers);
int ret = I2C_TRANSFER(priv->dev, &msgv[0], 2);
perf_end(priv->perf_transfers);
/* Try to read again */

ret = at24c_bread((FAR struct mtd_dev_s *)priv,
AT24XX_NPAGES - 1,
1,
buf);
}

if (ret < 0) {
if (ret != 1) {
perf_free(priv->perf_transfers);
perf_free(priv->perf_resets_retries);
perf_free(priv->perf_errors);
Expand All @@ -639,7 +633,7 @@ int px4_at24c_initialize(FAR struct i2c_master_s *dev,
priv->perf_resets_retries = NULL;
priv->perf_errors = NULL;

return ret;
return -1;
}

*mtd_dev = (FAR struct mtd_dev_s *)priv;
Expand Down
Loading