diff --git a/boards/arm/nrf52/nrf52840-dk/configs/qspi/defconfig b/boards/arm/nrf52/nrf52840-dk/configs/qspi/defconfig new file mode 100644 index 0000000000..3de3258fa1 --- /dev/null +++ b/boards/arm/nrf52/nrf52840-dk/configs/qspi/defconfig @@ -0,0 +1,45 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_ARCH_FPU is not set +# CONFIG_NSH_DISABLE_IFCONFIG is not set +# CONFIG_NSH_DISABLE_PS is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="nrf52840-dk" +CONFIG_ARCH_BOARD_NRF52840_DK=y +CONFIG_ARCH_CHIP="nrf52" +CONFIG_ARCH_CHIP_NRF52840=y +CONFIG_ARCH_CHIP_NRF52=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_STDARG_H=y +CONFIG_BOARD_LOOPSPERMSEC=5500 +CONFIG_DEBUG_SYMBOLS=y +CONFIG_FS_LITTLEFS=y +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=4098 +CONFIG_MM_REGIONS=2 +CONFIG_MTD=y +CONFIG_MTD_MX25RXX=y +CONFIG_NRF52_QSPI=y +CONFIG_NRF52_UART0=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=65535 +CONFIG_RAM_START=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=26 +CONFIG_START_MONTH=3 +CONFIG_SYMTAB_ORDEREDBYNAME=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 +CONFIG_UART0_SERIAL_CONSOLE=y diff --git a/boards/arm/nrf52/nrf52840-dk/include/board.h b/boards/arm/nrf52/nrf52840-dk/include/board.h index a2f6321580..d8ea193c88 100644 --- a/boards/arm/nrf52/nrf52840-dk/include/board.h +++ b/boards/arm/nrf52/nrf52840-dk/include/board.h @@ -165,4 +165,22 @@ #define NRF52_ADC_CH2_PIN (GPIO_INPUT | GPIO_PORT0 | GPIO_PIN(28)) #define NRF52_ADC_CH3_PIN (GPIO_INPUT | GPIO_PORT0 | GPIO_PIN(29)) +/* QSPI Pins ****************************************************************/ + +/* QSPI0 + * QSPI CS - P0.17 + * QSPI SCK - P0.19 + * QSPI IO0 - P0.20 + * QSPI IO1 - P0.21 + * QSPI IO2 - P0.22 + * QSPI IO3 - P0.23 + */ + +#define NRF52_QSPI0_CSN_PIN (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | GPIO_PIN(17)) +#define NRF52_QSPI0_SCK_PIN (GPIO_OUTPUT | GPIO_PORT0 | GPIO_PIN(19)) +#define NRF52_QSPI0_IO0_PIN (GPIO_OUTPUT | GPIO_PORT0 | GPIO_PIN(20)) +#define NRF52_QSPI0_IO1_PIN (GPIO_OUTPUT | GPIO_PORT0 | GPIO_PIN(21)) +#define NRF52_QSPI0_IO2_PIN (GPIO_OUTPUT | GPIO_PORT0 | GPIO_PIN(22)) +#define NRF52_QSPI0_IO3_PIN (GPIO_OUTPUT | GPIO_PORT0 | GPIO_PIN(23)) + #endif /* __BOARDS_ARM_NRF52_NRF52840_DK_INCLUDE_BOARD_H */ diff --git a/boards/arm/nrf52/nrf52840-dk/src/Makefile b/boards/arm/nrf52/nrf52840-dk/src/Makefile index b741feda23..dffc657f4c 100644 --- a/boards/arm/nrf52/nrf52840-dk/src/Makefile +++ b/boards/arm/nrf52/nrf52840-dk/src/Makefile @@ -82,4 +82,8 @@ ifeq ($(CONFIG_USBDEV_COMPOSITE),y) CSRCS += nrf52_composite.c endif +ifeq ($(CONFIG_NRF52_QSPI),y) +CSRCS += nrf52_mx25.c +endif + include $(TOPDIR)/boards/Board.mk diff --git a/boards/arm/nrf52/nrf52840-dk/src/nrf52840-dk.h b/boards/arm/nrf52/nrf52840-dk/src/nrf52840-dk.h index a64c217985..db9095a494 100644 --- a/boards/arm/nrf52/nrf52840-dk/src/nrf52840-dk.h +++ b/boards/arm/nrf52/nrf52840-dk/src/nrf52840-dk.h @@ -201,5 +201,17 @@ int nrf52_pwm_setup(void); int nrf52_adc_setup(void); #endif +/**************************************************************************** + * Name: nrf52_mx25_initialize + * + * Description: + * Initialize the MX25RXX QSPI memeory + * + ****************************************************************************/ + +#ifdef CONFIG_NRF52_QSPI +int nrf52_mx25_initialize(void); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __BOARDS_ARM_NRF52_NRF52840_DK_SRC_NRF52840_DK_H */ diff --git a/boards/arm/nrf52/nrf52840-dk/src/nrf52_bringup.c b/boards/arm/nrf52/nrf52840-dk/src/nrf52_bringup.c index d8ca297ec5..38257d68ce 100644 --- a/boards/arm/nrf52/nrf52840-dk/src/nrf52_bringup.c +++ b/boards/arm/nrf52/nrf52840-dk/src/nrf52_bringup.c @@ -261,9 +261,18 @@ int nrf52_bringup(void) usbdev_rndis_initialize(mac); #endif +#ifdef CONFIG_NRF52_QSPI + /* Initialize the MX25 QSPU memory */ + + ret = nrf52_mx25_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: nrf52_mx25_initialize() failed: %d\n", ret); + } +#endif + #ifdef CONFIG_NRF52_SOFTDEVICE_CONTROLLER ret = nrf52_sdc_initialize(); - if (ret < 0) { syslog(LOG_ERR, "ERROR: nrf52_sdc_initialize() failed: %d\n", ret); diff --git a/boards/arm/nrf52/nrf52840-dk/src/nrf52_mx25.c b/boards/arm/nrf52/nrf52840-dk/src/nrf52_mx25.c new file mode 100644 index 0000000000..14e5399851 --- /dev/null +++ b/boards/arm/nrf52/nrf52840-dk/src/nrf52_mx25.c @@ -0,0 +1,107 @@ +/**************************************************************************** + * boards/arm/nrf52/nrf52840-dk/src/nrf52_mx25.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include + +#include "nrf52_qspi.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf52_mx25_initialize + * + * Description: + * Initialize the MX25RXX QSPI memeory + * + ****************************************************************************/ + +int nrf52_mx25_initialize(void) +{ + struct qspi_dev_s *qspi_dev; + struct mtd_dev_s *mtd_dev; + char blockdev[32]; + int ret = -1; + + /* Create an instance of the NRF52 QSPI device driver */ + + qspi_dev = nrf52_qspi_initialize(0); + if (!qspi_dev) + { + _err("nrf52_qspi_initialize() failed\n"); + return -1; + } + + _info("nrf52_qspi_initialize() successful\n"); + + /* Use the QSPI device instance to initialize the MX25 device */ + + mtd_dev = mx25rxx_initialize(qspi_dev, true); + if (!mtd_dev) + { + _err("mx25rxx_initialize() failed\n"); + return -1; + } + + /* Configure the device with no partition support */ + + snprintf(blockdev, sizeof(blockdev), "/dev/mtdqspi%d", 0); + + ret = register_mtddriver(blockdev, mtd_dev, 0755, NULL); + if (ret != OK) + { + _err("register_mtddriver() failed: %d\n", ret); + return -1; + } + + _info("register_mtddriver() successful\n"); + +#ifdef CONFIG_FS_LITTLEFS + ret = nx_mount(blockdev, "/mnt/qspi", "littlefs", 0, NULL); + if (ret < 0) + { + ret = nx_mount(blockdev, "/mnt/qspi", "littlefs", 0, + "forceformat"); + if (ret < 0) + { + _err("nx_mount() failed: %d\n", ret); + } + else + { + _info("nx_mount() successful\n"); + } + } +#endif + + return ret; +}