Serial Monitor for a custom board

For my project, i am using the STM32L082KZT6. I have made a custom board file for it and fixed the variants, however after uploading i cannot read the Serial monitor even though i have this in the platformio.ini:

[env:JENG_STM32L082KZ]
platform = ststm32
board = JENG_STM32L082KZ
framework = arduino
monitor_speed = 9600
upload_protocol = stlink
debug_tool = stlink

and in the variant.h:

#define SERIAL_UART_INSTANCE 2 //ex: 2 for Serial2 (USART2)
// Default pin used for ‘Serial’ instance (ex: ST-Link)

// Mandatory for Firmata
#define PIN_SERIAL_RX 0
#define PIN_SERIAL_TX 1

The variant code is based on the NucleoL073RZ variant.h file which uses the same pins and same LPUART1 protocol on these pins. I have tried setting the PIN_SERIAL’s to PA_13 and PA_14 but this also did not work.

(I also have gotten the other necessary files from https://github.com/stm32duino/Arduino_Tools/tree/master/src/genpinmap/Arduino/STM32L0/STM32L082K(B-Z)Tx)

Exactly, PA13 and PA14 are LPUART1_RX and LPUART1_TX, so if you want these pins it has to be serial instance 0 (maps to LPUART) and rx,tx pins defined to PA13 and PA14 (not PA_13. PinName enum and integer mapping are different)

So try

#define SERIAL_UART_INSTANCE 0 //ex: 2 for Serial2 (USART2)
// Default pin used for ‘Serial’ instance (ex: ST-Link)

// Mandatory for Firmata
#define PIN_SERIAL_RX PA13
#define PIN_SERIAL_TX PA14

Currently you’re telling it to use USART2 and pins 0, 1 map to PA2,PA3 (see on top the variant.h file)

Can you blink an LED before that? Because if not, then MCU doesn’t even reach the setup() or loop() function, indicating a clock setup failure or something else.

2 Likes

Thank you for your input, the program already ran propperly and the Serial Monitor was not working yet but that is now fixed due to the Instance 0.

1 Like