stm32f405rgt6 'pin_B6' undeclared

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
tecdroid
Posts: 27
Joined: Thu Apr 08, 2021 6:22 am

stm32f405rgt6 'pin_B6' undeclared

Post by tecdroid » Tue Nov 30, 2021 5:09 pm

Hi,

i built a little board with an stm32f405rgt6 and tried to strip down mpconfigboard.h to fit it on my hardware but when I compile I get that result.

Code: Select all

...
CC timer.c
CC led.c
CC pin.c
CC pin_defs_stm32.c
CC pin_named_pins.c
CC bufhelper.c
CC dma.c
CC i2c.c
CC pyb_i2c.c
In file included from ./mpconfigport.h:31,
                 from ../../py/mpconfig.h:62,
                 from ../../py/mpstate.h:31,
                 from ../../py/runtime.h:29,
                 from pyb_i2c.c:30:
pyb_i2c.c: In function 'pyb_i2c_init':
boards/BRB01/mpconfigboard.h:47:30: error: 'pin_B6' undeclared (first use in this function); did you mean 'pin_C6'?
 #define MICROPY_HW_I2C1_SCL (pin_B6)
                              ^~~~~~
pyb_i2c.c:267:19: note: in expansion of macro 'MICROPY_HW_I2C1_SCL'
         scl_pin = MICROPY_HW_I2C1_SCL;
                   ^~~~~~~~~~~~~~~~~~~
boards/BRB01/mpconfigboard.h:47:30: note: each undeclared identifier is reported only once for each function it appears in
 #define MICROPY_HW_I2C1_SCL (pin_B6)
                              ^~~~~~
pyb_i2c.c:267:19: note: in expansion of macro 'MICROPY_HW_I2C1_SCL'
         scl_pin = MICROPY_HW_I2C1_SCL;
                   ^~~~~~~~~~~~~~~~~~~
boards/BRB01/mpconfigboard.h:48:30: error: 'pin_B7' undeclared (first use in this function); did you mean 'pin_C7'?
 #define MICROPY_HW_I2C1_SDA (pin_B7)
                              ^~~~~~
pyb_i2c.c:268:19: note: in expansion of macro 'MICROPY_HW_I2C1_SDA'
         sda_pin = MICROPY_HW_I2C1_SDA;
                   ^~~~~~~~~~~~~~~~~~~
boards/BRB01/mpconfigboard.h:50:30: error: 'pin_B10' undeclared (first use in this function); did you mean 'pin_A10'?
 #define MICROPY_HW_I2C2_SCL (pin_B10)
                              ^~~~~~~
pyb_i2c.c:274:19: note: in expansion of macro 'MICROPY_HW_I2C2_SCL'
         scl_pin = MICROPY_HW_I2C2_SCL;
                   ^~~~~~~~~~~~~~~~~~~
boards/BRB01/mpconfigboard.h:51:30: error: 'pin_B11' undeclared (first use in this function); did you mean 'pin_A11'?
 #define MICROPY_HW_I2C2_SDA (pin_B11)
                              ^~~~~~~
pyb_i2c.c:275:19: note: in expansion of macro 'MICROPY_HW_I2C2_SDA'
         sda_pin = MICROPY_HW_I2C2_SDA;
                   ^~~~~~~~~~~~~~~~~~~
make: *** [../../py/mkrules.mk:77: build-BRB01/pyb_i2c.o] Fehler 1
So, it seems that i might have thrown i2c out but i don't know why.
BTW: Where are all those options described?

My mpconfigboard looks that way:

Code: Select all

#define MICROPY_HW_BOARD_NAME       "BRBv1.1"
#define MICROPY_HW_MCU_NAME         "STM32F405RG"

#define MICROPY_PY_FRAMEBUF	    (0)
//#define MICROPY_HW_HAS_SWITCH       (1)
#define MICROPY_HW_HAS_FLASH        (1)
#define MICROPY_HW_ENABLE_RNG       (1)
#define MICROPY_HW_ENABLE_RTC       (1)
#define MICROPY_HW_ENABLE_SERVO     (1)
#define MICROPY_HW_ENABLE_DAC       (1)
#define MICROPY_HW_ENABLE_USB       (1)

// HSE is 12MHz
#define MICROPY_HW_CLK_PLLM (12)
#define MICROPY_HW_CLK_PLLN (336)
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
#define MICROPY_HW_CLK_PLLQ (7)
#define MICROPY_HW_CLK_LAST_FREQ (1)

// The pyboard has a 32kHz crystal for the RTC
#define MICROPY_HW_RTC_USE_LSE      (1)
#define MICROPY_HW_RTC_USE_US       (0)
#define MICROPY_HW_RTC_USE_CALOUT   (1)

// UART config
#define MICROPY_HW_UART1_NAME   "XB"
#define MICROPY_HW_UART1_TX     (pin_B6)
#define MICROPY_HW_UART1_RX     (pin_B7)
#define MICROPY_HW_UART2_TX     (pin_A2)
#define MICROPY_HW_UART2_RX     (pin_A3)
#define MICROPY_HW_UART2_RTS    (pin_A1)
#define MICROPY_HW_UART2_CTS    (pin_A0)
#define MICROPY_HW_UART3_NAME   "YB"
#define MICROPY_HW_UART3_TX     (pin_B10)
#define MICROPY_HW_UART3_RX     (pin_B11)
#define MICROPY_HW_UART3_RTS    (pin_B14)
#define MICROPY_HW_UART3_CTS    (pin_B13)
#define MICROPY_HW_UART4_NAME   "XA"
#define MICROPY_HW_UART4_TX     (pin_A0)
#define MICROPY_HW_UART4_RX     (pin_A1)
#define MICROPY_HW_UART6_NAME   "YA"
#define MICROPY_HW_UART6_TX     (pin_C6)
#define MICROPY_HW_UART6_RX     (pin_C7)

// I2C buses
#define MICROPY_HW_I2C1_NAME "X"
#define MICROPY_HW_I2C1_SCL (pin_B6)
#define MICROPY_HW_I2C1_SDA (pin_B7)
#define MICROPY_HW_I2C2_NAME "Y"
#define MICROPY_HW_I2C2_SCL (pin_B10)
#define MICROPY_HW_I2C2_SDA (pin_B11)

// SPI buses
#define MICROPY_HW_SPI1_NAME "X"
#define MICROPY_HW_SPI1_NSS  (pin_A4) // X5
#define MICROPY_HW_SPI1_SCK  (pin_A5) // X6
#define MICROPY_HW_SPI1_MISO (pin_A6) // X7
#define MICROPY_HW_SPI1_MOSI (pin_A7) // X8
#define MICROPY_HW_SPI2_NAME "Y"
#define MICROPY_HW_SPI2_NSS  (pin_B12) // Y5
#define MICROPY_HW_SPI2_SCK  (pin_B13) // Y6
#define MICROPY_HW_SPI2_MISO (pin_B14) // Y7
#define MICROPY_HW_SPI2_MOSI (pin_B15) // Y8

// CAN buses
#define MICROPY_HW_CAN1_NAME "YA"
#define MICROPY_HW_CAN1_TX   (pin_B9) // Y4
#define MICROPY_HW_CAN1_RX   (pin_B8) // Y3
#define MICROPY_HW_CAN2_NAME "YB"
#define MICROPY_HW_CAN2_TX   (pin_B13) // Y6
#define MICROPY_HW_CAN2_RX   (pin_B12) // Y5

// USB config
#define MICROPY_HW_USB_FS              (1)
#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9)
#define MICROPY_HW_USB_OTG_ID_PIN      (pin_A10)

I also built my own pins because I don't use all of them:

Code: Select all

X13,Reset
X14,GND
X15,3.3V
X16,VIN
X23,A3.3V
X24,AGND
Y13,Reset
Y14,GND
Y15,3.3V
Y16,VIN
USB_VBUS,PA9
USB_ID,PA10
USB_DM,PA11
USB_DP,PA12
IO0,PC13
IO1,PC14
IO2,PC5
IO3,PC0
IO4,PC1
IO5,PC2
IO6,PC3
IO7,PB12
IO8,PB13
IO9,PB14
IO10,PB15
IO11,PC6
IO12,PC7
IO13,PC8
IO14,PC9
IO15,PA10
IO16,PA11

tecdroid
Posts: 27
Joined: Thu Apr 08, 2021 6:22 am

Re: stm32f405rgt6 'pin_B6' undeclared

Post by tecdroid » Tue Nov 30, 2021 7:40 pm

Okay, seems that pins which aren't used in pins.csv won't be created in pins.h. After I put declarations for all pins into pins.csv, I could compile..

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: stm32f405rgt6 'pin_B6' undeclared

Post by dhylands » Tue Nov 30, 2021 10:31 pm

Yeah - the intersections of the pins described in pins.csv and the possible pins from stm32f405_af.csv is what will wind up being declared in pins.h

SO what this essentially means, is that any pin that you use on your board (even if it isn't exposed to the end-user) should be declared in pins.csv

This way the generated pins file (which does take up space in flash) will only be as big as it needs to be for your particular board, rather then the most generic stm32f405 board.

tecdroid
Posts: 27
Joined: Thu Apr 08, 2021 6:22 am

Re: stm32f405rgt6 'pin_B6' undeclared

Post by tecdroid » Wed Dec 01, 2021 2:42 pm

biggest problem is that i don't know what the defines all mean.. just guessing it.. and some seem to activate parts i don't need or want..

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: stm32f405rgt6 'pin_B6' undeclared

Post by dhylands » Wed Dec 01, 2021 7:45 pm

All of the defines in mpconfigboard.h that assign pins need to map to valid pins.

If you aren't going to use I2C at all then you can put:

#define MICROPY_HW_ENABLE_I2C (0)

and then you can remove all of the #define MICROPY_HW_I2Cx_xxx macros.

If you were using UARTS, but not using UART3, then you should remove the #define MICROPY_HW_UART3_xxx macros.

You can also disable functionality from the HAL. stm32/boards/stm32f4xx_hal_conf_base.h turns on most of the HAL modules.

In your stm32f4xx_hal_conf.h file, after the

Code: Select all

#include "boards/stm32f4xx_hal_conf_base.h"
you could put

Code: Select all

#undef HAL_I2C_MODULE_ENABLED
in order to turn off I2C in the hal. This would also require to turn off I2C at the micropython level. The end result will be smaller firmware.

Post Reply