stm32-rs / stm32l0xx-hal

A hardware abstraction layer (HAL) for the STM32L0 series microcontrollers written in Rust
BSD Zero Clause License
96 stars 60 forks source link

Update I2C pin mappings based on STM32L0xx GPIO IP #87

Closed dbrgn closed 4 years ago

dbrgn commented 4 years ago

The GPIO internal peripheral (IP) does not match the stm32l0x/stm32l0x2/stm32l0x3 grouping used in the PACs. Instead, there are 4 different GPIO IPs in the STM32L0 family that define how the pin functions are mapped to the actual pins. This means that the current I2C mappings are broken for a lot of MCUs. For reference, these issues have already been opened because the mappings were broken:

We can use the io-* Cargo features to differentiate between these mappings. This requires that the proper io-* feature is set when compiling (and is thus a breaking change). The easiest way to apply the feature without looking at the STM32CubeMX database XML files is to simply use the proper mcu-* feature, for example mcu-STM32L071KBTx.

The pin mappings used in this changeset were taken out of the cube-parse output for the STM32L0 family. The output can be found here. To re-generate:

cargo run -- pin_mappings STM32L0 -d /path/to/stm32cubemx/db/mcu/

The source files in the STM32CubeMx database used to generate the mappings:

More information on the database format can be found in the cube-parse README.

The long-term solution should probably be a universal pin mapping file generated by cube-parse, but with the current APIs this would be a major refactoring. Therefore a manual fix must suffice for now.

Fixes #76, fixes #77, fixes #85.

CC @rnestler @DanSGiesbrecht @ijager

dbrgn commented 4 years ago

I have verified this PR against an STM32L071KBTx MCU and at least I2C1 seems to work properly.

arkorobotics commented 4 years ago

@dbrgn Looks like #68 has a few merge conflicts with this PR

dbrgn commented 4 years ago

@dbrgn Looks like #68 has a few merge conflicts with this PR

Yup, I just rebased the branch. Let's hope I resolved the conflicts correctly & the tests pass again :slightly_smiling_face:

arkorobotics commented 4 years ago

Looks good! Thanks!