Error #define PB2 -Solved!

acronis
Mon Jun 19, 2017 7:49 am
Arduino 1.8.2 + Generic STM32F103V series

Hello. Why error occurs when assigning PIN PB2 ? The rest of the PIN all is well.

#define TEST_BUTTON PB2
void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:
digitalRead(TEST_BUTTON);
}

Error
C:\Users\Admin\Documents\Arduino\sketch_jun19b\sketch_jun19b.ino: In function ‘void loop()’:

sketch_jun19b:1: error: ‘PB2’ was not declared in this scope

#define TEST_BUTTON PB2

C:\Users\Admin\Documents\Arduino\sketch_jun19b\sketch_jun19b.ino:10:13: note: in expansion of macro ‘TEST_BUTTON’

digitalRead(TEST_BUTTON);

exit status 1
‘PB2’ was not declared in this scope

#define TEST_BUTTON PB3
void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:
digitalRead(TEST_BUTTON);
}
No Error

What is the error PB2 ?


stevestrong
Mon Jun 19, 2017 8:32 am
This has maybe to do with the fact that PB2 is BOOT1 pin, so it is normally not used.

You could insert the line:
{&gpiob, NULL, NULL, 2, 0, ADCx}, /* PB2 */


acronis
Mon Jun 19, 2017 8:54 am
{&gpiob, &timer3, &adc1, 0, 3, 8}, /* PB0 */
{&gpiob, &timer3, &adc1, 1, 4, 9}, /* PB1 */
/* NOTE PB2 is not included as its Boot 1 */
{&gpiob, NULL, NULL, 2, 0, ADCx}, /* PB2 */
{&gpiob, NULL, NULL, 3, 0, ADCx}, /* PB3 */ //JTDO, SPI3_SCK / I2S3_CK/
{&gpiob, NULL, NULL, 4, 0, ADCx}, /* PB4 */ //NJTRST, SPI3_MISO

Did.
But the error remained.
What could be the problem ?


stevestrong
Mon Jun 19, 2017 9:03 am
You should also insert PB2 after PB1 into:
https://github.com/rogerclarkmelbourne/ … ard.h#L117

acronis
Mon Jun 19, 2017 9:07 am
Did.
Error

c:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32\STM32F1\variants\generic_stm32f103v\board.cpp:169:1: error: too many initializers for ‘const stm32_pin_info [79]’

};

^


stevestrong
Mon Jun 19, 2017 9:08 am
Change the value to 80 in:
https://github.com/rogerclarkmelbourne/ … oard.h#L94

acronis
Mon Jun 19, 2017 9:09 am
Fixed in [80].
It worked.
Thank you very much for the help !

stevestrong
Mon Jun 19, 2017 9:10 am
Welcome.
Please set the title to [SOLVED] if it works.

RogerClark
Mon Jun 19, 2017 10:38 am
[stevestrong – Mon Jun 19, 2017 9:10 am] –
Welcome.
Please set the title to [SOLVED] if it works.

Sounds like this a bug

Is the number in the header incorrect ?


stevestrong
Mon Jun 19, 2017 11:45 am
[RogerClark – Mon Jun 19, 2017 10:38 am] –
Is the number in the header incorrect ?

Not quite, just that it has to be updated if you insert a new pin (PB2 in this case).
Although I don’t see any benefit to define that number ahead of the pin map.


RogerClark
Mon Jun 19, 2017 9:39 pm
Ok.

So the potential issue is that pin PB1 is not in the pinmap

I think the Maple mini also uses this for its button. But there is IMHO a bug in the MM hardware, as there should be a weak pulldown on the button, to prevent the built in Serial bootloader reading Boot1 as High , ( because it is floating)

I did consider using the boot1 link on the bootloader as a button, but most people think its a bad or unnecessary idea.
( Personally I think its a useful addition to the bootloader, because on OSX and Linux, I think its difficult to upload by just pressing the reset button prior to upload, because the linux dfu-util does not seem to wait for the DFU device , like the windows version does.


Leave a Reply

Your email address will not be published. Required fields are marked *