Skip to content

Commit

Permalink
Fixed LPUART1 on G4
Browse files Browse the repository at this point in the history
  • Loading branch information
DieHertz authored and haslinghuis committed Mar 10, 2023
1 parent ffec6f4 commit abb7672
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/main/drivers/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "drivers/io.h"
#include "drivers/io_types.h"
#include "drivers/resource.h"
// TODO(hertz@): uncomment and use UARTDevice_e::MAX_UARTDEV
// #include "drivers/serial_uart.h"

#include "pg/pg.h"

Expand Down
37 changes: 23 additions & 14 deletions src/main/drivers/serial_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,47 +388,56 @@ void uartConfigureDma(uartDevice_t *uartdev)
}
#endif

#define UART_IRQHandler(type, number, dev) \
FAST_IRQ_HANDLER void type ## number ## _IRQHandler(void) \
{ \
uartPort_t *uartPort = &(uartDevmap[UARTDEV_ ## dev]->port); \
uartIrqHandler(uartPort); \
#define UART_IRQHandler(type, number, dev) \
FAST_IRQ_HANDLER void type ## number ## _IRQHandler(void) \
{ \
uartPort_t *uartPort = &(uartDevmap[dev]->port); \
uartIrqHandler(uartPort); \
}

#ifdef USE_UART1
UART_IRQHandler(USART, 1, 1) // USART1 Rx/Tx IRQ Handler
UART_IRQHandler(USART, 1, UARTDEV_1) // USART1 Rx/Tx IRQ Handler
#endif

#ifdef USE_UART2
UART_IRQHandler(USART, 2, 2) // USART2 Rx/Tx IRQ Handler
UART_IRQHandler(USART, 2, UARTDEV_2) // USART2 Rx/Tx IRQ Handler
#endif

#ifdef USE_UART3
UART_IRQHandler(USART, 3, 3) // USART3 Rx/Tx IRQ Handler
UART_IRQHandler(USART, 3, UARTDEV_3) // USART3 Rx/Tx IRQ Handler
#endif

#ifdef USE_UART4
UART_IRQHandler(UART, 4, 4) // UART4 Rx/Tx IRQ Handler
UART_IRQHandler(UART, 4, UARTDEV_4) // UART4 Rx/Tx IRQ Handler
#endif

#ifdef USE_UART5
UART_IRQHandler(UART, 5, 5) // UART5 Rx/Tx IRQ Handler
UART_IRQHandler(UART, 5, UARTDEV_5) // UART5 Rx/Tx IRQ Handler
#endif

#ifdef USE_UART6
UART_IRQHandler(USART, 6, 6) // USART6 Rx/Tx IRQ Handler
UART_IRQHandler(USART, 6, UARTDEV_6) // USART6 Rx/Tx IRQ Handler
#endif

#ifdef USE_UART7
UART_IRQHandler(UART, 7, 7) // UART7 Rx/Tx IRQ Handler
UART_IRQHandler(UART, 7, UARTDEV_7) // UART7 Rx/Tx IRQ Handler
#endif

#ifdef USE_UART8
UART_IRQHandler(UART, 8, 8) // UART8 Rx/Tx IRQ Handler
UART_IRQHandler(UART, 8, UARTDEV_8) // UART8 Rx/Tx IRQ Handler
#endif

#ifdef USE_UART9
UART_IRQHandler(LPUART, 1, 9) // UART9 (implemented with LPUART1) Rx/Tx IRQ Handler
UART_IRQHandler(UART, 9, UARTDEV_9) // UART9 Rx/Tx IRQ Handler
#endif

#ifdef USE_UART10
UART_IRQHandler(UART, 10, UARTDEV_10) // UART10 Rx/Tx IRQ Handler
#endif

#ifdef USE_LPUART1
UART_IRQHandler(LPUART, 1, LPUARTDEV_1) // LPUART1 Rx/Tx IRQ Handler
#endif


#endif // USE_UART
2 changes: 2 additions & 0 deletions src/main/drivers/serial_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ typedef enum {
UARTDEV_9 = 8,
UARTDEV_10 = 9,
LPUARTDEV_1 = 10,

MAX_UARTDEV = LPUARTDEV_1,
} UARTDevice_e;

typedef struct uartPort_s {
Expand Down
12 changes: 6 additions & 6 deletions src/main/drivers/stm32/serial_uart_stm32g4xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@
#ifndef UART5_RX_DMA_CHANNEL
#define UART5_RX_DMA_CHANNEL NULL
#endif
#ifndef UART9_TX_DMA_CHANNEL
#define UART9_TX_DMA_CHANNEL NULL
#ifndef LPUART1_TX_DMA_CHANNEL
#define LPUART1_TX_DMA_CHANNEL NULL
#endif
#ifndef UART9_RX_DMA_CHANNEL
#define UART9_RX_DMA_CHANNEL NULL
#ifndef LPUART1_RX_DMA_CHANNEL
#define LPUART1_RX_DMA_CHANNEL NULL
#endif

const uartHardware_t uartHardware[UARTDEV_COUNT] = {
Expand Down Expand Up @@ -228,9 +228,9 @@ const uartHardware_t uartHardware[UARTDEV_COUNT] = {
.reg = LPUART1,
#ifdef USE_DMA
.rxDMAChannel = DMA_REQUEST_LPUART1_RX,
.rxDMAResource = (dmaResource_t *)UART9_RX_DMA_CHANNEL,
.rxDMAResource = (dmaResource_t *)LPUART1_RX_DMA_CHANNEL,
.txDMAChannel = DMA_REQUEST_LPUART1_TX,
.txDMAResource = (dmaResource_t *)UART9_TX_DMA_CHANNEL,
.txDMAResource = (dmaResource_t *)LPUART1_TX_DMA_CHANNEL,
#endif
.rxPins = {
{ DEFIO_TAG_E(PA3), GPIO_AF12_LPUART1 },
Expand Down
8 changes: 6 additions & 2 deletions src/main/pg/serial_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "drivers/serial.h"
#include "drivers/serial_uart.h"

// TODO(hertz@): UARTDEV_CONFIG_MAX is measured to be exactly 8, which cannot accomodate even all the UARTs below
PG_REGISTER_ARRAY_WITH_RESET_FN(serialUartConfig_t, UARTDEV_CONFIG_MAX, serialUartConfig, PG_SERIAL_UART_CONFIG, 0);

typedef struct uartDmaopt_s {
Expand Down Expand Up @@ -74,13 +75,16 @@ static uartDmaopt_t uartDmaopt[] = {
#ifdef USE_UART10
{ UARTDEV_10, UART10_TX_DMA_OPT, UART10_RX_DMA_OPT },
#endif
#ifdef USE_LPUART1
{ LPUARTDEV_1, DMA_OPT_UNUSED, DMA_OPT_UNUSED },
#endif
};

void pgResetFn_serialUartConfig(serialUartConfig_t *config)
{
for (unsigned i = 0; i < UARTDEV_CONFIG_MAX; i++) {
config[i].txDmaopt = -1;
config[i].rxDmaopt = -1;
config[i].txDmaopt = DMA_OPT_UNUSED;
config[i].rxDmaopt = DMA_OPT_UNUSED;
}

for (unsigned i = 0; i < ARRAYLEN(uartDmaopt); i++) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/pg/serial_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include "drivers/io_types.h"
#include "drivers/dma_reqmap.h"

#define UARTDEV_CONFIG_MAX 8 // Alternative to UARTDEV_COUNT_MAX, which requires serial_uart_imp.h

// TODO(hertz@): this alternative got out of sync
#define UARTDEV_CONFIG_MAX 11 // Alternative to UARTDEV_COUNT_MAX, which requires serial_uart_imp.h

typedef struct serialUartConfig_s {
int8_t txDmaopt;
Expand Down

0 comments on commit abb7672

Please sign in to comment.