Go Down

Topic: STM32F103 pin mapping (Read 5836 times) previous topic - next topic

C_Raynor

Let me start by saying it could be my lack of search abilities.

I could find no mapping of pins anywhere I looked between what the Arduino IDE would accept and the pin [name/number] on the "blue pill".

If this is helpful for others, it was worth the time I took this morning to do this.

I modified the blink sketch a small amount to set a pattern of flashes so there would be no mistake on what I was seeing.


Code: [Select]
/*
  Modified Blink for "Blue Pill" STM32F103C8T6

  Turns an LED on in a set pattern, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman
  modified 29 Sep 2019
  by Charlie Raynor

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Blink
*/
/*
  Sketch is modified "blink" in the examples folder of the IDE.
  All pins responded to digitalWrite, Look at the datasheet for which pins are ADC and
  DAC,and how to set them up for that.

  I changed the led pin number starting with 2, progressing all the way to 31,the total
  number of accessible GPIO pins on the blue pill. As with all MCU chips, most have special
  purposes, outlined in the datasheet.
 */
int ledPin = 31;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode (ledPin, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(150);                   // wait for a second
  digitalWrite(ledPin, LOW);    // turn the LED off by making the voltage LOW
  delay(100);                   // wait for a second
  digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(300);                   // wait for a second
  digitalWrite(ledPin, LOW);    // turn the LED off by making the voltage LOW
  delay(100);                   // wait for a second
  digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(150);                   // wait for a second
  digitalWrite(ledPin, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                  // wait for a second


 
}


The pin mapping that I came up with:

Code: [Select]
Arduino pin  2 = B7
Arduino pin  3 = B6
Arduino pin  4 = B5
Arduino pin  5 = B4
Arduino pin  6 = B3
Arduino pin  7 = A15
Arduino pin  8 = A12
Arduino pin  9 = A11
Arduino pin 10 = A10
Arduino pin 11 = A9
Arduino pin 12 = A8
Arduino pin 13 = B15
Arduino pin 14 = B14
Arduino pin 15 = B13
Arduino pin 16 = null
Arduino pin 17 = C13, onboard led, input only.
Arduino pin 18 = C14
Arduino pin 19 = C15
Arduino pin 20 = A0
Arduino pin 21 = A1
Arduino pin 22 = A2
Arduino pin 23 = A3
Arduino pin 24 = A4
Arduino pin 25 = A5
Arduino pin 26 = A6
Arduino pin 27 = A7
Arduino pin 28 = B0
Arduino pin 29 = B1
Arduino pin 30 = B10
Arduino pin 31 = B11


Note that according to the datasheet, pin C13 (PC13) is the tamper-RTC pin and as such is low current input. The pattern set by the sketch is reversed. See notes 5 and 6 in the Pinouts and pin description of the datasheet.

Also note that Arduino pin 17 returned NO pin associated with it on the blue pill, and blue pill pin B12 is absent from the listing.

septillion

I used to have an older version of what was STM32duino and it came with a little bit more examples which did show it directly. So I fully think the project is to blame. But what I do know is that you could have saved yourself some time ::) That;s because if you want to use the pin labeled A15 you just type PA15.

Code: [Select]
const byte LedPin = PA15;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LedPin, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LedPin, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LedPin, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}


Nice and easy to remember ;)
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

C_Raynor

Quote
That;s because if you want to use the pin labeled A15 you just type PA15.
I've tried that, many times. ALWAYS returned an error no matter how I declared the pin. I.E. "int [pin name] = [pin number] etc.

Error was not consistent, either. Verify sketch with no changes, different error.

Obviously, others don't seem to be having this problem. May I ask what STM32 lib others are using? That may be MY problem. Yes, I have the arduino SAM and SAMD boards in stalled in the manager, as well as several of the available STM32 flavors. I've read on these forums that some of the libs from these are needed, but not included in the generic boards coding.

Still, the problem remains.

I guess I'm still not in "the club".

septillion

I first tried the old stm32duino 2017.9.22. And later upgraded to the new STM32 cores 1.7.0 (which is now from ST/STMicroelectonics itself) which did require me to manually remove the old one to not give errors.

So what do you have installed?

And I think the new STM32 core doesn't require anything else anymore now it's fully build around the STM HAL.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

C_Raynor

So what do you have installed?


Arduino SAM boards, SAMD boards (I am planning to use these in the future), STM32F1xx/GD32F1xx, STM32 cores.

On the current "Blink" sketch, there is a glaring omission, that will ALWAYS return an error 'LED_BUILTIN' was not declared in this scope. It doesn't matter what board I have selected, THAT error is consistent. Good that the last writer gave a hint in his comment above the code, but neglected to say how to fix.

Code: [Select]
/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}



Like many others that have barely scratched the surface, this sketch is my "go-to" for checking the glones for working.

C_Raynor

Tried again with what you said, declaring the pin to be used as an int, as a const byte, as a #declare.

When I use the board pin name/number, ERROR. If I use the arduino pin number, it compiles. BTW, 1.8.10.

Never the same error twice in a row. However, all errors ARE related to pin numbering.


Any explanation why my copy of the IDE is being consistent in this manner?

septillion

And which version of "STM32 cores"?

And is "STM32F1xx/GD32F1xx" a separate core? If so, that may have a clash with the "STM32 cores"

And not saying (or actually thinking) it's a problem here, but 1.8.10 seems to be a flawed Arduino version again... Happens pretty often with Arduino so I tend to stick to a version a lit longer before I switch to a newer. Use 1.8.5 atm.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

MrMark

#7
Sep 30, 2019, 02:17 pm Last Edit: Sep 30, 2019, 02:20 pm by MrMark
For the ST Microelectornics core, pin names using the Port/Pin convention are defined here:
https://github.com/stm32duino/Arduino_Core_STM32/blob/master/cores/arduino/stm32/PinNames.h

Without delving into source code, documentation is a bit thin for this stuff.

nrrdzilla

Hi all.

Sorry I missed chiming in on this thread when it first happened... as it turns out I'd been dealing with the same issue mere weeks earlier, and just now found this thread by chance.

Is this file what you are looking for:
<HOME>/.platformio/packages/framework-arduinoststm32/variants/PILL_F103XX/variant.h
?

PS we started using Platformio at work, instead of the vanilla Arduino IDE, but I think the above should still be valid.

Cheers,
N

Go Up