Raise STM32F1 UART IRQ Priority, add error handling (#19301)
(Error handling for Overrun, Framing and Parity.)
This commit is contained in:
parent
20ac0faa86
commit
b98946b5c1
@ -55,10 +55,8 @@
|
|||||||
|
|
||||||
void MarlinSerial::begin(unsigned long baud, uint8_t config) {
|
void MarlinSerial::begin(unsigned long baud, uint8_t config) {
|
||||||
HardwareSerial::begin(baud, config);
|
HardwareSerial::begin(baud, config);
|
||||||
// replace the IRQ callback with the one we have defined
|
// Replace the IRQ callback with the one we have defined
|
||||||
#if ENABLED(EMERGENCY_PARSER)
|
TERN_(EMERGENCY_PARSER, _serial.rx_callback = _rx_callback);
|
||||||
_serial.rx_callback = _rx_callback;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is Copyright (c) 2006 Nicholas Zambetti.
|
// This function is Copyright (c) 2006 Nicholas Zambetti.
|
||||||
|
@ -35,7 +35,14 @@ static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb
|
|||||||
* See table 198 (sec 27.4, p809) in STM document RM0008 rev 15.
|
* See table 198 (sec 27.4, p809) in STM document RM0008 rev 15.
|
||||||
* We enable RXNEIE.
|
* We enable RXNEIE.
|
||||||
*/
|
*/
|
||||||
if ((regs->CR1 & USART_CR1_RXNEIE) && (regs->SR & USART_SR_RXNE)) {
|
uint32_t srflags = regs->SR, cr1its = regs->CR1;
|
||||||
|
|
||||||
|
if ((cr1its & USART_CR1_RXNEIE) && (srflags & USART_SR_RXNE)) {
|
||||||
|
if (srflags & USART_SR_FE || srflags & USART_SR_PE ) {
|
||||||
|
// framing error or parity error
|
||||||
|
regs->DR; // Read and throw away the data, which also clears FE and PE
|
||||||
|
}
|
||||||
|
else {
|
||||||
uint8_t c = (uint8)regs->DR;
|
uint8_t c = (uint8)regs->DR;
|
||||||
#ifdef USART_SAFE_INSERT
|
#ifdef USART_SAFE_INSERT
|
||||||
// If the buffer is full and the user defines USART_SAFE_INSERT,
|
// If the buffer is full and the user defines USART_SAFE_INSERT,
|
||||||
@ -49,8 +56,16 @@ static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb
|
|||||||
emergency_parser.update(serial.emergency_state, c);
|
emergency_parser.update(serial.emergency_state, c);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (srflags & USART_SR_ORE) {
|
||||||
|
// overrun and empty data, just do a dummy read to clear ORE
|
||||||
|
// and prevent a raise condition where a continous interrupt stream (due to ORE set) occurs
|
||||||
|
// (see chapter "Overrun error" ) in STM32 reference manual
|
||||||
|
regs->DR;
|
||||||
|
}
|
||||||
|
|
||||||
// TXE signifies readiness to send a byte to DR.
|
// TXE signifies readiness to send a byte to DR.
|
||||||
if ((regs->CR1 & USART_CR1_TXEIE) && (regs->SR & USART_SR_TXE)) {
|
if ((cr1its & USART_CR1_TXEIE) && (srflags & USART_SR_TXE)) {
|
||||||
if (!rb_is_empty(wb))
|
if (!rb_is_empty(wb))
|
||||||
regs->DR=rb_remove(wb);
|
regs->DR=rb_remove(wb);
|
||||||
else
|
else
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <HardwareSerial.h>
|
#include <HardwareSerial.h>
|
||||||
|
#include <libmaple/usart.h>
|
||||||
#include <WString.h>
|
#include <WString.h>
|
||||||
|
|
||||||
#include "../../inc/MarlinConfigPre.h"
|
#include "../../inc/MarlinConfigPre.h"
|
||||||
@ -29,6 +30,8 @@
|
|||||||
#include "../../feature/e_parser.h"
|
#include "../../feature/e_parser.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define UART_IRQ_PRIO 1
|
||||||
|
|
||||||
class MarlinSerial : public HardwareSerial {
|
class MarlinSerial : public HardwareSerial {
|
||||||
public:
|
public:
|
||||||
MarlinSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin) :
|
MarlinSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin) :
|
||||||
@ -38,6 +41,18 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
#ifdef UART_IRQ_PRIO
|
||||||
|
// shadow the parent methods to set irq priority after the begin
|
||||||
|
void begin(uint32 baud) {
|
||||||
|
MarlinSerial::begin(baud, SERIAL_8N1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void begin(uint32 baud, uint8_t config) {
|
||||||
|
HardwareSerial::begin(baud, config);
|
||||||
|
nvic_irq_set_priority(c_dev()->irq_num, UART_IRQ_PRIO);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLED(EMERGENCY_PARSER)
|
#if ENABLED(EMERGENCY_PARSER)
|
||||||
EmergencyParser::State emergency_state;
|
EmergencyParser::State emergency_state;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user