Generic STM32F030K6T6 - Serial does not work

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
peekay123
Posts: 4
Joined: Tue Aug 20, 2024 12:49 am
Answers: 1

Generic STM32F030K6T6 - Serial does not work

Post by peekay123 »

I am using Arduino IDE v2.3.2 with this basic STM32F030K6T6 from Aliexpres:

https://www.aliexpress.com/item/1005001 ... 1802kPAicZ

The board is set to "Generic STM32F0 series", the board part number is "Generic F030K6Tx" and I use "STM32CubeProgrammer (Serial) for flashing using an FT232 USB-to-Serial adapter on Windows 10. Serial programming works flawlessly. In the IDE, U(S)ART Support is "Enabled (Generic 'Serial')" and the "C Runtime Library" is set to "Newlib Nano (default)".

When I try a simple sketch that does Serial.printl("Testing...") every second along with blinking an LED, nothing appears on the Serial port (using the same FT232 to receive) but the LED blinks.

Any guidance is greatly appreciated.
by peekay123 » Thu Aug 22, 2024 4:33 pm
Your post made me think and I now realize that the serial programming connector on the board connects to PA9/PA10 UART pins and not the PA2/PA3 UART pins. So, even though I use the PA9 and PA10 pins for I2C, when in bootloader mode, the pullups don't affect the NRZ nature of the serial port. However, and I'm not sure where I parked my brain for this, I was expecting the serial output on the same PA9/PA10 pins!!!

So, I either a) move the I2C pins to PB6/PB7 or monitor the Serial output on PA2/PA3 (default in the generic variant).

Thanks for making me think this one out!
Go to full post
peekay123
Posts: 4
Joined: Tue Aug 20, 2024 12:49 am
Answers: 1

Re: Generic STM32F030K6T6 - Serial does not work

Post by peekay123 »

Crickets! So, does anyone know where in the Serial object is instantiated?
fpiSTM
Posts: 1946
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

Re: Generic STM32F030K6T6 - Serial does not work

Post by fpiSTM »

Generic drine a default Serial but are you sure you used those ones?
peekay123
Posts: 4
Joined: Tue Aug 20, 2024 12:49 am
Answers: 1

Re: Generic STM32F030K6T6 - Serial does not work

Post by peekay123 »

I am using the Generic STM32F0 Series / Genric F030K6Tx configuration. The variant_generic.h file used in the variant folder does include the typical Serial stuff with the correct RX/TX pin definitions. I can't however, figure out where the Serial object actually gets created. I see HardwareSerial being used for Serial1 and above but nothing for Serial.

Code: Select all

// Default pin used for generic 'Serial' instance
// Mandatory for Firmata
#ifndef PIN_SERIAL_RX
  #define PIN_SERIAL_RX         PA3
#endif
#ifndef PIN_SERIAL_TX
  #define PIN_SERIAL_TX         PA2
#endif

/*----------------------------------------------------------------------------
 *        Arduino objects - C++ only
 *----------------------------------------------------------------------------*/

#ifdef __cplusplus
  // These serial port names are intended to allow libraries and architecture-neutral
  // sketches to automatically default to the correct port name for a particular type
  // of use.  For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
  // the first hardware serial port whose RX/TX pins are not dedicated to another use.
  //
  // SERIAL_PORT_MONITOR        Port which normally prints to the Arduino Serial Monitor
  //
  // SERIAL_PORT_USBVIRTUAL     Port which is USB virtual serial
  //
  // SERIAL_PORT_LINUXBRIDGE    Port which connects to a Linux system via Bridge library
  //
  // SERIAL_PORT_HARDWARE       Hardware serial port, physical RX & TX pins.
  //
  // SERIAL_PORT_HARDWARE_OPEN  Hardware serial ports which are open for use.  Their RX & TX
  //                            pins are NOT connected to anything by default.
  #ifndef SERIAL_PORT_MONITOR
    #define SERIAL_PORT_MONITOR   Serial
  #endif
  #ifndef SERIAL_PORT_HARDWARE
    #define SERIAL_PORT_HARDWARE  Serial
  #endif
#endif
ag123
Posts: 1901
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: Generic STM32F030K6T6 - Serial does not work

Post by ag123 »

As in the wiki
https://github.com/stm32duino/Arduino_C ... wareserial

Code: Select all

//                      RX    TX
HardwareSerial SerialMy(PA10, PA9);

void setup() {
  SerialMy.begin(115200); 
}

void loop() {
  SerialMy.println("Hello World!");
  delay(1000);
}
and on that same page, some symbols are predefined
Serial1 for USART1
Serial2 for USART2
Serial3 for USART3
Serial normally goes to Serial1 (select that on the IDE menu)

so you could do like

Code: Select all

void setup() {
	Serial1.begin(115200);
	Serial1.println("hello world");
}
baud rates are important for uart ports.
GonzoG
Posts: 495
Joined: Wed Jan 15, 2020 11:30 am
Answers: 36
Location: Prudnik, Poland

Re: Generic STM32F030K6T6 - Serial does not work

Post by GonzoG »

There is no one definition of what "Serial" object is. It's just an alias.
It all depends on IDE settings (Tools menu) and default board definitions.
It can be USB, LPUART or any U(S)ART interface.
If default instance is 1, it will be assigned to Serial1,
if 2 it will be assigned to Serial2 and so on.

So it's always set to a default serial interface with current settings.

For generic F030K6 it's Serial1 with pins PA3, PA2.
In WSerial.h:

Code: Select all

...
    #elif SERIAL_UART_INSTANCE == 1
      #define ENABLE_HWSERIAL1
      #if !defined(Serial)
        #define Serial Serial1
        #define serialEvent serialEvent1
      #endif
peekay123
Posts: 4
Joined: Tue Aug 20, 2024 12:49 am
Answers: 1

Re: Generic STM32F030K6T6 - Serial does not work

Post by peekay123 »

Your post made me think and I now realize that the serial programming connector on the board connects to PA9/PA10 UART pins and not the PA2/PA3 UART pins. So, even though I use the PA9 and PA10 pins for I2C, when in bootloader mode, the pullups don't affect the NRZ nature of the serial port. However, and I'm not sure where I parked my brain for this, I was expecting the serial output on the same PA9/PA10 pins!!!

So, I either a) move the I2C pins to PB6/PB7 or monitor the Serial output on PA2/PA3 (default in the generic variant).

Thanks for making me think this one out!
Post Reply

Return to “General discussion”