Mapping of peripherals by compiler

Post here first, or if you can't find a relevant section!
Post Reply
hdleng
Posts: 7
Joined: Fri Jan 15, 2021 11:44 pm
Location: Tucson, AZ, USA

Mapping of peripherals by compiler

Post by hdleng »

I am looking for a convenient (lazy) way to determine how the Arduino IDE maps STM32 peripherals when it compiles a program. I am aware of the PeripheralPins.c file that is used to map generic functions (I2C communications e.g.) to specific pins for a selected board. And, working backwards through such files, I can find where to check for various physical interfaces. I'm hoping that there is a simpler way to accomplish this. Is there a way to create a compiler listing that gives that information?

For example, I bought an Adafruit si5351 shield, compiled the example file, uploaded to an Arduino Uno, connected the shield, and everything worked. I then created a new sketch using the same example file, and I selected the STM32F407G-DISC1 board. The sketch compiles, loads, and runs (at least I see the serial messages). The PeripheralPins.c file maps SDA to PB7, PB11, or PC9 and SCL to PA8 or PB8. I assume the compiler chooses the first pin that has not already been assigned to another alternate function. I can probe those pins to determine what the compiler chose. But, as I said, I looking for a lazy to accomplish that.
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Mapping of peripherals by compiler

Post by fpiSTM »

By default, pins to use for, Serial, wire an spi default instance are defined to be on the same pins than the arduino connector if it is available on the board:
https://github.com/stm32duino/Arduino_C ... #L212-L218

Else this is define by the variant:
https://github.com/stm32duino/Arduino_C ... #L136-L137
hdleng
Posts: 7
Joined: Fri Jan 15, 2021 11:44 pm
Location: Tucson, AZ, USA

Re: Mapping of peripherals by compiler

Post by hdleng »

fpiSTM, perfect! That is just what I was looking for, thanks.
hdleng
Posts: 7
Joined: Fri Jan 15, 2021 11:44 pm
Location: Tucson, AZ, USA

Mapping of peripherals by compiler - further questions

Post by hdleng »

I need to map peripheral I/O to pins other than those in variant.h. Specifically, I am using a Discovery F407 board, and i need to map SDA and SCL to PB9 and PB6 to interface with existing hardware. Variant.h has these at:

// I2C Definitions
#define PIN_WIRE_SDA PB7
#define PIN_WIRE_SCL PB8

I inserted this into my sketch immediate ahead of the setup() function:

#ifdef PIN_WIRE_SDA
#undef PIN_WIRE_SDA
#define PIN_WIRE_SDA PB9
#endif

#ifdef PIN_WIRE_SCL
#undef PIN_WIRE_SCL
#define PIN_WIRE_SCL PB6
#endif

The result is that the compiled program still uses the mapping in variant.h.

Obviously, there is something wrong with my approach. Can anyone give me a hand?
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Mapping of peripherals by compiler

Post by fpiSTM »

hdleng
Posts: 7
Joined: Fri Jan 15, 2021 11:44 pm
Location: Tucson, AZ, USA

Re: Mapping of peripherals by compiler

Post by hdleng »

fpiSTM, thank you; that seems so simple. I feel foolish for not having already found the API documentation in the wiki.
Post Reply

Return to “General discussion”