Either way, you will have to choose some serial port pins on your driver board, and connect them. Either using the ST-Link or by using another TTL Serial to USB adapter.
I’m using nucleo, should work (when i short RX to gnd it shows “something”) so my stspin32 don’t send anything on Serial (PA9 PA10), when i try to build with Serial1 (included “HardwareSerial.h”) i get
Processing genericSTM32G431VB (platform: ststm32; board: genericSTM32G431VB; framework: arduino)
-------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32G431VB.html
PLATFORM: ST STM32 (17.0.0) > STM32G431VB
HARDWARE: STM32G431VBT6 170MHz, 32KB RAM, 126KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, cmsis-dap, jlink)
PACKAGES:
- framework-arduinoststm32 @ 4.20600.231001 (2.6.0)
- framework-cmsis @ 2.50700.210515 (5.7.0)
- toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 15 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Adafruit NeoPixel @ 1.12.0
|-- SimpleFOCDrivers @ 1.0.6
|-- Simple FOC @ 2.3.2
Building in release mode
Compiling .pio\build\genericSTM32G431VB\src\main.cpp.o
Linking .pio\build\genericSTM32G431VB\firmware.elf
c:/users/tomek/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: warning: .pio/build/genericSTM32G431VB/firmware.elf has a LOAD segment
with RWX permissions
c:/users/tomek/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/genericSTM32G431VB/src/main.cpp.o: in function `loop':
main.cpp:(.text.loop+0x38): undefined reference to `Serial1'
c:/users/tomek/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/genericSTM32G431VB/src/main.cpp.o: in function `setup':
main.cpp:(.text.setup+0x60): undefined reference to `Serial1'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\genericSTM32G431VB\firmware.elf] Error 1
===================================== [FAILED] Took 27.18 seconds =====================================
* The terminal process "C:\Users\tomek\.platformio\penv\Scripts\platformio.exe 'run', '--environment', 'genericSTM32G431VB'" terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.
i connected RX TX with my debugger and run code with stmcubeide which sends sth on serial monitor, works perfect
when im trying do it with platformio i get nothing
i tried Serial.begin(hardware uart), mySerial.begin(software uart “SoftwareSerial.h”)
even copy pasted hal init, clock init and usart init from stmcubeide (generated by cubemx, same which works in stmcubemx) and then tried to
HAL_UART_Transmit(&huart1, (uint8_t*)message, strlen(message), HAL_MAX_DELAY);
still nothing
Serial1.begin doesn’t compile, like i said earlier
to your platformio.ini, and then the normal “Serial” object should refer to USART1.
Make sure the options for USB serial are not set!
Additionally you need to set the correct pins, if they’re not the default ones:
-DPIN_SERIAL1_RX PA_10
-DPIN_SERIAL1_TX PA_9
Here you have to check the pinmap for the serial functions. Sometimes the pin you’re using needs to be specified using an alternate function, like: PA_10_ALT1
You can’t set any of this using #define - you have to put it into build flags so it acts on the entire build, including the framework.
Are you sure that platformio is looking for the right serial port? Annoyingly, for me, it will always default to the wrong port, either you can manuall set it in platformio.ini with monitor_port = or by pressing Ctrl T then P.
I’ve recently got serial working on my custom stspin32g4 board (coincidence!!)
Had a problem too, I was using a stlink3-minie which has a virtual com port. Annoyingly their idea of rx / tx is opposite to what I was expecting (t_vcp_rx seems to means target rx not stlink rx). Grrr.
Anyway back to your problem. As a debugging step:
Try this:
import SoftwareSerial;
SoftwareSerial mySerial(PA10, PA9);
// SoftwareSerial mySerial(PA9, PA10); <- Try this too
void setup() {
mySerial.begin(115200); //<- or what ever you have setup as monitor_speed in platfromio.ini
delay(1000);
mySerial.printn("hello world");
}
Once you get SoftwareSerial working, you can try to sort out HardwareSerial e.g. following steps recommended by others.
In my case I can only get SoftwareSerial on this first revision of my board as my pcb layout is wrong
STM32duino is perhaps a little too flexible in its serial configuration options. Its really super-confusing, but usually a combination of setting the UART instance and the right pins leads to success…
Hmmmm… not sure what is happening there. Perhaps you still need to add a motor.enable() if you’re not calling the initFOC() method due to open loop mode?