Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
19804: cpu/nrf{53,9160}: add periph_rtt support r=benpicco a=dylad

### Contribution description

This PR enables support for `periph_rtt` on both nRF9160 and nRF53.
This PR is based on #19803 

I was only able to test on nrf5340dk-app as I don't have access to any nrf9160-based board.

Here is `test/periph/rtt` output for reference on `nrf5340dk-app`:

### Testing procedure
flash `tests/periph/rtt` on `nrf9160dk` or `nrf5340dk-app`  and check the results.
```
s
2023-07-06 16:11:16,471 # START
2023-07-06 16:11:16,479 # main(): This is RIOT! (Version: 2023.07-devel-765-g02c65-cpu/nrf53/add_rtt_support)
2023-07-06 16:11:16,480 # 
2023-07-06 16:11:16,482 # RIOT RTT low-level driver test
2023-07-06 16:11:16,483 # RTT configuration:
2023-07-06 16:11:16,485 # RTT_MAX_VALUE: 0x00ffffff
2023-07-06 16:11:16,487 # RTT_FREQUENCY: 1024
2023-07-06 16:11:16,487 # 
2023-07-06 16:11:16,494 # Testing the tick conversion (with rounding if RTT_FREQUENCY is not power of 2)
2023-07-06 16:11:16,498 # Trying to convert 1 to seconds and back
2023-07-06 16:11:16,501 # Trying to convert 256 to seconds and back
2023-07-06 16:11:16,505 # Trying to convert 65536 to seconds and back
2023-07-06 16:11:16,509 # Trying to convert 16777216 to seconds and back
2023-07-06 16:11:16,514 # Trying to convert 2147483648 to seconds and back
2023-07-06 16:11:16,514 # All ok
2023-07-06 16:11:16,514 # 
2023-07-06 16:11:16,517 # Initializing the RTT driver
2023-07-06 16:11:16,835 # This test will now display 'Hello' every 5 seconds
2023-07-06 16:11:16,835 # 
2023-07-06 16:11:16,836 # RTT now: 4
2023-07-06 16:11:16,840 # Setting initial alarm to now + 5 s (5124)
2023-07-06 16:11:16,841 # rtt_get_alarm() PASSED
2023-07-06 16:11:16,846 # Done setting up the RTT, wait for many Hellos
2023-07-06 16:11:16,852 # { "threads": [{ "name": "main", "stack_size": 1536, "stack_used": 404 }]}
2023-07-06 16:11:21,833 # Hello
2023-07-06 16:11:26,831 # Hello
2023-07-06 16:11:31,830 # Hello
2023-07-06 16:11:36,828 # Hello
2023-07-06 16:11:41,826 # Hello
2023-07-06 16:11:46,825 # Hello
2023-07-06 16:11:51,823 # Hello
2023-07-06 16:11:56,821 # Hello
2023-07-06 16:12:01,821 # Hello
2023-07-06 16:12:06,819 # Hello
2023-07-06 16:12:11,817 # Hello
2023-07-06 16:12:16,815 # Hello
2023-07-06 16:12:21,813 # Hello
2023-07-06 16:12:26,811 # Hello
```
### Issues/PRs references
based on #19803 

19807: boards/esp32s2-lilygo-ttgo-t8: fix display configuration r=benpicco a=gschorcht

### Contribution description

This PR fixes the display configuration for the ESP32-S2 LilyGO TTGO T8 (also known as LilyGo T-Display S2) which uses a ST7789 as display driver IC that is compatible with the ST7735.

For that purpose the ST7735 driver is extended by a pseudomodule definition `st7789` for the ST7789 which is enabled by the board and enables automatically the `st7789` (f57b6b7). Vise versa, board's `Makefile.dep` enables automatically the `st7789` pseudomodule if the `st7735` is used. The pseudomodule `st7789` is just used to increase the upper limit for supported lines.

### Testing procedure

```
BOARD=esp32s2-lilygo-ttgo-t8 make -C tests/drivers/st7735/ flash
```
should work:

![IMG_20230707_112616](https://github.com/RIOT-OS/RIOT/assets/31932013/4393866b-27d9-4a6a-96fc-7c460be35cde)

### Issues/PRs references

19809: cpu/nrf53: add usbdev support r=benpicco a=dylad

### Contribution description
This PR enables `periph_usbdev` support on nRF5340DK-app board. Since the IP is the same as nRF52, the driver and its related data and structs were moved from `cpu/nrf52` to `cpu/nrf5x_common`


### Testing procedure
Test any USBUS related test application on `nrf5340dk-app`

`CFLAGS='-DSECTOR_COUNT=64' USEMODULE='mtd_emulated' make BOARD=nrf5340dk-app -C tests/sys/usbus_msc flash`

dmesg output:
```
[ 7466.262760] usb 1-2.1: new full-speed USB device number 16 using xhci_hcd
[ 7466.483916] usb 1-2.1: New USB device found, idVendor=1209, idProduct=7d01, bcdDevice= 1.00
[ 7466.483925] usb 1-2.1: New USB device strings: Mfr=3, Product=2, SerialNumber=4
[ 7466.483928] usb 1-2.1: Product: nrf5340dk-app
[ 7466.483931] usb 1-2.1: Manufacturer: RIOT-os.org
[ 7466.483933] usb 1-2.1: SerialNumber: AD0FD4AE806080C2
[ 7466.487010] usb-storage 1-2.1:1.0: USB Mass Storage device detected
[ 7466.487348] scsi host2: usb-storage 1-2.1:1.0
[ 7467.516789] scsi 2:0:0:0: Direct-Access     RIOT-OS  RIOT_MSC_DISK     1.0 PQ: 0 ANSI: 1
[ 7467.517152] sd 2:0:0:0: Attached scsi generic sg3 type 0
[ 7467.517501] sd 2:0:0:0: [sdd] 64 512-byte logical blocks: (32.8 kB/32.0 KiB)
[ 7467.517732] sd 2:0:0:0: [sdd] Write Protect is off
[ 7467.517733] sd 2:0:0:0: [sdd] Mode Sense: 03 00 00 00
[ 7467.517906] sd 2:0:0:0: [sdd] No Caching mode page found
[ 7467.517910] sd 2:0:0:0: [sdd] Assuming drive cache: write through
[ 7467.532159] sd 2:0:0:0: [sdd] Attached SCSI removable disk
```

I also tested `tests/sys/usbus_cdc_ecm` and `tests/sys/usbus/usbus_hid` succesfully.


### Issues/PRs references



Co-authored-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
  • Loading branch information
3 people authored Jul 7, 2023
4 parents 735d371 + 263e993 + 1a92c49 + 3ad31bb commit 8707548
Show file tree
Hide file tree
Showing 22 changed files with 123 additions and 23 deletions.
2 changes: 1 addition & 1 deletion boards/esp32s2-lilygo-ttgo-t8/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ config BOARD_ESP32S2_LILYGO_TTGO_T8
select HAS_SDCARD_SPI
select HAS_TINYUSB_DEVICE
select HAVE_MTD_SDCARD_DEFAULT
select HAVE_ST7735
select HAVE_ST7789
select MODULE_FATFS_VFS if MODULE_VFS_DEFAULT

config FORCE_USB_STDIO
Expand Down
7 changes: 6 additions & 1 deletion boards/esp32s2-lilygo-ttgo-t8/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ ifneq (,$(filter vfs_default,$(USEMODULE)))
endif

ifneq (,$(filter disp_dev,$(USEMODULE)))
USEMODULE += st7735
USEMODULE += st7789
endif

ifneq (,$(filter st7735,$(USEMODULE)))
# use st7789 pseudomodule if st7735 is enabled to indicate that we use a ST7789
USEMODULE += st7789
endif

include $(RIOTBOARD)/common/esp32s2/Makefile.dep
7 changes: 3 additions & 4 deletions boards/esp32s2-lilygo-ttgo-t8/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

## Overview {#esp32s2_lilygo_ttgo_t8_overview}

The Espressif LILYGO TTGO T8 ESP32-S2 is a ESP32-S2 board with an OLED Display
(not yet supported) and a TF Card slot.
The Espressif LILYGO TTGO T8 ESP32-S2 (also known as LilyGo T-Display S2) is
a ESP32-S2 board with an OLED Display and a TF Card slot.

\image html https://ae01.alicdn.com/kf/H8062f551fe7b4233809294d4a5b1d45d1.jpg "LILYGO TTGO T8 ESP32-S2" width=600px

Expand All @@ -39,7 +39,7 @@ ESP32-S2 SoC | yes
8 MB QSPI RAM | yes
SD Card slot | yes
32.768KHz Crystal | yes
OLED display ST77789 | no
OLED display ST77789 | yes

[Back to table of contents](#esp32s2_lilygo_ttgo_t8_toc)

Expand All @@ -49,7 +49,6 @@ This section describes

- the [MCU](#esp32s2_lilygo_ttgo_t8_mcu),
- the default [board configuration](#esp32s2_lilygo_ttgo_t8_board_configuration),
- [optional hardware configurations](#esp32s2_lilygo_ttgo_t8_optional_hardware),
- the [board pinout](#esp32s2_lilygo_ttgo_t8_pinout).

[Back to table of contents](#esp32s2_lilygo_ttgo_t8_toc)
Expand Down
13 changes: 8 additions & 5 deletions boards/esp32s2-lilygo-ttgo-t8/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,19 @@
* @{
*/
#if defined(MODULE_ST7735)
#define ST7735_PARAM_SPI SPI_DEV(1) /**< SPI device */
#define ST7735_PARAM_SPI_CLK SPI_CLK_5MHZ /**< SPI clock frequency */
#define ST7735_PARAM_SPI SPI_DEV(0) /**< SPI device */
#define ST7735_PARAM_SPI_CLK SPI_CLK_10MHZ /**< SPI clock frequency */
#define ST7735_PARAM_SPI_MODE SPI_MODE_0 /**< SPI mode */
#define ST7735_PARAM_CS GPIO34 /**< Chip Select pin */
#define ST7735_PARAM_DCX GPIO37 /**< DCX pin */
#define ST7735_PARAM_RST GPIO38 /**< Reset pin */
#define ST7735_PARAM_RGB 1 /**< RGB mode enable */
#define ST7735_PARAM_INVERTED 0 /**< Inverted mode enable */
#define ST7735_PARAM_NUM_LINES 135U /**< Number of lines */
#define ST7735_PARAM_RGB_CHANNELS 240U /**< Number of columns */
#define ST7735_PARAM_INVERTED 1 /**< Inverted mode enable */
#define ST7735_PARAM_NUM_LINES 240U /**< Number of lines */
#define ST7735_PARAM_RGB_CHANNELS 135U /**< Number of columns */
#define ST7735_PARAM_ROTATION LCD_MADCTL_MY /**< Rotation */
#define ST7735_PARAM_OFFSET_X 40 /**< X offset */
#define ST7735_PARAM_OFFSET_Y 52 /**< Y offset */
#endif
/** @} */

Expand Down
2 changes: 1 addition & 1 deletion boards/esp32s2-lilygo-ttgo-t8/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ extern "C" {
#define SPI0_SCK GPIO36 /**< FSPICLK used as signal `OLED_CLK` */
#endif
#ifndef SPI0_MISO
#define SPI0_MISO GPIO37 /**< FSPIQ used as Display signal `OLED_MISO` */
#define SPI0_MISO GPIO9 /**< FSPIHD dummy (not broken out), GPIO37 is used as DCX */
#endif
#ifndef SPI0_MOSI
#define SPI0_MOSI GPIO35 /**< FSPID used as Display signal `OLED_MOSI` */
Expand Down
2 changes: 2 additions & 0 deletions boards/nrf5340dk-app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ config BOARD_NRF5340DK_APP
bool
default y
select CPU_MODEL_NRF5340_APP
select HAS_PERIPH_RTT
select HAS_PERIPH_TIMER
select HAS_PERIPH_UART
select HAS_PERIPH_UART_HW_FC
select HAS_PERIPH_USBDEV

# Put other features for this board (in alphabetical order)
2 changes: 2 additions & 0 deletions boards/nrf5340dk-app/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ CPU_MODEL = nrf5340_app
CPU = nrf53

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_rtt
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += periph_uart_hw_fc
FEATURES_PROVIDED += periph_usbdev
18 changes: 18 additions & 0 deletions boards/nrf5340dk-app/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ static const uart_conf_t uart_config[] = {
#define UART_NUMOF ARRAY_SIZE(uart_config) /**< UART configuration NUMOF */
/** @} */

/**
* @name Real time counter configuration
* @{
*/
#ifndef RTT_DEV
#define RTT_DEV (0) /**< NRF_RTC0_S */
#endif

#define RTT_MAX_VALUE (0x00ffffff) /**< 24bit */
#define RTT_MAX_FREQUENCY (32768U) /**< in Hz */
#define RTT_MIN_FREQUENCY (8U) /**< in Hz */
#define RTT_CLOCK_FREQUENCY (32768U) /**< in Hz, LFCLK*/

#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1024U) /**< in Hz */
#endif
/** @} */

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions boards/nrf9160dk/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ config BOARD_NRF9160DK
default y
select CPU_MODEL_NRF9160
select HAS_PERIPH_I2C
select HAS_PERIPH_RTT
select HAS_PERIPH_SPI
select HAS_PERIPH_TIMER
select HAS_PERIPH_UART
Expand Down
1 change: 1 addition & 0 deletions boards/nrf9160dk/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CPU = nrf9160

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_rtt
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart
Expand Down
18 changes: 18 additions & 0 deletions boards/nrf9160dk/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ static const uart_conf_t uart_config[] = {
#define UART_NUMOF ARRAY_SIZE(uart_config) /**< UART confgiguration NUMOF */
/** @} */

/**
* @name Real time counter configuration
* @{
*/
#ifndef RTT_DEV
#define RTT_DEV (0) /**< NRF_RTC0_S */
#endif

#define RTT_MAX_VALUE (0x00ffffff) /**< 24bit */
#define RTT_MAX_FREQUENCY (32768U) /**< in Hz */
#define RTT_MIN_FREQUENCY (8U) /**< in Hz */
#define RTT_CLOCK_FREQUENCY (32768U) /**< in Hz, LFCLK*/

#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1024U) /**< in Hz */
#endif
/** @} */

#ifdef __cplusplus
}
#endif
Expand Down
10 changes: 0 additions & 10 deletions cpu/nrf52/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,6 @@ void nrf5x_spi_acquire(NRF_SPIM_Type *bus, spi_twi_irq_cb_t cb, void *arg);
*/
void nrf5x_spi_release(NRF_SPIM_Type *bus);

/**
* @brief USBDEV buffers must be word aligned because of DMA restrictions
*/
#define USBDEV_CPU_DMA_ALIGNMENT (4)

/**
* @brief USBDEV buffer instantiation requirement
*/
#define USBDEV_CPU_DMA_REQUIREMENTS __attribute__((aligned(USBDEV_CPU_DMA_ALIGNMENT)))

#ifdef __cplusplus
}
#endif
Expand Down
7 changes: 7 additions & 0 deletions cpu/nrf53/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ static_assert((CLOCK_CORECLOCK == MHZ(128)) || CLOCK_CORECLOCK == MHZ(64));
/* For now, disable the unused network core */
NRF_RESET_S->NETWORK.FORCEOFF = 1;

#if defined(MODULE_PERIPH_RTT) && (CLOCK_LFCLK==CLOCK_LFCLKSRC_SRC_LFXO)
/* Enable P0.00 and P0.01 as XL1/XL2 if LXFO is selected */
NRF_P0_S->PIN_CNF[0] &= ~GPIO_PIN_CNF_MCUSEL_Msk;
NRF_P0_S->PIN_CNF[0] |= GPIO_PIN_CNF_MCUSEL_Peripheral << GPIO_PIN_CNF_MCUSEL_Pos;
NRF_P0_S->PIN_CNF[1] &= ~GPIO_PIN_CNF_MCUSEL_Msk;
NRF_P0_S->PIN_CNF[1] |= GPIO_PIN_CNF_MCUSEL_Peripheral << GPIO_PIN_CNF_MCUSEL_Pos;
#endif
/* call cortexm default initialization */
cortexm_init();

Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions cpu/nrf5x_common/include/periph_cpu_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ typedef struct {

#endif /* ndef CPU_MODEL_NRF52832XXAA && ndef CPU_FAM_NRF51 */

/**
* @brief USBDEV buffers must be word aligned because of DMA restrictions
*/
#define USBDEV_CPU_DMA_ALIGNMENT (4)

/**
* @brief USBDEV buffer instantiation requirement
*/
#define USBDEV_CPU_DMA_REQUIREMENTS __attribute__((aligned(USBDEV_CPU_DMA_ALIGNMENT)))

#ifdef __cplusplus
}
#endif
Expand Down
14 changes: 14 additions & 0 deletions cpu/nrf5x_common/periph/rtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@
#include "periph/rtt.h"

/* get the IRQ configuration */
#ifdef NRF_RTC0_S
#if (RTT_DEV == 0)
#define DEV NRF_RTC0_S
#define ISR isr_rtc0
#define IRQn RTC0_IRQn
#elif (RTT_DEV == 1)
#define DEV NRF_RTC1_S
#define ISR isr_rtc1
#define IRQn RTC1_IRQn
#else
#error "RTT configuration: invalid or no RTC device specified (RTT_DEV)"
#endif
#else
#if (RTT_DEV == 1)
#define DEV NRF_RTC1
#define ISR isr_rtc1
Expand All @@ -37,6 +50,7 @@
#else
#error "RTT configuration: invalid or no RTC device specified (RTT_DEV)"
#endif
#endif /* def NRF_RTC0_S */

/* allocate memory for callbacks and their args */
static rtt_cb_t alarm_cb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
#define ENABLE_DEBUG 0
#include "debug.h"

/* Compatibility wrapper for nRF53 */
#ifdef NRF_USBD_S
#define NRF_USBD NRF_USBD_S
#endif

static nrfusb_t _usbdevs[NRF_USB_NUM_PERIPH];

static void _init(usbdev_t *usbdev);
Expand Down
4 changes: 4 additions & 0 deletions drivers/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ ifneq (,$(filter stmpe811_%,$(USEMODULE)))
USEMODULE += stmpe811
endif

ifneq (,$(filter st7789,$(USEMODULE)))
USEMODULE += st7735
endif

ifneq (,$(filter sx126%,$(USEMODULE)))
USEMODULE += sx126x
endif
Expand Down
4 changes: 4 additions & 0 deletions drivers/include/st7735.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
* when strictly necessary. This option will slow down the driver as it
* certainly can't use DMA anymore, every short has to be converted before
* transfer.
*
* @note The driver can also be used for the ST7789 which is compatible with
* the ST7735 but supports higher resolutions. Just enable the module
* `st7789` instead of `st7735` if your board uses the ST7789.
*/


Expand Down
10 changes: 10 additions & 0 deletions drivers/st7735/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ config HAVE_ST7735
help
Indicates that an ST7735 display is present.

config MODULE_ST7789
bool "ST7789 display driver"
select MODULE_ST7735

config HAVE_ST7789
bool
select MODULE_ST7789 if MODULE_DISP_DEV
help
Indicates that an ST7789 display is present.

menuconfig KCONFIG_USEMODULE_ST7735
bool "Configure ST7735 driver"
depends on USEMODULE_ST7735
Expand Down
2 changes: 2 additions & 0 deletions drivers/st7735/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
PSEUDOMODULES += st7789

USEMODULE_INCLUDES_st7735 := $(LAST_MAKEFILEDIR)/include
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_st7735)
7 changes: 6 additions & 1 deletion drivers/st7735/st7735.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ static uint8_t _st7735_calc_vml(int16_t vcoml)

static int _init(lcd_t *dev, const lcd_params_t *params)
{
assert(params->lines <= 162);
if (IS_USED(MODULE_ST7789)) {
assert(params->lines <= 320);
}
else {
assert(params->lines <= 162);
}
dev->params = params;
uint8_t command_params[4] = { 0 };

Expand Down

0 comments on commit 8707548

Please sign in to comment.