Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Allow ChibiOS SIO driver for UART driver #22839

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,15 @@ ifeq ($(strip $(SPI_DRIVER_REQUIRED)), yes)
endif

ifeq ($(strip $(UART_DRIVER_REQUIRED)), yes)
OPT_DEFS += -DHAL_USE_SERIAL=TRUE
QUANTUM_LIB_SRC += uart.c
ifeq ($(strip $(PLATFORM)), CHIBIOS)
ifneq ($(filter $(MCU_SERIES),RP2040),)
OPT_DEFS += -DHAL_USE_SIO=TRUE
QUANTUM_LIB_SRC += uart_sio.c
else
OPT_DEFS += -DHAL_USE_SERIAL=TRUE
QUANTUM_LIB_SRC += uart_serial.c
endif
else
QUANTUM_LIB_SRC += uart.c
endif
endif
15 changes: 13 additions & 2 deletions docs/platformdev_rp2040.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The following table shows the current driver status for peripherals on RP2040 MCUs:

| System | Support |
| System | Support |
| ---------------------------------------------------------------- | ---------------------------------------------- |
| [ADC driver](adc_driver.md) | :heavy_check_mark: |
| [Audio](audio_driver.md#pwm-hardware) | :heavy_check_mark: |
Expand All @@ -13,7 +13,7 @@ The following table shows the current driver status for peripherals on RP2040 MC
| [External EEPROMs](eeprom_driver.md) | :heavy_check_mark: using `I2C` or `SPI` driver |
| [EEPROM emulation](eeprom_driver.md#wear_leveling-configuration) | :heavy_check_mark: |
| [serial driver](serial_driver.md) | :heavy_check_mark: using `SIO` or `PIO` driver |
| [UART driver](uart_driver.md) | Support planned (no ETA) |
| [UART driver](uart_driver.md) | :heavy_check_mark: using `SIO` driver |

## GPIO

Expand Down Expand Up @@ -52,6 +52,13 @@ To configure the I2C driver please read the [ChibiOS/ARM](i2c_driver.md#arm-conf

To configure the SPI driver please read the [ChibiOS/ARM](spi_driver.md#chibiosarm-configuration) section.

### UART Driver

| RP2040 Peripheral | `mcuconf.h` values | `UART_DRIVER` |
| ----------------- | ------------------ | ------------- |
| `UART0` | `RP_SIO_USE_UART0` | `SIOD0` |
| `UART1` | `RP_SIO_USE_UART1` | `SIOD1` |

## Double-tap reset boot-loader entry :id=double-tap

The double-tap reset mechanism is an alternate way in QMK to enter the embedded mass storage UF2 boot-loader of the RP2040. It enables bootloader entry by a fast double-tap of the reset pin on start up, which is similar to the behavior of AVR Pro Micros. This feature activated by default for the Pro Micro RP2040 board, but has to be configured for other boards. To activate it, add the following options to your keyboards `config.h` file:
Expand Down Expand Up @@ -87,6 +94,10 @@ This is the default board that is chosen, unless any other RP2040 board is selec
| `SOFT_SERIAL_PIN` | undefined, use `SERIAL_USART_TX_PIN` |
| `SERIAL_USART_TX_PIN` | `GP0` |
| `SERIAL_USART_RX_PIN` | `GP1` |
| **UART driver** | |
| `UART_DRIVER` | `SIOD0` |
| `UART_TX_PIN` | `GP0` |
| `UART_RX_PIN` | `GP1` |

?> The pin-outs of Adafruit's KB2040 and Boardsource's Blok both deviate from the Sparkfun Pro Micro RP2040. Lookup the pin-out of these boards and adjust your keyboards pin definition accordingly if you want to use these boards.

Expand Down
30 changes: 12 additions & 18 deletions docs/uart_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ No special setup is required - just connect the `RX` and `TX` pins of your UART

You'll need to determine which pins can be used for UART -- as an example, STM32 parts generally have multiple UART peripherals, labeled USART1, USART2, USART3 etc.

To enable UART, modify your board's `halconf.h` to enable the serial driver:

```c
#define HAL_USE_SERIAL TRUE
```

Then, modify your board's `mcuconf.h` to enable the peripheral you've chosen, for example:
To enable UART, modify your board's `mcuconf.h` to enable the peripheral you've chosen, for example:

```c
#undef STM32_SERIAL_USE_USART2
Expand All @@ -47,17 +41,17 @@ Then, modify your board's `mcuconf.h` to enable the peripheral you've chosen, fo

Configuration-wise, you'll need to set up the peripheral as per your MCU's datasheet -- the defaults match the pins for a Proton-C, i.e. STM32F303.

|`config.h` override |Description |Default Value|
|--------------------------|---------------------------------------------------------------|-------------|
|`#define SERIAL_DRIVER` |USART peripheral to use - USART1 -> `SD1`, USART2 -> `SD2` etc.|`SD1` |
|`#define SD1_TX_PIN` |The pin to use for TX |`A9` |
|`#define SD1_TX_PAL_MODE` |The alternate function mode for TX |`7` |
|`#define SD1_RX_PIN` |The pin to use for RX |`A10` |
|`#define SD1_RX_PAL_MODE` |The alternate function mode for RX |`7` |
|`#define SD1_CTS_PIN` |The pin to use for CTS |`A11` |
|`#define SD1_CTS_PAL_MODE`|The alternate function mode for CTS |`7` |
|`#define SD1_RTS_PIN` |The pin to use for RTS |`A12` |
|`#define SD1_RTS_PAL_MODE`|The alternate function mode for RTS |`7` |
| `config.h` override | Description | Default Value |
| --------------------------- | --------------------------------------------------------------- | ------------- |
| `#define UART_DRIVER` | USART peripheral to use - USART1 -> `SD1`, USART2 -> `SD2` etc. | `SD1` |
| `#define UART_TX_PIN` | The pin to use for TX | `A9` |
| `#define UART_TX_PAL_MODE` | The alternate function mode for TX | `7` |
| `#define UART_RX_PIN` | The pin to use for RX | `A10` |
| `#define UART_RX_PAL_MODE` | The alternate function mode for RX | `7` |
| `#define UART_CTS_PIN` | The pin to use for CTS | `A11` |
| `#define UART_CTS_PAL_MODE` | The alternate function mode for CTS | `7` |
| `#define UART_RTS_PIN` | The pin to use for RTS | `A12` |
| `#define UART_RTS_PAL_MODE` | The alternate function mode for RTS | `7` |

## API :id=api

Expand Down
6 changes: 6 additions & 0 deletions keyboards/handwired/onekey/stm32f3_disco/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
#pragma once

#define ADC_PIN A0

#define UART_TX_PIN C4
#define UART_RX_PIN C5

#define SERIAL_USART_TX_PIN C4
#define SERIAL_USART_RX_PIN C4
6 changes: 6 additions & 0 deletions keyboards/handwired/onekey/stm32f3_disco/mcuconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@

#undef STM32_ADC_USE_ADC1
#define STM32_ADC_USE_ADC1 TRUE

#undef STM32_SIO_USE_USART1
#define STM32_SIO_USE_USART1 TRUE

#undef STM32_SERIAL_USE_USART1
#define STM32_SERIAL_USE_USART1 TRUE
28 changes: 26 additions & 2 deletions platforms/chibios/boards/GENERIC_PROMICRO_RP2040/configs/config.h
KarlK90 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Stefan Kerkmann
// Copyright 2024 Stefan Kerkmann
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once
Expand Down Expand Up @@ -55,8 +55,32 @@
# define SERIAL_USART_RX_PIN GP1
#endif

/**======================
** UART Driver
*========================**/

#if !defined(UART_DRIVER)
# define UART_DRIVER SIOD0
#endif

#if !defined(UART_TX_PIN)
# define UART_TX_PIN GP0
#endif

#if !defined(UART_RX_PIN)
# define UART_RX_PIN GP1
#endif

#if !defined(UART_CTS_PIN)
# define UART_CTS_PIN GP2
#endif

#if !defined(UART_RTS_PIN)
# define UART_RTS_PIN GP3
#endif

/**======================
** Double-tap
*========================**/

#define RP2040_BOOTLOADER_DOUBLE_TAP_RESET
#define RP2040_BOOTLOADER_DOUBLE_TAP_RESET
24 changes: 24 additions & 0 deletions platforms/chibios/boards/QMK_BLOK/configs/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#pragma once

/**======================
** I2C Driver
*========================**/

#ifndef I2C_DRIVER
# define I2C_DRIVER I2CD0
#endif
Expand All @@ -13,6 +17,26 @@
# define I2C1_SCL_PIN D0
#endif

/**======================
** UART Driver
*========================**/

#ifndef UART_DRIVER
# define UART_DRIVER SIOD0
#endif

#ifndef UART_TX_PIN
# define UART_TX_PIN D3
#endif

#ifndef UART_RX_PIN
# define UART_RX_PIN D2
#endif

/**======================
** Double-tap
*========================**/

#ifndef RP2040_BOOTLOADER_DOUBLE_TAP_RESET
# define RP2040_BOOTLOADER_DOUBLE_TAP_RESET
#endif
Expand Down
24 changes: 24 additions & 0 deletions platforms/chibios/boards/QMK_PM2040/configs/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#pragma once

/**======================
** I2C Driver
*========================**/

#ifndef I2C_DRIVER
# define I2C_DRIVER I2CD1
#endif
Expand All @@ -13,6 +17,26 @@
# define I2C1_SCL_PIN D0
#endif

/**======================
** UART Driver
*========================**/

#ifndef UART_DRIVER
# define UART_DRIVER SIOD0
#endif

#ifndef UART_TX_PIN
# define UART_TX_PIN D3
#endif

#ifndef UART_RX_PIN
# define UART_RX_PIN D2
#endif

/**======================
** Double-tap
*========================**/

#ifndef RP2040_BOOTLOADER_DOUBLE_TAP_RESET
# define RP2040_BOOTLOADER_DOUBLE_TAP_RESET
#endif
Expand Down
14 changes: 14 additions & 0 deletions platforms/chibios/chibios_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@
# ifndef SPI_MISO_PAL_MODE
# define SPI_MISO_PAL_MODE (PAL_MODE_ALTERNATE_SPI | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_DRIVE4)
# endif

# ifndef UART_TX_PAL_MODE
# define UART_TX_PAL_MODE PAL_MODE_ALTERNATE_UART
# endif
# ifndef UART_RX_PAL_MODE
# define UART_RX_PAL_MODE PAL_MODE_ALTERNATE_UART
# endif
# ifndef UART_CTS_PAL_MODE
# define UART_CTS_PAL_MODE PAL_MODE_ALTERNATE_UART
# endif
# ifndef UART_RTS_PAL_MODE
# define UART_RTS_PAL_MODE PAL_MODE_ALTERNATE_UART
# endif

#endif

// STM32 compatibility
Expand Down
70 changes: 0 additions & 70 deletions platforms/chibios/drivers/uart.c

This file was deleted.

Loading
Loading