softwareserial for Nucleo boards

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
aafanasj
Posts: 4
Joined: Thu Mar 19, 2020 6:54 pm

softwareserial for Nucleo boards

Post by aafanasj »

Hello guys,

Could you please advise, does SoftwareSerial work on Nucleo boards?

I have tried L452, L152, F207 for several GPIOs and checked with oscilloscope - no data sent;

But simple GPIO sketch works fine for same GPIOs.

Thanks,
Alex.
by ABOSTM » Fri Mar 20, 2020 5:57 pm
OK, I tested my NUCLEO_L152RE and it is true that is doesn't work with official core version V1.8.0.
It is a know issue, similar to https://github.com/stm32duino/Arduino_C ... issues/917
Rework of HardwareTimer library solve this issue but this is not yet officially released.
So either you can take master branch of https://github.com/stm32duino/Arduino_Core_STM32 to get HardwareTimer rework, and it will work.
Or simplier:
you can patch file: ...\1.8.0\libraries\SoftwareSerial\src\SoftwareSerial.cpp,
and add the setmode() function call just after setPrescaleFactor(), like below

Code: Select all

      timer.setPrescaleFactor(pre);
      timer.setMode(2, TIMER_OUTPUT_COMPARE);
Go to full post
ABOSTM
Posts: 60
Joined: Wed Jan 08, 2020 8:40 am
Answers: 7

Re: softwareserial for Nucleo boards

Post by ABOSTM »

Hi Alex,
Yes it should work.
Can you give us more details:
Which core are you using ? which version?
Can you share you sketch?
aafanasj
Posts: 4
Joined: Thu Mar 19, 2020 6:54 pm

Re: softwareserial for Nucleo boards

Post by aafanasj »

Hello ABOSTM,

Thank you for reply.

I use basic example from STM32 core delivery:

=======================================================================
/*
Software serial multple serial test

Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.

The circuit:
* RX is digital pin 10 (connect to TX of other device)
* TX is digital pin 11 (connect to RX of other device)

created back in the mists of time
modified 25 May 2012
by Tom Igoe
based on Mikal Hart's example

This example code is in the public domain.

*/
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}


Serial.println("Goodnight moon!");

// set the data rate for the SoftwareSerial port
mySerial.begin(4800);
mySerial.println("Hello, world?");

Serial.println("Goodnight day!");
}

void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}
=======================================================================

From log:
Using library SoftwareSerial at version 1.0 in folder: C:\Users\....\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.8.0\libraries\SoftwareSerial

The same sketch works fine with UNO board.

Thanks,
Alex.
ABOSTM
Posts: 60
Joined: Wed Jan 08, 2020 8:40 am
Answers: 7

Re: softwareserial for Nucleo boards

Post by ABOSTM »

OK, I tested my NUCLEO_L152RE and it is true that is doesn't work with official core version V1.8.0.
It is a know issue, similar to https://github.com/stm32duino/Arduino_C ... issues/917
Rework of HardwareTimer library solve this issue but this is not yet officially released.
So either you can take master branch of https://github.com/stm32duino/Arduino_Core_STM32 to get HardwareTimer rework, and it will work.
Or simplier:
you can patch file: ...\1.8.0\libraries\SoftwareSerial\src\SoftwareSerial.cpp,
and add the setmode() function call just after setPrescaleFactor(), like below

Code: Select all

      timer.setPrescaleFactor(pre);
      timer.setMode(2, TIMER_OUTPUT_COMPARE);
aafanasj
Posts: 4
Joined: Thu Mar 19, 2020 6:54 pm

Re: softwareserial for Nucleo boards

Post by aafanasj »

Hello ABOSTM,

Thank you for reply.

I will test it today later and provide results.

Thanks,
Alex.
aafanasj
Posts: 4
Joined: Thu Mar 19, 2020 6:54 pm

Re: softwareserial for Nucleo boards

Post by aafanasj »

Hello ABOSTM,

It works.

Thank you for great support.

Regards,
Alex.
Post Reply

Return to “General discussion”