Skip to content

Commit a1e6f3f

Browse files
committed
Add support of I2C3 on blackpill boards
1 parent 951c1ac commit a1e6f3f

File tree

6 files changed

+54
-8
lines changed

6 files changed

+54
-8
lines changed

STM32F4/cores/maple/libmaple/i2c.c

+31
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,27 @@ i2c_dev i2c_dev2 = {
8080
};
8181
#endif
8282

83+
#if BOARD_NR_I2C>2
84+
/** I2C2 device */
85+
i2c_dev i2c_dev3 = {
86+
.regs = I2C3_BASE,
87+
#ifdef BOARD_I2C3_SDA_PIN
88+
.sda_pin = BOARD_I2C3_SDA_PIN,
89+
#else
90+
.sda_pin = PC9,
91+
#endif
92+
#ifdef BOARD_I2C3_SCL_PIN
93+
.scl_pin = BOARD_I2C3_SCL_PIN,
94+
#else
95+
.scl_pin = PA8,
96+
#endif
97+
.clk_id = RCC_I2C3,
98+
.ev_nvic_line = NVIC_I2C3_EV,
99+
.er_nvic_line = NVIC_I2C3_ER,
100+
.state = I2C_STATE_DISABLED
101+
};
102+
#endif
103+
83104
static inline int32 wait_for_state_change(i2c_dev *dev,
84105
i2c_state state,
85106
uint32 timeout);
@@ -535,6 +556,11 @@ void __irq_i2c2_ev(void) {
535556
i2c_irq_handler(&i2c_dev2);
536557
}
537558
#endif
559+
#if BOARD_NR_I2C>2
560+
void __irq_i2c3_ev(void) {
561+
i2c_irq_handler(&i2c_dev3);
562+
}
563+
#endif
538564
/**
539565
* @brief Interrupt handler for I2C error conditions
540566
* @param dev I2C device
@@ -564,6 +590,11 @@ void __irq_i2c2_er(void) {
564590
i2c_irq_error_handler(&i2c_dev2);
565591
}
566592
#endif
593+
#if BOARD_NR_I2C>2
594+
void __irq_i2c3_er(void) {
595+
i2c_irq_error_handler(&i2c_dev3);
596+
}
597+
#endif
567598
/*
568599
* CCR/TRISE configuration helper
569600
*/

STM32F4/cores/maple/libmaple/i2c.h

+6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ extern i2c_dev i2c_dev1;
100100
extern i2c_dev i2c_dev2;
101101
#define I2C2 (&i2c_dev2)
102102
#endif
103+
#if BOARD_NR_I2C>2
104+
extern i2c_dev i2c_dev3;
105+
#define I2C3 (&i2c_dev3)
106+
#endif
103107

104108
/*
105109
* Register map base pointers
@@ -109,6 +113,8 @@ extern i2c_dev i2c_dev2;
109113
#define I2C1_BASE ((struct i2c_reg_map*)0x40005400)
110114
/** I2C2 register map base pointer */
111115
#define I2C2_BASE ((struct i2c_reg_map*)0x40005800)
116+
/** I2C3 register map base pointer */
117+
#define I2C3_BASE ((struct i2c_reg_map*)0x40005C00)
112118

113119
/*
114120
* Register bit definitions

STM32F4/libraries/Wire/Wire.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ TwoWire::TwoWire(uint8 dev_sel, uint8 flags) {
6767
else if (dev_sel == 2) {
6868
sel_hard = I2C2;
6969
}
70+
#endif
71+
#if BOARD_NR_I2C>2
72+
else if (dev_sel == 3) {
73+
sel_hard = I2C3;
74+
}
7075
#endif
7176
else {
7277
ASSERT(1);

STM32F4/platform.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ tools.stlink_upload.cmd=stlink_upload
121121
tools.stlink_upload.cmd.windows=stlink_upload.bat
122122
tools.stlink_upload.path.windows={runtime.hardware.path}/tools/win
123123
tools.stlink_upload.path.macosx={runtime.hardware.path}/tools/macosx
124-
tools.stlink_upload.path.linux={runtime.hardware.path}/tools/linux64
124+
tools.stlink_upload.path.linux={runtime.hardware.path}/tools/linux
125125
tools.stlink_upload.path.linux64={runtime.hardware.path}/tools/linux64
126126
tools.stlink_upload.upload.params.verbose=-d
127127
tools.stlink_upload.upload.params.quiet=
@@ -132,7 +132,7 @@ tools.hid_upload.cmd=hid_upload
132132
tools.hid_upload.cmd.windows=hid_upload.bat
133133
tools.hid_upload.path.windows={runtime.hardware.path}/tools/win
134134
tools.hid_upload.path.macosx={runtime.hardware.path}/tools/macosx
135-
tools.hid_upload.path.linux={runtime.hardware.path}/tools/linux64
135+
tools.hid_upload.path.linux={runtime.hardware.path}/tools/linux
136136
tools.hid_upload.path.linux64={runtime.hardware.path}/tools/linux64
137137
tools.hid_upload.upload.params.verbose=-d
138138
tools.hid_upload.upload.params.quiet=n

STM32F4/variants/blackpill_f401/blackpill_f401.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@
5252
//#define BOARD_USART6_TX_PIN PA11 // USB_DM
5353
//#define BOARD_USART6_RX_PIN PA12 // USB_DP
5454

55-
#define BOARD_NR_I2C 2
55+
#define BOARD_NR_I2C 3
5656
#define BOARD_I2C1_SCL_PIN PB6
5757
#define BOARD_I2C1_SDA_PIN PB7
5858
#define BOARD_I2C1A_SCL_PIN PB8
5959
#define BOARD_I2C1A_SDA_PIN PB9
60-
#define BOARD_I2C2_SCL_PIN PB10
61-
#define BOARD_I2C2_SDA_PIN PB3
60+
#define BOARD_I2C2_SCL_PIN PB10
61+
#define BOARD_I2C2_SDA_PIN PB3
62+
#define BOARD_I2C3_SCL_PIN PA8
63+
#define BOARD_I2C3_SDA_PIN PB4
6264

6365
#define BOARD_NR_SPI 3
6466
#define BOARD_SPI1_NSS_PIN PA4

STM32F4/variants/blackpill_f411/blackpill_f411.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@
5353
//#define BOARD_USART6_TX_PIN PA11 // USB_DM
5454
//#define BOARD_USART6_RX_PIN PA12 // USB_DP
5555

56-
#define BOARD_NR_I2C 2
56+
#define BOARD_NR_I2C 3
5757
#define BOARD_I2C1_SCL_PIN PB6
5858
#define BOARD_I2C1_SDA_PIN PB7
5959
#define BOARD_I2C1A_SCL_PIN PB8
6060
#define BOARD_I2C1A_SDA_PIN PB9
61-
#define BOARD_I2C2_SCL_PIN PB10
62-
#define BOARD_I2C2_SDA_PIN PB3
61+
#define BOARD_I2C2_SCL_PIN PB10
62+
#define BOARD_I2C2_SDA_PIN PB3
63+
#define BOARD_I2C3_SCL_PIN PA8
64+
#define BOARD_I2C3_SDA_PIN PB4
6365

6466
#define BOARD_NR_SPI 3
6567
#define BOARD_SPI1_NSS_PIN PA4

0 commit comments

Comments
 (0)