Skip to content

Commit 77e202f

Browse files
committed
STM32 I2C: use higher IRQ priority for slave vs. master
1 parent 9895bcf commit 77e202f

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

targets/TARGET_STM/i2c_api.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,27 @@ void i2c_ev_err_enable(i2c_t *obj, uint32_t handler) {
128128
struct i2c_s *obj_s = I2C_S(obj);
129129
IRQn_Type irq_event_n = obj_s->event_i2cIRQ;
130130
IRQn_Type irq_error_n = obj_s->error_i2cIRQ;
131+
/* default prio in master case is set to 2 */
132+
uint32_t prio = 2;
131133

132-
/* Set up event IT using IRQ and handler tables */
134+
/* Set up ITs using IRQ and handler tables */
133135
NVIC_SetVector(irq_event_n, handler);
134-
HAL_NVIC_SetPriority(irq_event_n, 0, 0);
135-
HAL_NVIC_EnableIRQ(irq_event_n);
136-
/* Set up error IT using IRQ and handler tables */
137136
NVIC_SetVector(irq_error_n, handler);
138-
HAL_NVIC_SetPriority(irq_error_n, 0, 1);
139-
HAL_NVIC_EnableIRQ(irq_error_n);
137+
138+
#if DEVICE_I2CSLAVE
139+
/* Set higher priority to slave device than master.
140+
* In case a device makes use of both master and slave, the
141+
* slave needs higher responsiveness.
142+
*/
143+
if (obj_s->slave) {
144+
prio = 1;
145+
}
146+
#endif
147+
148+
NVIC_SetPriority(irq_event_n, prio);
149+
NVIC_SetPriority(irq_error_n, prio);
150+
NVIC_EnableIRQ(irq_event_n);
151+
NVIC_EnableIRQ(irq_error_n);
140152
}
141153

142154
void i2c_ev_err_disable(i2c_t *obj) {

0 commit comments

Comments
 (0)