/* STM32_Serial1Passthough.ino by Matthew Ford (c)2022 Forward Computing and Control Pty. Ltd. This code is not warranted to be fit for any purpose. You may only use it at your own risk. This code may be freely used for both private and commercial use. Provide this copyright is maintained. Needs SafeString library installed from Arduino Library Manager SerialPassthrough sketch for BluePill SMT32 (STM32F103C8) Fixed baud rate 115200, TX is A9 RX is A10 connect A9 -> target RX via 1K protection resistor connect A10 -> target TX via 1K protection resistor connect GND -> target GND Green Led will flash as data sent/received ( the 1K protection resistor protects against accidental TX <-> TX connecton shorting out the devices and VDD (+supply volts) miss-matches between BluePill and target) BluePill 3V3 pin can provide 300mA of which ~50mA is used by the BluePill leaving ~250mA for powering the target Need to load Bootloader first using STM32CubeProgrammer Then need to press reset push button when Arduino tries to upload (Green Led flashes rapidly) These Compile settings for BluePill STM32F103C8 in Arduino Tools menu are IMPORTANT!! Check them all. Note the changes from default <<<<< =========================================================== Board: "Generic STM32F1 series" <<<<<<< Board part number: "BluePill F103C8 <<<<<< U(S)ART support: "Enabled (generic 'Serial')" USB support (if available): "CDC (generic 'Serial' supersede U(S)ART)" <<<<<<<< USB speed (if available): "Low/Full Speed" Optimize: "Smallest (-Os default)" Debug symboles: "None" C Runtime Library: "Newlib Nano (default)" Upload method: "Maple DFU Bootloader 2.0" <<<<<<<<< Port: "COM.." <<<<<<<<< */ // Install SafeString library from Arduino Library Manager for millisDelay class // see https://www.forward.com.au/pfod/ArduinoProgramming/TimingDelaysInArduino.html#usingMillisDelay // and https://www.forward.com.au/pfod/ArduinoProgramming/SafeString/index.html #include millisDelay flash; const unsigned long FLASH_DELAY_MS = 10; void setup() { pinMode(LED_BUILTIN, OUTPUT); Serial.begin(115200); Serial1.begin(115200); // TX1 = A9, RX1 = A10 } void loop() { if (flash.justFinished()) { digitalWrite(LED_BUILTIN, HIGH); // turn the LED off by making the voltage HIGH on BluePill } if (Serial.available()) { Serial1.write(Serial.read()); // read it and send it out Serial1 (pins A9 A10) if (!flash.isRunning()) { flash.start(FLASH_DELAY_MS); digitalWrite(LED_BUILTIN, LOW); // turn the LED on (LOW is the voltage level) } } if (Serial1.available()) { // If anything comes in Serial1 (pins A9 A10) Serial.write(Serial1.read()); // read it and send it out Serial (USB) if (!flash.isRunning()) { flash.start(FLASH_DELAY_MS); digitalWrite(LED_BUILTIN, LOW); // turn the LED on (LOW is the voltage level) } } }