@@ -182,30 +182,21 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
182
182
******************************************************************************/
183
183
184
184
// not api
185
- void uart1_irq ( void ) {
186
- USART_TypeDef * usart = ( USART_TypeDef * ) UART_1 ;
187
- if (serial_irq_ids [ 0 ] != 0 ) {
188
- if ( USART_GetITStatus ( usart , USART_IT_TXE ) != RESET ) {
189
- irq_handler ( serial_irq_ids [ 0 ], TxIrq );
185
+ static void uart_irq ( USART_TypeDef * usart , int id ) {
186
+ if ( serial_irq_ids [ id ] != 0 ) {
187
+ if (USART_GetITStatus ( usart , USART_IT_TC ) != RESET ) {
188
+ irq_handler ( serial_irq_ids [ id ], TxIrq );
189
+ USART_ClearITPendingBit ( usart , USART_IT_TC );
190
190
}
191
191
if (USART_GetITStatus (usart , USART_IT_RXNE ) != RESET ) {
192
- irq_handler (serial_irq_ids [0 ], RxIrq );
192
+ irq_handler (serial_irq_ids [id ], RxIrq );
193
+ USART_ClearITPendingBit (usart , USART_IT_RXNE );
193
194
}
194
195
}
195
196
}
196
197
197
- // not api
198
- void uart2_irq (void ) {
199
- USART_TypeDef * usart = (USART_TypeDef * )UART_2 ;
200
- if (serial_irq_ids [1 ] != 0 ) {
201
- if (USART_GetITStatus (usart , USART_IT_TXE ) != RESET ) {
202
- irq_handler (serial_irq_ids [1 ], TxIrq );
203
- }
204
- if (USART_GetITStatus (usart , USART_IT_RXNE ) != RESET ) {
205
- irq_handler (serial_irq_ids [1 ], RxIrq );
206
- }
207
- }
208
- }
198
+ static void uart1_irq (void ) {uart_irq ((USART_TypeDef * )UART_1 , 0 );}
199
+ static void uart2_irq (void ) {uart_irq ((USART_TypeDef * )UART_2 , 1 );}
209
200
210
201
void serial_irq_handler (serial_t * obj , uart_irq_handler handler , uint32_t id ) {
211
202
irq_handler = handler ;
@@ -233,7 +224,7 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
233
224
USART_ITConfig (usart , USART_IT_RXNE , ENABLE );
234
225
}
235
226
else { // TxIrq
236
- USART_ITConfig (usart , USART_IT_TXE , ENABLE );
227
+ USART_ITConfig (usart , USART_IT_TC , ENABLE );
237
228
}
238
229
239
230
NVIC_SetVector (irq_n , vector );
0 commit comments