I'm trying to use an STM32F411CEU as a USB to serial converter. The goal is to be able to detect when another STM32 is connected and automatically initiate flashing of that chip. For now though, I'm only using it as a simple USB to serial converter.
My problem is that I am not able to get ST tools (STM32CubeProgrammer or stm32flash) to connect to the STM32 to be flashed through this STM32F4-based converter on Windows or Linux platforms. On Mac, everything works as expected, and I am able to use this as a programmer without a problem. I am also able to serial write and read through the STM32F4 on Windows and Linux.
When debugging the problem, I see that no reply is registered for the initial 0x7f message that the ST tools send. However, the 0x7f message is received by the STM32 to be flashed, and the reply 0x79 is written to SerialUSB by the STM32F4 converter.
This is the sketch I am running on the STM32F4 USB to serial converter:
Code: Select all
/* Flash settings:
* - Board: Generic STM32F4 series
* - Board part number: Generic F411CEUx
* - USART support: Enabled, no generic Serial
* - USB support: CDC, no generic Serial
* - USB speed: Full speed
* - Upload method: STM32CubeProgrammer (DFU)
*/
#define PIN_SERIAL_RX PA10
#define PIN_SERIAL_TX PA9
HardwareSerial Serial(PIN_SERIAL_RX, PIN_SERIAL_TX);
#define NRST PA2
#define BOOT0 PA3
#define LED PA4
void resetBoardForProgramming() {
// Place board in boot mode
digitalWrite(NRST, HIGH);
pinMode(NRST, OUTPUT);
digitalWrite(BOOT0, HIGH); // set BOOT0 to enter programming mode
delay(100);
digitalWrite(NRST, LOW); // push RESET button
delay(100);
digitalWrite(NRST, HIGH); // release RESET button
delay(100);
digitalWrite(BOOT0, LOW); // will cause reset at end of programming cycle causes program start
//pinMode(NRST, INPUT);
}
void setup() {
Serial.begin(115200, SERIAL_8E1); // 8 bit data length, even parity, 1 stop bit
SerialUSB.begin();
Serial.setTimeout(500); // ms
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
pinMode(NRST, INPUT_PULLDOWN);
pinMode(BOOT0, OUTPUT);
digitalWrite(BOOT0, LOW);
digitalWrite(NRST, HIGH);
resetBoardForProgramming();
}
void loop() {
// Blink LED with 1Hz frequency
digitalWrite(LED, int(millis() / 500) % 2);
// --- Serial passthrough --- //
if (Serial.available()) { // If anything comes in Serial (USB),
SerialUSB.write(Serial.read()); // read it and send it out Serial1 (pins 0 & 1)
}
if (SerialUSB.available()) { // If anything comes in Serial (USB),
Serial.write(SerialUSB.read()); // read it and send it out Serial1 (pins 0 & 1)
}
//SerialUSB.println(String(analogRead(NRST)) + " " + String(digitalRead(NRST)) + " - " + String(analogRead(BOOT0)) + " " + String(digitalRead(BOOT0)));
}