Question about using serial monitor communicate with STM32

hello,I am new to this forum.I am using Arduino IDE to write code for STM32 for some project.When i download STM32duino(GitHub - stm32duino/Arduino_Core_STM32: STM32 core support for Arduino) to use it.I want to use STM32 USART to communicate and i hope that message will show on the serial monitor.My code is shown below.

HardwareSerial Serial1(PA10,PA9); 
void setup() {
  pinMode(PA5,OUTPUT);
  Serial.begin(115200);
}

void loop() {
  digitalWrite(PA5, HIGH);
  delay(1000);
  digitalWrite(PA5, LOW);
  delay(1000);
  Serial.println("turn on the LED");
}

when i delete line 1 ,code is working but only led is blinking , there are no messages on the serial monitor.But when i add line 1 code,there is a error when i start to verify:
no matching function for call to 'HardwareSerial::HardwareSerial(, )'

So in my opinion,i don,t have library to use HardwareSerial function.How can i use this function or how can i write the code to use serial monitor to communicate with STM32 board?
Thanks!

maybe
Serial1.begin(115200);

show schematic what and how you have connected

Well downloading a core is not sufficient to make it work.
Did you really install the STM32-core with the board-manager of the arduino-IDE?

What about googling. I quogled "Arduino STM32" second hit guided to this

Though the docs state
By default, only one Serialx instance is available mapped to the generic Serial name.

So it should work with "Serial"

EDIT: / ADDITION

there is a forum dedicated to STM32. I estimate the probability to get an answer in this forum ist higher
https://www.stm32duino.com/index.php

best regards Stefan

If you go to the board-manager and filter with "stm32" to see what options were shown it shows
three options

As you can see from the screenshot I have installed the


option.

With this core installed using the generic Serial compiled just fine

//HardwareSerial Serial1(PA10,PA9);

void setup() {
  pinMode(PA5,OUTPUT);
  Serial.begin(115200);
}


void loop() {
  digitalWrite(PA5, HIGH);
  delay(1000);
  digitalWrite(PA5, LOW);
  delay(1000);
  Serial.println("turn on the LED");
}

best regards Stefan

Serial1.begin(115200); doesn,t work.
My board is STM32F103RB,i connnect on ST-link port(mini B connector) with an usb line with my computer.Other than that, there's no other connection.

hello StefanL38
in my board manager,i have installed this one.But serial monitor has no message.


And I'll try the link you provided.Thanks!

when using a STM32F103C8T6 I found Getting-Started-With-Stm32-Using-Arduino-IDE useful
and setting up Serial2 and Serial3 Arduino_Core_STM32 API

I started a thread that asks for an easy to use STM-core.
It turned out that assigning IO-pins for the serial interface is not possible

You have to use exact that IO-pins the serial interface is hardwired to inside the microcontroller.

This means there i sno need to assign the IO-pins. And this seems to be the reason why HardwareSerial accepts only te baudrate as parameter.

I compiled this democode successfully

void setup() {
  pinMode(PA5,OUTPUT);
  Serial1.begin(115200);
  Serial2.begin(9600);
  Serial3.begin(19200);
}

void loop() {
  digitalWrite(PA5, HIGH);
  Serial1.println("turn on the LED");
  Serial2.println("turn on the LED");
  Serial3.println("turn on the LED");
delay(1000);
  digitalWrite(PA5, LOW);
  Serial2.println("turn off the LED");
  delay(1000);
}

this compiled for several STM-boards.
So if you use that IO-pins that are dedicated to a serial interface instead of trying to define them new it should work

best regards Stefan

although I have experimented with the Arduino IDE programming the STM32 for serious work I use STM32cubeIDE using a ST-LINK

There are different - incompatible - cores to support STM32. This is the result of history: The first one was by Roger Clark, based on the LeafLabs software. It supports only a subset of the STM32 processors. Later on STM decided to develop a generic core, that supports nearly all of STM32 processors. And there maybe other cores as well.
Unfortunately this makes things more complicated. As with all cores not directly supported by Arduino you first have to add a boardmanager URL in preferences. The board manager only shows cores with a correspondingt URL.

This is a borad manager with both cores installed. The first entry is STM core ( you can see the many supported processors), the two following are by Roger Clark:

The Name STM32duino is also disturbing, because it was first used by R.C. but now it is used by STM also.

The Github repository of Roger Clark also provides bootloaders, that allow uploading via the USB connector. Also Serial is assigned to USB - not to any USART line ( the STM32F103 has a native USB hardware).

@z_hang_zju : The Github link in your post #1 shows another core (STM generic ) than your screenshot in post #6 ( Core by Roger Clark ). Your first line may not be compatible to the core of Roger Clark.
Please post exactly which board you have (not only processor - there are many different STM32 boards even with the same processor ) and how it is wired and connected to your PC. If you only have an ST-link connection, there may be no connection to the serial monitor at all.

The USART pins can be changed to alternate pins - but not freely. Usually the USART HW has two set of pins that can be selected. I think that's what can be done with HardwareSerial of the STM core. So you must know which pins can be selected. You have to ask the datasheet of your processor :wink:
I have only used the STM core sporadically and at a very superficial level so far.

I started a thread about this question.
Post 12 seems to be helpful

Not fully true. USART1 can be remapped ( to PB7/PB6 ) but USART2/USART3 can be not ( due to the fact, that on the small 48pin chip on bluepill the according remap pins are not available).
But I don't know if it can be done by core functions or has to be done by hw registers directly.

Also a nice example by another user present on this thread using the official STM32 core: Stm32 Serial communication issues - #19 by horace

For stm32f103rb,USART2 is contained in st-link connnecter.So l,m finding a way to use USART2 send mesage on the Arduino IDE serial monitor.(I mean without remap IO pins.)

Before, when i use stm32f103c8t6(bilupill),i successfully establish communication between Arduino IDE and bilupill with serial connector(CH340),map USART on PA9,PA10.BUt now i want to try again with an usb line onSTM32F103RB ,there are some bugs above. :face_with_head_bandage:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.