Skip to content

Commit

Permalink
px4_24xxxx_mtd.c: Fix mass erase in case device is not responding
Browse files Browse the repository at this point in the history
Return -ENODEV if the device is not responding in mass erase

Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Dec 3, 2024
1 parent 29060c5 commit b8843e0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions platforms/nuttx/src/px4/common/px4_24xxxx_mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ static int at24c_eraseall(FAR struct at24c_dev_s *priv)
{
int startblock = 0;
uint8_t buf[AT24XX_PAGESIZE + 2];
int tries;

struct i2c_msg_s msgv[1] = {
{
Expand All @@ -235,9 +236,15 @@ static int at24c_eraseall(FAR struct at24c_dev_s *priv)
buf[1] = offset & 0xff;
buf[0] = (offset >> 8) & 0xff;

tries = 10;

while (I2C_TRANSFER(priv->dev, &msgv[0], 1) < 0) {
fwarn("erase stall\n");
px4_usleep(10000);

if (--tries == 0) {
return -ENODEV;
}
}
}

Expand Down

0 comments on commit b8843e0

Please sign in to comment.