Serial programming STM32F446 using ESP32-Wroom
The question gives away most of what I am trying to accomplish. I got a project for which I need to update the code/firmware and to test what I do. I have a device (PCB with peripherals).
How things are connected?
I have an ESP32-Wroom which is like the main MCU and it talks to most peripherals and an onboard STM32F446RETx MCU. GPIO25 and GPIO26 of the ESP32 connect with PA9 and PA10 forming a serial connection. I have an onboard jumper that I can use to tap into PA9 and PA10 in addition to another pin duo that I can use to hear Serial of the ESP32. I also have another pin duo that I can use to connect ST-Link SWD with STM32 as well. In case you got distracted about what I am trying to do, I only want to serially program the STM32 using ESP32.
What does the code that I have do?
The ESP32 code sets the BOOT0 to high and BOOT1 to low before starting Serial1 connection (using IO25 IO26) using even parity and 1 stop bit as per the ST guidelines. Then comes the part of initiating the handshake Serial1.write(0x7f) with hope of getting 0x79. However, the response I get is neither NACK (0x1f) nor BUSY (0x76), and it not an ACK either in case you wanted to read things explicitly.
What did I do next?
The PCB has a jumper that allows me tap into PA9 and PA10 connections of STM so I just put the BOOT pins in pattern 1 (as per AN2606 or whatever application note has the pattern) and try using stm32flash to get the chip information but nothing comes from the STM.
I would really like to know if there is something that I can do to salvage the situation. Feel free to ask follow up questions for clarity.
Edit 1: Added ESP32 code responsible for the handshake
int STM32BL_Init(void)
{
bool status = false;
pinMode(STM_BOOT_0, OUTPUT);
pinMode(STM_BOOT_1, OUTPUT);
// Configure USART
Serial1.end();
Serial.println("Restarting UART1");
delay(100);
Serial1.begin(9600, SERIAL_8E1, 25, 26); // UART1
Serial1.setTimeout(1000);
delay(100);
// Activate pattern 1
Serial.println("Activating pattern 1");
digitalWrite(STM_BOOT_0, HIGH);
digitalWrite(STM_BOOT_1, LOW);
// Send handshake byte and look for ACK
int retries = 10;
if (Serial1.available()) Serial1.write(STM32_CMD_INIT);
else
{
Serial.println("Serial1 not available");
}
char ack;// = (char)Serial1.read();
while (((ack = (char) Serial1.read()) != STM32_ACK) && retries > 0)
{
Serial.println("Handshake failed!");
printf("Received %x\n", ack);
//ack = (char) Serial.read();
delay(50);
retries--;
}
flash_ptr = 0x08008000;
return status;
}