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.
Mapping of peripherals by compiler
Re: Mapping of peripherals by compiler
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
https://github.com/stm32duino/Arduino_C ... #L212-L218
Else this is define by the variant:
https://github.com/stm32duino/Arduino_C ... #L136-L137
Re: Mapping of peripherals by compiler
fpiSTM, perfect! That is just what I was looking for, thanks.
Mapping of peripherals by compiler - further questions
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?
// 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?
Re: Mapping of peripherals by compiler
You can use setSDA/SCL:
https://github.com/stm32duino/wiki/wiki ... tance-pins
To redefine a definition, you can use:
https://github.com/stm32duino/wiki/wiki ... uild_opt.h
Or
https://github.com/stm32duino/wiki/wiki ... definition
https://github.com/stm32duino/wiki/wiki ... tance-pins
To redefine a definition, you can use:
https://github.com/stm32duino/wiki/wiki ... uild_opt.h
Or
https://github.com/stm32duino/wiki/wiki ... definition
Re: Mapping of peripherals by compiler
fpiSTM, thank you; that seems so simple. I feel foolish for not having already found the API documentation in the wiki.