Page 1 of 1

Trying to port Arduino programs to STM32 boards.

Posted: Sat Mar 21, 2020 4:56 pm
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 ...

Re: Trying to port Arduino programs to STM32 boards.

Posted: Sat Mar 21, 2020 4:58 pm
by BennehBoy
Remove the underscores from the pin names.

Re: Trying to port Arduino programs to STM32 boards.

Posted: Sat Mar 21, 2020 5:42 pm
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);

Re: Trying to port Arduino programs to STM32 boards.

Posted: Sat Mar 21, 2020 7:21 pm
by Fabaum
The both ways worked fine, thank you very much, friends!

Re: Trying to port Arduino programs to STM32 boards.

Posted: Sat Mar 21, 2020 7:41 pm
by stas2z
Why just not use PA5?

Re: Trying to port Arduino programs to STM32 boards.

Posted: Mon Mar 23, 2020 1:17 pm
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".

Re: Trying to port Arduino programs to STM32 boards.

Posted: Mon Mar 23, 2020 3:28 pm
by stas2z
Right "arduino" syntax is PA5
PA_5 naming used internally and not for "public"

Re: Trying to port Arduino programs to STM32 boards.

Posted: Mon Mar 23, 2020 4:04 pm
by Fabaum
Perfect, stas2z!
With the help of friends, I will gradually understand these particularities.
Thanks!