STM32F413CGU6: Reset after Erase Memory command via I2C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-13 6:27 AM - edited ‎2025-03-13 6:35 AM
Hello,
with an ESP8266 I execute an erase memory command for the STM32F413CGU6 and when the sector is erased, the STM32 always performs a reset. The sector is erased afterwards, but the ESP doesn't have acces to the Boot0 pin and afterwards the STM32 isn't anymore in the boot mode.
This is the function for erasing the memory:
#define I2C_ADDRESS 0x4B // 7-bit I2C address of the STM32 device
bool eraseSectors(HardwareSerial &serial, TwoWire Wire, uint8_t numSectors, uint8_t sector) {
Wire.beginTransmission(I2C_ADDRESS);
Wire.write(0x00); // Send MSB of sector count
Wire.write(0x00); // Send LSB of sector count
Wire.write(0x00); // Send checksum
Wire.endTransmission();
uint8_t count = 0;
while ((!receiveAck(Wire)) && count < 10) {
Serial.println(count);
delay(1000);
count++;
}
count = 0;
// Step 3: Send the actual sector numbers
Serial.println("erase pages");
Wire.beginTransmission(I2C_ADDRESS);
Wire.write(0x00); // Send MSB of sector number
Wire.write(sector); // Send LSB of sector number
Wire.write(sector); // Send checksum for sector numbers
Wire.endTransmission();
// Step 4: Wait for ACK after sending sector numbers and checksum
while ((!receiveAck(Wire)) && count < 10) {
Serial.println(count);
delay(1000);
count++;
}
count = 0;
Serial.println("Sector erased successfully");
return true;
}
Can someone please tell me where the error is?
Thanks in advance
Eric
- Labels:
-
Bootloader
-
Flash
-
I2C
-
STM32F4 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-13 6:40 AM
> when the sector is erased, the STM32 always performs a reset
What makes you think this? Do you receive an ACK? Code just silently falls through if one is not received.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-13 6:51 AM - edited ‎2025-03-13 6:54 AM
The reset pin of the STM and the ESP are connected together. Also the ESP resets.
The ACK from the STM for the number of pages is 79 and for the selected sector is DE (it should be 79 aswell).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-13 6:57 AM
This is the function for receiving the ACKs:
bool receiveAck(TwoWire Wire) {
uint8_t response = 0;
Wire.requestFrom(I2C_ADDRESS_R, 1); // Request 1 byte from STM32
while (Wire.available()) {
response = Wire.read();
if (response == STM32_ACK) {
Serial.printf("%02X\n", response);
return true;
}
}
Serial.printf("%02X\n", response);
return false;
}
