This driver requires the STM32 device specific HAL and STM32CubeMX (CubeMX) initialization code generator. The driver instance is mapped to hardware as shown in the table below:
CMSIS Driver Instance | STM32 Hardware Resource |
---|---|
Driver_I2C1 | I2C1 |
Driver_I2C2 | I2C2 |
Driver_I2C3 | I2C3 |
Driver_I2C4 | I2C4 |
Driver_I2C5 | I2C5 |
Driver_I2C6 | I2C6 |
Driver_I2C7 | I2C7 |
Driver_I2C8 | I2C8 |
This driver has the following deviations from the CMSIS-Driver specification:
Conceptual deviations:
main.c
.Functional deviations:
This driver requires the following configuration in CubeMX:
Notes
- configuration information in the MX_Device.h file is based on CubeMX configuration.
- DMA configuration can differ between devices series so configure DMA as required by the used device.
- for DMA usage on devices with cache, ensure that data buffers for Transmit and Receive functions are in non-cacheable memory, or ensure that memory for transmit is updated (cache clean) before Transmit function is called and that memory containing received data is updated after the reception finishes (cache invalidate).
- some DMA controllers can only access specific memories, so ensure that proper memory is used for the buffers according to the DMA requirement.
Pin | Functionality |
---|---|
PB6 | I2C1_SCL |
PB7 | I2C1_SDA |
Under Categories: Connectivity select I2C1:
Mode:
Configuration:
Pin Name | Signal on Pin | Pin Context.. | GPIO output.. | GPIO mode | GPIO Pull-up/Pull.. | Maximum out.. | Fast Mode | User Label |
---|---|---|---|---|---|---|---|---|
PB6 | I2C1_SCL | n/a | n/a | Alternate Function Push Pull | Pull-up | Low | n/a | . |
PB7 | I2C1_SDA | n/a | n/a | Alternate Function Push Pull | Pull-up | Low | n/a | . |
Under Categories: System Core select DMA (might be different on other device series, or for some peripherals might be BDMA):
Configuration:
DMA1, DMA2:
Click on Add button and add DMA Requests as in table below:
DMA Request | Stream | Direction | Priority |
---|---|---|---|
I2C1_RX | DMA1 Stream 0 | Peripheral to Memory | Low |
I2C1_TX | DMA1 Stream 1 | Memory to Peripheral | Low |
Under Categories: System Core select NVIC:
Configuration:
NVIC Interrupt Table | Enabled | Preemption Priority | Sub Priority |
---|---|---|---|
DMA1 stream0 global interrupt | checked | 0 | 0 |
DMA1 stream1 global interrupt | checked | 0 | 0 |
I2C1 event interrupt | checked | 0 | 0 |
I2C1 error interrupt | checked | 0 | 0 |
Enabled interrupt table | Select for.. | Generate Enable in.. | Generate IRQ h.. | Call HAL handler |
---|---|---|---|---|
DMA1 stream0 global interrupt | unchecked | checked | checked | checked |
DMA1 stream1 global interrupt | unchecked | checked | checked | checked |
I2C1 event interrupt | unchecked | checked | checked | checked |
I2C1 error interrupt | unchecked | checked | checked | checked |
Under Advanced Settings:
Generated Function Calls:
Generate Code | Function Name | Peripheral Inst.. | Do not generate .. | Visibility (Static) |
---|---|---|---|---|
checked | MX_I2C1_Init | I2C1 | unchecked | checked |