From fdbba517a26d444b03ee26979e0bc65d1d0cdc07 Mon Sep 17 00:00:00 2001 From: Dylan Laduranty Date: Wed, 5 Jul 2023 15:35:59 +0200 Subject: [PATCH] boards/nrf5340dk-app: add SPI flash configuration and I2C pins Signed-off-by: Dylan Laduranty --- boards/nrf5340dk-app/Kconfig | 4 ++ boards/nrf5340dk-app/Makefile.dep | 9 ++++ boards/nrf5340dk-app/board.c | 58 ++++++++++++++++++++++ boards/nrf5340dk-app/include/board.h | 14 ++++++ boards/nrf5340dk-app/include/periph_conf.h | 15 ++++++ cpu/nrf52/periph/Kconfig | 10 ---- cpu/nrf53/Kconfig | 3 -- cpu/nrf5x_common/periph/Kconfig.nrf5x | 10 ++++ 8 files changed, 110 insertions(+), 13 deletions(-) create mode 100644 boards/nrf5340dk-app/Makefile.dep create mode 100644 boards/nrf5340dk-app/board.c diff --git a/boards/nrf5340dk-app/Kconfig b/boards/nrf5340dk-app/Kconfig index a5b742e0c0..8c5adbc127 100644 --- a/boards/nrf5340dk-app/Kconfig +++ b/boards/nrf5340dk-app/Kconfig @@ -11,11 +11,15 @@ config BOARD_NRF5340DK_APP bool default y select CPU_MODEL_NRF5340_APP + select HAS_PERIPH_I2C + select HAS_PERIPH_SPI + select HAS_PERIPH_SPI_GPIO_MODE select HAS_PERIPH_PWM select HAS_PERIPH_RTT select HAS_PERIPH_TIMER select HAS_PERIPH_UART select HAS_PERIPH_UART_HW_FC select HAS_PERIPH_USBDEV + select HAVE_MTD_SPI_NOR # Put other features for this board (in alphabetical order) diff --git a/boards/nrf5340dk-app/Makefile.dep b/boards/nrf5340dk-app/Makefile.dep new file mode 100644 index 0000000000..04b4d6fa69 --- /dev/null +++ b/boards/nrf5340dk-app/Makefile.dep @@ -0,0 +1,9 @@ +ifneq (,$(filter mtd,$(USEMODULE))) + USEMODULE += mtd_spi_nor +endif + +# default to using littlefs2 on the external flash +ifneq (,$(filter vfs_default,$(USEMODULE))) + USEPKG += littlefs2 + USEMODULE += mtd +endif diff --git a/boards/nrf5340dk-app/board.c b/boards/nrf5340dk-app/board.c new file mode 100644 index 0000000000..ff530addc6 --- /dev/null +++ b/boards/nrf5340dk-app/board.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2023 Mesotic SAS + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_nrf5340dk-app + * @{ + * + * @file + * @brief Board specific implementations for the Nordic nRF5340DK board + * + * @author Dylan Laduranty + * @} + */ + +#include "board.h" +#include "periph/gpio.h" +#include "timex.h" +#ifdef MODULE_VFS_DEFAULT +#include "vfs_default.h" +#endif + +#ifdef MODULE_MTD_SPI_NOR +#include "mtd_spi_nor.h" +/* MX25R64 */ +static const mtd_spi_nor_params_t _nrf5340_nor_params = { + .opcode = &mtd_spi_nor_opcode_default, + .wait_chip_erase = 240 * US_PER_SEC, + .wait_64k_erase = 800 * US_PER_MS, + .wait_sector_erase = 240 * US_PER_MS, + .wait_chip_wake_up = 1 * US_PER_MS, + .clk = MHZ(54), + .flag = SPI_NOR_F_SECT_4K | SPI_NOR_F_SECT_64K, + .spi = SPI_DEV(0), + .mode = SPI_MODE_0, + .cs = BOARD_QSPI_PIN_CS, + .wp = BOARD_QSPI_PIN_WP, + .hold = BOARD_QSPI_PIN_HOLD, +}; + +static mtd_spi_nor_t nrf5340_nor_dev = { + .base = { + .driver = &mtd_spi_nor_driver, + .page_size = 256, + .pages_per_sector = 16, + }, + .params = &_nrf5340_nor_params, +}; +mtd_dev_t *mtd0 = (mtd_dev_t *)&nrf5340_nor_dev; + +#ifdef MODULE_VFS_DEFAULT +VFS_AUTO_MOUNT(littlefs2, VFS_MTD(nrf5340_nor_dev), VFS_DEFAULT_NVM(0), 0); +#endif +#endif /* MODULE_MTD_SPI_NOR */ diff --git a/boards/nrf5340dk-app/include/board.h b/boards/nrf5340dk-app/include/board.h index 199b25182e..82917b7147 100644 --- a/boards/nrf5340dk-app/include/board.h +++ b/boards/nrf5340dk-app/include/board.h @@ -20,6 +20,7 @@ #define BOARD_H #include "cpu.h" +#include "mtd.h" #ifdef __cplusplus extern "C" { @@ -95,6 +96,19 @@ extern "C" { #define BTN3_MODE GPIO_IN_PU /**< BTN3 default mode */ /** @} */ +/** + * @name MTD configuration + * @{ + */ +extern mtd_dev_t *mtd0; +#define MTD_0 mtd0 +#define MTD_NUMOF 1 + +#define BOARD_QSPI_PIN_CS GPIO_PIN(0, 18) /**< SPI Flash Chip Select */ +#define BOARD_QSPI_PIN_WP GPIO_PIN(0, 15) /**< SPI Flash Write Protect */ +#define BOARD_QSPI_PIN_HOLD GPIO_PIN(0, 16) /**< SPI Flash Hold pin */ +/** @} */ + #ifdef __cplusplus } #endif diff --git a/boards/nrf5340dk-app/include/periph_conf.h b/boards/nrf5340dk-app/include/periph_conf.h index 1ad21b7c46..a4810e10f3 100644 --- a/boards/nrf5340dk-app/include/periph_conf.h +++ b/boards/nrf5340dk-app/include/periph_conf.h @@ -126,6 +126,21 @@ static const spi_conf_t spi_config[] = { #define SPI_NUMOF ARRAY_SIZE(spi_config) /** @} */ +/** + * * @name I2C configuration + * * @{ + * */ +static const i2c_conf_t i2c_config[] = { + { + .dev = NRF_TWIM2_S, + .scl = GPIO_PIN(1, 3), + .sda = GPIO_PIN(1, 2), + .speed = I2C_SPEED_NORMAL + } +}; +#define I2C_NUMOF ARRAY_SIZE(i2c_config) +/** @} */ + #ifdef __cplusplus } #endif diff --git a/cpu/nrf52/periph/Kconfig b/cpu/nrf52/periph/Kconfig index ff272d7b69..eed36b152b 100644 --- a/cpu/nrf52/periph/Kconfig +++ b/cpu/nrf52/periph/Kconfig @@ -7,16 +7,6 @@ if TEST_KCONFIG -config MODULE_PERIPH_UART_NONBLOCKING - depends on HAS_PERIPH_UART_NONBLOCKING - depends on MODULE_PERIPH_UART - select MODULE_TSRB - -config MODULE_PERIPH_SPI - depends on HAS_PERIPH_SPI - select MODULE_PERIPH_GPIO_IRQ if CPU_MODEL_NRF52832XXAA && HAS_PERIPH_GPIO_IRQ - select MODULE_PERIPH_SPI_GPIO_MODE if MODULE_PERIPH_SPI && HAS_PERIPH_SPI_GPIO_MODE - config MODULE_SAUL_NRF_VDDH bool "Internal Voltage Sensor" depends on HAS_PERIPH_ADC diff --git a/cpu/nrf53/Kconfig b/cpu/nrf53/Kconfig index 944daf3ff1..be2cb9fee2 100644 --- a/cpu/nrf53/Kconfig +++ b/cpu/nrf53/Kconfig @@ -15,9 +15,6 @@ config CPU_FAM_NRF53 select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_GPIO select HAS_PERIPH_GPIO_IRQ - select HAS_PERIPH_I2C - select HAS_PERIPH_SPI - select HAS_PERIPH_SPI_GPIO_MODE select HAS_PERIPH_TIMER_PERIODIC select HAS_PERIPH_UART_MODECFG select HAS_PERIPH_WDT diff --git a/cpu/nrf5x_common/periph/Kconfig.nrf5x b/cpu/nrf5x_common/periph/Kconfig.nrf5x index ea65976bbe..3e14ab97f1 100644 --- a/cpu/nrf5x_common/periph/Kconfig.nrf5x +++ b/cpu/nrf5x_common/periph/Kconfig.nrf5x @@ -33,4 +33,14 @@ config MODULE_VDD_LC_FILTER_REG1 help Use the LC filter attached to the CPUs voltage regulator +config MODULE_PERIPH_UART_NONBLOCKING + depends on HAS_PERIPH_UART_NONBLOCKING + depends on MODULE_PERIPH_UART + select MODULE_TSRB + +config MODULE_PERIPH_SPI + depends on HAS_PERIPH_SPI + select MODULE_PERIPH_GPIO_IRQ if CPU_MODEL_NRF52832XXAA && HAS_PERIPH_GPIO_IRQ + select MODULE_PERIPH_SPI_GPIO_MODE if MODULE_PERIPH_SPI && HAS_PERIPH_SPI_GPIO_MODE + endif # TEST_KCONFIG