Trying to port Arduino programs to STM32 boards.

Post Reply
Fabaum
Posts: 24
Joined: Tue Mar 17, 2020 4:10 pm

Trying to port Arduino programs to STM32 boards.

Post by Fabaum »

Hello friends,

I am doing experiments to check the differences between an Arduino standard board and a STM32 standard board using the ArduinoIDE.
In a first test, I verified and uploaded the sample program "Blink" to the STM32L476RG board:

void setup () {
pinMode (LED_BUILTIN, OUTPUT);
}
void loop () {
digitalWrite (LED_BUILTIN, HIGH);
delay (1000);
digitalWrite (LED_BUILTIN, LOW);
delay (1000);
}

The program worked correctly.
After that, I changed the variable LED_BUILTIN to pin PA-5, which corresponds to LED1 embedded in the board:

void setup () {
pinMode (PA_5, OUTPUT);
}
void loop () {
digitalWrite (PA_5, HIGH);
delay (500);
digitalWrite (PA_5, LOW);
delay (500);
}

This time, the program did not work.
I'm trying to get some flexibility when porting programs going beyond sample programs, but it seems that things are not so simple ...
Attachments
Pinagem-small.jpg
Pinagem-small.jpg (95.49 KiB) Viewed 8478 times
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: Trying to port Arduino programs to STM32 boards.

Post by BennehBoy »

Remove the underscores from the pin names.
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: Trying to port Arduino programs to STM32 boards.

Post by fredbox »

If you want to use the PinName (PA_5) you will need to convert to a DigitalPin.

Code: Select all

pinMode(pinNametoDigitalPin(PA_5), OUTPUT);
Then you can use the digitalWriteFast function that takes a PinName as a parameter:

Code: Select all

digitalWriteFast(PA_5, HIGH);
delay(500);
digitalWriteFast(PA_5, LOW);
delay(500);
or simpler:

Code: Select all

digitalToggleFast(PA_5);
delay(500);
Fabaum
Posts: 24
Joined: Tue Mar 17, 2020 4:10 pm

Re: Trying to port Arduino programs to STM32 boards.

Post by Fabaum »

The both ways worked fine, thank you very much, friends!
stas2z
Posts: 131
Joined: Mon Feb 24, 2020 8:17 pm
Answers: 8

Re: Trying to port Arduino programs to STM32 boards.

Post by stas2z »

Why just not use PA5?
Fabaum
Posts: 24
Joined: Tue Mar 17, 2020 4:10 pm

Re: Trying to port Arduino programs to STM32 boards.

Post by Fabaum »

Yes, the simplest way is the one you mentioned. However, it is interesting to see that there is more than one way to do the same thing, following the syntax that appears in "pins_arduino.h".
stas2z
Posts: 131
Joined: Mon Feb 24, 2020 8:17 pm
Answers: 8

Re: Trying to port Arduino programs to STM32 boards.

Post by stas2z »

Right "arduino" syntax is PA5
PA_5 naming used internally and not for "public"
Fabaum
Posts: 24
Joined: Tue Mar 17, 2020 4:10 pm

Re: Trying to port Arduino programs to STM32 boards.

Post by Fabaum »

Perfect, stas2z!
With the help of friends, I will gradually understand these particularities.
Thanks!
Post Reply

Return to “STM32L4 based boards”