@@ -227,20 +227,20 @@ static stream_ret_t stream_read_timeout(Stream *self, void *buf, size_t size, si
227
227
}
228
228
return i ? STREAM_RET_OK : STREAM_RET_TIMEOUT ;
229
229
} else {
230
- if (c == 0x1b ) {
230
+ // if (c == 0x1b) {
231
231
/* Do not handle timeout. We are sure there is another byte ready
232
232
* when ESC is received. Read the next byte after the ESC. */
233
- r = xStreamBufferReceive (stm32_uart -> rxbuf , & c , sizeof (c ), timeout_ms );
234
- ((uint8_t * )buf )[i ] = c ;
235
- } else if (c == 0x17 ) {
233
+ // r = xStreamBufferReceive(stm32_uart->rxbuf, &c, sizeof(c), timeout_ms);
234
+ // ((uint8_t *)buf)[i] = c;
235
+ // } else if (c == 0x17) {
236
236
/* Handle end of block (signalled by RTO interrupt). */
237
- if (read != NULL ) {
238
- * read = i ;
239
- }
240
- return STREAM_RET_EOT ;
241
- } else {
237
+ // if (read != NULL) {
238
+ // *read = i;
239
+ // }
240
+ // return STREAM_RET_EOT;
241
+ // } else {
242
242
((uint8_t * )buf )[i ] = c ;
243
- }
243
+ // }
244
244
}
245
245
}
246
246
if (read != NULL ) {
@@ -349,6 +349,7 @@ stm32_uart_ret_t stm32_uart_interrupt_handler(Stm32Uart *self) {
349
349
350
350
while ((USART_ISR (self -> port ) & USART_ISR_TXE )) {
351
351
uint8_t b = 0 ;
352
+ /** @todo 1 us! */
352
353
size_t r = xStreamBufferReceiveFromISR (self -> txbuf , & b , sizeof (b ), 0 );
353
354
if (r > 0 ) {
354
355
usart_send (self -> port , b );
@@ -369,25 +370,19 @@ stm32_uart_ret_t stm32_uart_interrupt_handler(Stm32Uart *self) {
369
370
USART_ICR (self -> port ) |= USART_ICR_TCCF ;
370
371
}
371
372
372
- while ((USART_ISR (self -> port ) & USART_ISR_RXNE )) {
373
- uint8_t b = usart_recv (self -> port );
374
-
375
- /* For any character < 0x20, prepend ESC */
376
- if (b < 0x20 ) {
377
- const uint8_t esc = 0x1b ;
378
- xStreamBufferSendFromISR (self -> rxbuf , & esc , sizeof (esc ), & woken );
379
- }
380
- /* Do not check the return value. If there was not enough space to save
381
- * the received byte, we have nothing else to do. */
382
- xStreamBufferSendFromISR (self -> rxbuf , & b , sizeof (b ), & woken );
373
+ /* Aggregate multiple receptions until the FIFO is empty or bbuf full. */
374
+ uint8_t bbuf [32 ];
375
+ size_t bbuf_len = 0 ;
376
+ while ((USART_ISR (self -> port ) & USART_ISR_RXNE ) && (bbuf_len < sizeof (bbuf ))) {
377
+ bbuf [bbuf_len ] = usart_recv (self -> port );
378
+ bbuf_len ++ ;
379
+ }
380
+ if (bbuf_len > 0 ) {
381
+ xStreamBufferSendFromISR (self -> rxbuf , bbuf , bbuf_len , & woken );
383
382
}
384
383
385
384
if (USART_ISR (self -> port ) & USART_ISR_RTOF ) {
386
385
USART_ICR (self -> port ) |= USART_ICR_RTOCF ;
387
-
388
- const uint8_t etb = 0x17 ;
389
- xStreamBufferSendFromISR (self -> rxbuf , & etb , sizeof (etb ), & woken );
390
- portYIELD_FROM_ISR (woken );
391
386
}
392
387
393
388
/* Enabling the RXNE interrupt also enables ORE. We must handle it properly. */
@@ -413,7 +408,7 @@ stm32_uart_ret_t stm32_uart_set_rto(Stm32Uart *self, bool rto) {
413
408
if (rto ) {
414
409
/* Set receiver timeout enable. 3 character time. */
415
410
USART_CR2 (self -> port ) |= USART_CR2_RTOEN ;
416
- USART_RTOR (self -> port ) = 20L ;
411
+ USART_RTOR (self -> port ) = 200L ;
417
412
418
413
/* Enable timeout interrupt. */
419
414
USART_CR1 (self -> port ) |= USART_CR1_RTOIE ;
0 commit comments