@@ -54,7 +54,6 @@ static uart_irq_handler irq_handler;
54
54
static void uart_irq (int id )
55
55
{
56
56
UART_HandleTypeDef * huart = & uart_handlers [id ];
57
-
58
57
if (serial_irq_ids [id ] != 0 ) {
59
58
if (__HAL_UART_GET_FLAG (huart , UART_FLAG_TXE ) != RESET ) {
60
59
if (__HAL_UART_GET_IT (huart , UART_IT_TXE ) != RESET ) {
@@ -64,7 +63,7 @@ static void uart_irq(int id)
64
63
if (__HAL_UART_GET_FLAG (huart , UART_FLAG_RXNE ) != RESET ) {
65
64
if (__HAL_UART_GET_IT (huart , UART_IT_RXNE ) != RESET ) {
66
65
irq_handler (serial_irq_ids [id ], RxIrq );
67
- /* Flag has been cleared when reading the content */
66
+ /* Flag has been cleared when reading the content */
68
67
}
69
68
}
70
69
if (__HAL_UART_GET_FLAG (huart , UART_FLAG_ORE ) != RESET ) {
@@ -87,47 +86,53 @@ static void uart2_irq(void)
87
86
}
88
87
#endif
89
88
90
- #if defined USART3_BASE
91
- static void uart3_irq (void )
89
+ // Used for both USART3_4_IRQn and USART3_8_IRQn
90
+ static void uart3_8_irq (void )
92
91
{
93
- uart_irq (2 );
94
- }
92
+ #if defined(TARGET_STM32F091RC )
93
+ #if defined(USART3_BASE )
94
+ if (__HAL_GET_PENDING_IT (HAL_ITLINE_USART3 ) != RESET ) {
95
+ uart_irq (2 );
96
+ }
95
97
#endif
96
-
97
- #if defined USART4_BASE
98
- static void uart4_irq (void )
99
- {
100
- uart_irq (3 );
101
- }
98
+ #if defined(USART4_BASE )
99
+ if (__HAL_GET_PENDING_IT (HAL_ITLINE_USART4 ) != RESET ) {
100
+ uart_irq (3 );
101
+ }
102
102
#endif
103
-
104
- #if defined USART5_BASE
105
- static void uart5_irq (void )
106
- {
107
- uart_irq (4 );
108
- }
103
+ #if defined(USART5_BASE )
104
+ if (__HAL_GET_PENDING_IT (HAL_ITLINE_USART5 ) != RESET ) {
105
+ uart_irq (4 );
106
+ }
109
107
#endif
110
-
111
- #if defined USART6_BASE
112
- static void uart6_irq (void )
113
- {
114
- uart_irq (5 );
115
- }
108
+ #if defined(USART6_BASE )
109
+ if (__HAL_GET_PENDING_IT (HAL_ITLINE_USART6 ) != RESET ) {
110
+ uart_irq (5 );
111
+ }
116
112
#endif
117
-
118
- #if defined USART7_BASE
119
- static void uart7_irq (void )
120
- {
121
- uart_irq (6 );
122
- }
113
+ #if defined(USART7_BASE )
114
+ if (__HAL_GET_PENDING_IT (HAL_ITLINE_USART7 ) != RESET ) {
115
+ uart_irq (6 );
116
+ }
123
117
#endif
124
-
125
- #if defined USART8_BASE
126
- static void uart8_irq (void )
127
- {
128
- uart_irq (7 );
129
- }
118
+ #if defined(USART8_BASE )
119
+ if (__HAL_GET_PENDING_IT (HAL_ITLINE_USART8 ) != RESET ) {
120
+ uart_irq (7 );
121
+ }
122
+ #endif
123
+ #else // TARGET_STM32F070RB, TARGET_STM32F072RB
124
+ #if defined(USART3_BASE )
125
+ if (USART3 -> ISR & (UART_FLAG_TXE | UART_FLAG_RXNE | UART_FLAG_ORE )) {
126
+ uart_irq (2 );
127
+ }
130
128
#endif
129
+ #if defined(USART4_BASE )
130
+ if (USART4 -> ISR & (UART_FLAG_TXE | UART_FLAG_RXNE | UART_FLAG_ORE )) {
131
+ uart_irq (3 );
132
+ }
133
+ #endif
134
+ #endif
135
+ }
131
136
132
137
void serial_irq_handler (serial_t * obj , uart_irq_handler handler , uint32_t id )
133
138
{
@@ -156,55 +161,57 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
156
161
}
157
162
#endif
158
163
159
- #if defined ( TARGET_STM32F091RC )
164
+ #if defined( USART3_BASE )
160
165
if (obj_s -> uart == UART_3 ) {
166
+ #if defined(TARGET_STM32F091RC )
161
167
irq_n = USART3_8_IRQn ;
162
- vector = (uint32_t )& uart3_irq ;
168
+ #else
169
+ irq_n = USART3_4_IRQn ;
170
+ #endif
171
+ vector = (uint32_t )& uart3_8_irq ;
163
172
}
173
+ #endif
164
174
175
+ #if defined(USART4_BASE )
165
176
if (obj_s -> uart == UART_4 ) {
177
+ #if defined(TARGET_STM32F091RC )
166
178
irq_n = USART3_8_IRQn ;
167
- vector = (uint32_t )& uart4_irq ;
179
+ #else
180
+ irq_n = USART3_4_IRQn ;
181
+ #endif
182
+ vector = (uint32_t )& uart3_8_irq ;
168
183
}
184
+ #endif
169
185
186
+ // Below usart are available only on TARGET_STM32F091RC
187
+ #if defined(USART5_BASE )
170
188
if (obj_s -> uart == UART_5 ) {
171
189
irq_n = USART3_8_IRQn ;
172
- vector = (uint32_t )& uart5_irq ;
190
+ vector = (uint32_t )& uart3_8_irq ;
173
191
}
192
+ #endif
174
193
194
+ #if defined(USART6_BASE )
175
195
if (obj_s -> uart == UART_6 ) {
176
196
irq_n = USART3_8_IRQn ;
177
- vector = (uint32_t )& uart6_irq ;
197
+ vector = (uint32_t )& uart3_8_irq ;
178
198
}
199
+ #endif
179
200
201
+ #if defined(USART7_BASE )
180
202
if (obj_s -> uart == UART_7 ) {
181
203
irq_n = USART3_8_IRQn ;
182
- vector = (uint32_t )& uart7_irq ;
204
+ vector = (uint32_t )& uart3_8_irq ;
183
205
}
206
+ #endif
184
207
208
+ #if defined(USART8_BASE )
185
209
if (obj_s -> uart == UART_8 ) {
186
210
irq_n = USART3_8_IRQn ;
187
- vector = (uint32_t )& uart8_irq ;
188
- }
189
-
190
- #elif defined (TARGET_STM32F030R8 ) || defined (TARGET_STM32F051R8 )
191
-
192
- #else
193
- #if defined(USART3_BASE )
194
- if (obj_s -> uart == UART_3 ) {
195
- irq_n = USART3_4_IRQn ;
196
- vector = (uint32_t )& uart3_irq ;
211
+ vector = (uint32_t )& uart3_8_irq ;
197
212
}
198
213
#endif
199
214
200
- #if defined(USART4_BASE )
201
- if (obj_s -> uart == UART_4 ) {
202
- irq_n = USART3_4_IRQn ;
203
- vector = (uint32_t )& uart4_irq ;
204
- }
205
- #endif
206
- #endif
207
-
208
215
if (enable ) {
209
216
if (irq == RxIrq ) {
210
217
__HAL_UART_ENABLE_IT (huart , UART_IT_RXNE );
0 commit comments