aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAmken USA <166057890+amken3d@users.noreply.github.com>2024-04-24 22:32:29 -0400
committerGitHub <noreply@github.com>2024-04-24 22:32:29 -0400
commit0b329c5d28230e8ad19434840bde26f5fd332998 (patch)
tree05dfcfb6be540d528042841061c82f7b4b7d9a71 /src
parentc3ec4af6cc3a62353e1eed57e0514356eeef1fb6 (diff)
downloadkutter-0b329c5d28230e8ad19434840bde26f5fd332998.tar.gz
kutter-0b329c5d28230e8ad19434840bde26f5fd332998.tar.xz
kutter-0b329c5d28230e8ad19434840bde26f5fd332998.zip
rp2040: Add kconfig options for rp2040 uart (#6549)
Modified serial.c and Kconfig to dynamically select all possible UART combinations for RP2040 Signed-off-by: Hriday Keni <info@amken.us>
Diffstat (limited to 'src')
-rw-r--r--src/rp2040/Kconfig47
-rw-r--r--src/rp2040/serial.c73
2 files changed, 97 insertions, 23 deletions
diff --git a/src/rp2040/Kconfig b/src/rp2040/Kconfig
index 59891649..ec8a1af3 100644
--- a/src/rp2040/Kconfig
+++ b/src/rp2040/Kconfig
@@ -95,19 +95,40 @@ config RP2040_STAGE2_CLKDIV
######################################################################
choice
- prompt "Communication interface"
- config RP2040_USB
- bool "USB"
- select USBSERIAL
- config RP2040_SERIAL_UART0
- bool "Serial (on UART0 GPIO1/GPIO0)"
- select SERIAL
- config RP2040_CANBUS
- bool "CAN bus"
- select CANSERIAL
- config RP2040_USBCANBUS
- bool "USB to CAN bus bridge"
- select USBCANBUS
+ prompt "Communication Interface"
+ config RP2040_USB
+ bool "USBSERIAL"
+ select USBSERIAL
+ config RP2040_SERIAL_UART0_PINS_0_1
+ bool "UART0 on GPIO0/GPIO1"
+ select SERIAL
+ config RP2040_SERIAL_UART0_PINS_12_13
+ bool "UART0 on GPIO12/GPIO13" if LOW_LEVEL_OPTIONS
+ select SERIAL
+ config RP2040_SERIAL_UART0_PINS_16_17
+ bool "UART0 on GPIO16/GPIO17" if LOW_LEVEL_OPTIONS
+ select SERIAL
+ config RP2040_SERIAL_UART0_PINS_28_29
+ bool "UART0 on GPIO28/GPIO29" if LOW_LEVEL_OPTIONS
+ select SERIAL
+ config RP2040_SERIAL_UART1_PINS_4_5
+ bool "UART1 on GPIO4/GPIO5" if LOW_LEVEL_OPTIONS
+ select SERIAL
+ config RP2040_SERIAL_UART1_PINS_8_9
+ bool "UART1 on GPIO8/GPIO9" if LOW_LEVEL_OPTIONS
+ select SERIAL
+ config RP2040_SERIAL_UART1_PINS_20_21
+ bool "UART1 on GPIO20/GPIO21" if LOW_LEVEL_OPTIONS
+ select SERIAL
+ config RP2040_SERIAL_UART1_PINS_24_25
+ bool "UART1 on GPIO24/GPIO25" if LOW_LEVEL_OPTIONS
+ select SERIAL
+ config RP2040_CANBUS
+ bool "CAN bus"
+ select CANSERIAL
+ config RP2040_USBCANBUS
+ bool "USB to CAN bus bridge"
+ select USBCANBUS
endchoice
config RP2040_CANBUS_GPIO_RX
diff --git a/src/rp2040/serial.c b/src/rp2040/serial.c
index abfdcb8b..351a873e 100644
--- a/src/rp2040/serial.c
+++ b/src/rp2040/serial.c
@@ -4,20 +4,64 @@
//
// This file may be distributed under the terms of the GNU GPLv3 license.
+
#include <stdint.h> // uint32_t
-#include "autoconf.h" // CONFIG_SERIAL
+#include "autoconf.h" // Include configuration header
#include "board/armcm_boot.h" // armcm_enable_irq
#include "board/irq.h" // irq_save
#include "board/serial_irq.h" // serial_rx_data
-#include "hardware/structs/resets.h" // RESETS_RESET_UART0_BITS
-#include "hardware/structs/uart.h" // UART0_BASE
-#include "internal.h" // UART0_IRQn
+#include "hardware/structs/resets.h" // RESETS_RESET_UART0/1_BITS
+#include "hardware/structs/uart.h" // uart0_hw, uart1_hw
+#include "internal.h" // UART0_IRQn, UART1_IRQn
#include "sched.h" // DECL_INIT
-#define UARTx uart0_hw
-#define UARTx_IRQn UART0_IRQ_IRQn
-#define GPIO_Rx 1
-#define GPIO_Tx 0
+// Dynamically select UART and IRQ based on configuration
+
+
+ #if CONFIG_RP2040_SERIAL_UART0_PINS_0_1
+ #define GPIO_Rx 1
+ #define GPIO_Tx 0
+ #define UARTx uart0_hw
+ #define UARTx_IRQn UART0_IRQ_IRQn
+ #elif CONFIG_RP2040_SERIAL_UART0_PINS_12_13
+ #define GPIO_Rx 13
+ #define GPIO_Tx 12
+ #define UARTx uart0_hw
+ #define UARTx_IRQn UART0_IRQ_IRQn
+ #elif CONFIG_RP2040_SERIAL_UART0_PINS_16_17
+ #define GPIO_Rx 17
+ #define GPIO_Tx 16
+ #define UARTx uart0_hw
+ #define UARTx_IRQn UART0_IRQ_IRQn
+ #elif CONFIG_RP2040_SERIAL_UART0_PINS_28_29
+ #define GPIO_Rx 29
+ #define GPIO_Tx 28
+ #define UARTx uart1_hw
+ #define UARTx_IRQn UART1_IRQ_IRQn
+ #define UARTx uart0_hw
+ #define UARTx_IRQn UART0_IRQ_IRQn
+ #elif CONFIG_RP2040_SERIAL_UART1_PINS_4_5
+ #define GPIO_Rx 5
+ #define GPIO_Tx 4
+ #define UARTx uart1_hw
+ #define UARTx_IRQn UART1_IRQ_IRQn
+ #elif CONFIG_RP2040_SERIAL_UART1_PINS_8_9
+ #define GPIO_Rx 9
+ #define GPIO_Tx 8
+ #define UARTx uart1_hw
+ #define UARTx_IRQn UART1_IRQ_IRQn
+ #elif CONFIG_RP2040_SERIAL_UART1_PINS_20_21
+ #define GPIO_Rx 20
+ #define GPIO_Tx 21
+ #define UARTx uart1_hw
+ #define UARTx_IRQn UART1_IRQ_IRQn
+ #elif CONFIG_RP2040_SERIAL_UART1_PINS_24_25
+ #define GPIO_Rx 24
+ #define GPIO_Tx 25
+ #define UARTx uart1_hw
+ #define UARTx_IRQn UART1_IRQ_IRQn
+ #endif
+
// Write tx bytes to the serial port
static void
@@ -67,10 +111,19 @@ serial_enable_tx_irq(void)
void
serial_init(void)
{
- enable_pclock(RESETS_RESET_UART0_BITS);
+
+ uint32_t pclk= 0x00;
+ if (UARTx == uart0_hw){
+ enable_pclock(RESETS_RESET_UART0_BITS);
+ pclk= get_pclock_frequency(RESETS_RESET_UART0_BITS);
+ } else {
+ enable_pclock(RESETS_RESET_UART1_BITS);
+ pclk = get_pclock_frequency(RESETS_RESET_UART1_BITS);
+ }
+
// Setup baud
- uint32_t pclk = get_pclock_frequency(RESETS_RESET_UART0_BITS);
+
uint32_t div = DIV_ROUND_CLOSEST(pclk * 4, CONFIG_SERIAL_BAUD);
UARTx->ibrd = div >> 6;
UARTx->fbrd = div & 0x3f;