STM32 Blue pill and Arduino IDE

2.2k views Asked by At

I want to program Stm32 bluepill with Arduino IDE but when I want to define pins like I write " pinMode(A10, OUTPUT)" it gives error. the error is "'A10' was not declared in this scope" I want to know how should I declare Pins in Arduino IDE for STM32

3

There are 3 answers

0
iheanyi On BEST ANSWER

Based on the error you're reporting, you're not building your code for the correct board. I suspect you're targeting the ArduinoUNO (default) which does not have an A10.

Also, as hcheung's answer mentions, the name on the blue pill is "PA10".

Follow the instructions here to install the board configuration for the STM "blue pill" then select it and build again.

https://maker.pro/arduino/tutorial/how-to-program-the-stm32-blue-pill-with-arduino-ide

Note, the board selection as of today is now "STM32F1 series" instead of "STM32F103C series" as specified at the link.

2
A.R.S.D. On

One reason could be there is not ADC pin of number 10 for the currently selected board (check the board on tool -> boards), there might be fewer number of ADC pins, e.g. try A0.

Or maybe you have selected wrong board. Bluepill isn't included in the Arduino IDE, by default. So you have to add it to your IDE first. There is a nice instruction here on how to do this and a sample code. https://maker.pro/arduino/tutorial/how-to-program-the-stm32-blue-pill-with-arduino-ide

Remember that this newly installed library could have small differences in syntax compared with standard Arduino code, Like this example that is taken from the mentioned site:

void setup() {
  // change pin PC13
  pinMode(PC13, OUTPUT);
}

//infinite loop 
void loop() {
  digitalWrite(PC13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(PC13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

As you can see here the pin is selected using "PC13", and not just a number aka "13".

So in this case by installing the library used in the mentioned site you should write PA0 to PA7 for using ADC. Here is a sample picture displaying the name of the pins and their features: enter image description here

1
hcheung On

For STM32 Blue Pill with Arduino Core, digital pins are named based on its port and pin number, such as PB1, PA10.

There is no A10, I assumed that you mean PA10 (which was marked on the Blue Pill PCB as "A10" (for Port A Pin 10) due to limit space on the PCB.

To use it as a digital pin, simply use PA10 to address it, that is:

pinMode(PA10, OUTPUT);

or because PA10 internally happened to be referred as D10, you can also use:

pinMode(10, OUTPUT); //not recommended

For better understanding of all the pin assignments for STM32F103 Blue Pill, please take a look at the source code here and here.