Skip to main content
Eric_Z
Associate II
March 13, 2025
Question

STM32F413CGU6: Reset after Erase Memory command via I2C

  • March 13, 2025
  • 1 reply
  • 465 views

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

1 reply

TDK
Super User
March 13, 2025

> 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.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Eric_Z
Eric_ZAuthor
Associate II
March 13, 2025

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).