🔧 STM32 support 9 UARTs (#26072)

This commit is contained in:
ellensp
2023-07-30 11:30:56 +12:00
committed by GitHub
parent 347a7dc71e
commit abd1896ce2
3 changed files with 29 additions and 17 deletions

View File

@@ -57,61 +57,61 @@
#define _MSERIAL(X) MSerial##X #define _MSERIAL(X) MSerial##X
#define MSERIAL(X) _MSERIAL(X) #define MSERIAL(X) _MSERIAL(X)
#if WITHIN(SERIAL_PORT, 1, 6) #if WITHIN(SERIAL_PORT, 1, 9)
#define MYSERIAL1 MSERIAL(SERIAL_PORT) #define MYSERIAL1 MSERIAL(SERIAL_PORT)
#elif !defined(USBCON) #elif !defined(USBCON)
#error "SERIAL_PORT must be from 1 to 6." #error "SERIAL_PORT must be from 1 to 9."
#elif SERIAL_PORT == -1 #elif SERIAL_PORT == -1
#define MYSERIAL1 MSerialUSB #define MYSERIAL1 MSerialUSB
#else #else
#error "SERIAL_PORT must be from 1 to 6, or -1 for Native USB." #error "SERIAL_PORT must be from 1 to 9, or -1 for Native USB."
#endif #endif
#ifdef SERIAL_PORT_2 #ifdef SERIAL_PORT_2
#if WITHIN(SERIAL_PORT_2, 1, 6) #if WITHIN(SERIAL_PORT_2, 1, 9)
#define MYSERIAL2 MSERIAL(SERIAL_PORT_2) #define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#elif !defined(USBCON) #elif !defined(USBCON)
#error "SERIAL_PORT_2 must be from 1 to 6." #error "SERIAL_PORT_2 must be from 1 to 9."
#elif SERIAL_PORT_2 == -1 #elif SERIAL_PORT_2 == -1
#define MYSERIAL2 MSerialUSB #define MYSERIAL2 MSerialUSB
#else #else
#error "SERIAL_PORT_2 must be from 1 to 6, or -1 for Native USB." #error "SERIAL_PORT_2 must be from 1 to 9, or -1 for Native USB."
#endif #endif
#endif #endif
#ifdef SERIAL_PORT_3 #ifdef SERIAL_PORT_3
#if WITHIN(SERIAL_PORT_3, 1, 6) #if WITHIN(SERIAL_PORT_3, 1, 9)
#define MYSERIAL3 MSERIAL(SERIAL_PORT_3) #define MYSERIAL3 MSERIAL(SERIAL_PORT_3)
#elif !defined(USBCON) #elif !defined(USBCON)
#error "SERIAL_PORT_3 must be from 1 to 6." #error "SERIAL_PORT_3 must be from 1 to 9."
#elif SERIAL_PORT_3 == -1 #elif SERIAL_PORT_3 == -1
#define MYSERIAL3 MSerialUSB #define MYSERIAL3 MSerialUSB
#else #else
#error "SERIAL_PORT_3 must be from 1 to 6, or -1 for Native USB." #error "SERIAL_PORT_3 must be from 1 to 9, or -1 for Native USB."
#endif #endif
#endif #endif
#ifdef MMU2_SERIAL_PORT #ifdef MMU2_SERIAL_PORT
#if WITHIN(MMU2_SERIAL_PORT, 1, 6) #if WITHIN(MMU2_SERIAL_PORT, 1, 9)
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT) #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
#elif !defined(USBCON) #elif !defined(USBCON)
#error "MMU2_SERIAL_PORT must be from 1 to 6." #error "MMU2_SERIAL_PORT must be from 1 to 9."
#elif MMU2_SERIAL_PORT == -1 #elif MMU2_SERIAL_PORT == -1
#define MMU2_SERIAL MSerialUSB #define MMU2_SERIAL MSerialUSB
#else #else
#error "MMU2_SERIAL_PORT must be from 1 to 6, or -1 for Native USB." #error "MMU2_SERIAL_PORT must be from 1 to 9, or -1 for Native USB."
#endif #endif
#endif #endif
#ifdef LCD_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if WITHIN(LCD_SERIAL_PORT, 1, 6) #if WITHIN(LCD_SERIAL_PORT, 1, 9)
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT) #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#elif !defined(USBCON) #elif !defined(USBCON)
#error "LCD_SERIAL_PORT must be from 1 to 6." #error "LCD_SERIAL_PORT must be from 1 to 9."
#elif LCD_SERIAL_PORT == -1 #elif LCD_SERIAL_PORT == -1
#define LCD_SERIAL MSerialUSB #define LCD_SERIAL MSerialUSB
#else #else
#error "LCD_SERIAL_PORT must be from 1 to 6, or -1 for Native USB." #error "LCD_SERIAL_PORT must be from 1 to 9, or -1 for Native USB."
#endif #endif
#if HAS_DGUS_LCD #if HAS_DGUS_LCD
#define LCD_SERIAL_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite() #define LCD_SERIAL_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()

View File

@@ -37,6 +37,15 @@
#ifndef USART5 #ifndef USART5
#define USART5 UART5 #define USART5 UART5
#endif #endif
#ifndef USART7
#define USART7 UART7
#endif
#ifndef USART8
#define USART8 UART8
#endif
#ifndef USART9
#define USART9 UART9
#endif
#define DECLARE_SERIAL_PORT(ser_num) \ #define DECLARE_SERIAL_PORT(ser_num) \
void _rx_complete_irq_ ## ser_num (serial_t * obj); \ void _rx_complete_irq_ ## ser_num (serial_t * obj); \

View File

@@ -45,7 +45,7 @@ struct USARTMin {
volatile uint32_t CR2; volatile uint32_t CR2;
}; };
#if WITHIN(SERIAL_PORT, 1, 6) #if WITHIN(SERIAL_PORT, 1, 9)
// Depending on the CPU, the serial port is different for USART1 // Depending on the CPU, the serial port is different for USART1
static const uintptr_t regsAddr[] = { static const uintptr_t regsAddr[] = {
TERN(STM32F1xx, 0x40013800, 0x40011000), // USART1 TERN(STM32F1xx, 0x40013800, 0x40011000), // USART1
@@ -54,6 +54,9 @@ struct USARTMin {
0x40004C00, // UART4_BASE 0x40004C00, // UART4_BASE
0x40005000, // UART5_BASE 0x40005000, // UART5_BASE
0x40011400 // USART6 0x40011400 // USART6
0x40007800 // UART7_BASE
0x40007C00 // UART8_BASE
0x40011800 // UART9_BASE
}; };
static USARTMin * regs = (USARTMin*)regsAddr[SERIAL_PORT - 1]; static USARTMin * regs = (USARTMin*)regsAddr[SERIAL_PORT - 1];
#endif #endif
@@ -116,7 +119,7 @@ static void TXBegin() {
// A SW memory barrier, to ensure GCC does not overoptimize loops // A SW memory barrier, to ensure GCC does not overoptimize loops
#define sw_barrier() __asm__ volatile("": : :"memory"); #define sw_barrier() __asm__ volatile("": : :"memory");
static void TX(char c) { static void TX(char c) {
#if WITHIN(SERIAL_PORT, 1, 6) #if WITHIN(SERIAL_PORT, 1, 9)
constexpr uint32_t usart_sr_txe = _BV(7); constexpr uint32_t usart_sr_txe = _BV(7);
while (!(regs->SR & usart_sr_txe)) { while (!(regs->SR & usart_sr_txe)) {
hal.watchdog_refresh(); hal.watchdog_refresh();