Skip to content

Commit

Permalink
stm32h7/linum-stm32h753bi: Add support to littlefs and nxffs with fla…
Browse files Browse the repository at this point in the history
…sh mem. via quadspi

Signed-off-by: Jorge Guzman <[email protected]>
  • Loading branch information
JorgeGzm authored and xiaoxiang781216 committed Apr 15, 2024
1 parent 81c8f90 commit 5e3cbd1
Show file tree
Hide file tree
Showing 11 changed files with 370 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,4 +551,42 @@ Transmiting a file to PC::
If you don't have a SDCard on your board, you can mount the TMPFS at /tmp and transfer files to it,
but you cannot transfer big files because TMPFS could use the free RAM of your board::

nsh> mount -t tmpfs /tmp
nsh> mount -t tmpfs /tmp

nxffs
-----
This example use the flash memory W25Q128JV via qspi with the nxffs file system::

NuttShell (NSH) NuttX-12.5.1-RC0
nsh> ls
/:
dev/
w25/
nsh> cd /w25
nsh> echo "hello world!" > message.txt
nsh> ls
/w25:
message.txt
nsh> cat message.txt
hello world!

littlefs
--------
This example use the flash memory W25Q128JV via qspi with the littlefs file system::

NuttShell (NSH) NuttX-12.5.1-RC0
nsh> ls
/:
dev/
w25/
nsh> cd /w25
nsh> mkdir folder1
nsh> cd folder1
nsh> echo "hello world!!!!" > message.txt
nsh> cat message.txt
hello world!!!!
nsh> ls
/w25/folder1:
.
..
message.txt
8 changes: 4 additions & 4 deletions arch/arm/src/stm32h7/stm32_qspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1851,7 +1851,7 @@ static uint32_t qspi_setfrequency(struct qspi_dev_s *dev, uint32_t frequency)
return 0;
}

spiinfo("frequency=%d\n", frequency);
spiinfo("frequency=%" PRId32 "\n", frequency);
DEBUGASSERT(priv);

/* Wait till BUSY flag reset */
Expand Down Expand Up @@ -1905,14 +1905,14 @@ static uint32_t qspi_setfrequency(struct qspi_dev_s *dev, uint32_t frequency)
/* Calculate the new actual frequency */

actual = QSPI_CLK_FREQUENCY / prescaler;
spiinfo("prescaler=%d actual=%d\n", prescaler, actual);
spiinfo("prescaler=%" PRId32 " actual=%" PRId32 "\n", prescaler, actual);

/* Save the frequency setting */

priv->frequency = frequency;
priv->actual = actual;

spiinfo("Frequency %d->%d\n", frequency, actual);
spiinfo("Frequency %" PRId32 "->%" PRId32 "\n", frequency, actual);
return actual;
}

Expand Down Expand Up @@ -1983,7 +1983,7 @@ static void qspi_setmode(struct qspi_dev_s *dev, enum qspi_mode_e mode)
}

qspi_putreg(priv, regval, STM32_QUADSPI_DCR_OFFSET);
spiinfo("DCR=%08x\n", regval);
spiinfo("DCR=%08" PRIx32 "\n", regval);

/* Save the mode so that subsequent re-configurations will be faster */

Expand Down
69 changes: 69 additions & 0 deletions boards/arm/stm32h7/linum-stm32h753bi/configs/littlefs/defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#
# 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_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_NSH_QUOTE is not set
# CONFIG_STANDARD_SERIAL is not set
# CONFIG_STM32H7_USE_LEGACY_PINMAP is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="linum-stm32h753bi"
CONFIG_ARCH_BOARD_LINUM_STM32H753BI=y
CONFIG_ARCH_CHIP="stm32h7"
CONFIG_ARCH_CHIP_STM32H753BI=y
CONFIG_ARCH_CHIP_STM32H7=y
CONFIG_ARCH_CHIP_STM32H7_CORTEXM7=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARMV7M_DCACHE=y
CONFIG_ARMV7M_DCACHE_WRITETHROUGH=y
CONFIG_ARMV7M_DTCM=y
CONFIG_ARMV7M_ICACHE=y
CONFIG_BOARD_LOOPSPERMSEC=43103
CONFIG_BUILTIN=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEFAULT_TASK_STACKSIZE=4096
CONFIG_EXAMPLES_ALARM=y
CONFIG_EXAMPLES_ALARM_STACKSIZE=2048
CONFIG_FS_LITTLEFS=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBM=y
CONFIG_MM_DEFAULT_ALIGNMENT=4
CONFIG_MM_REGIONS=4
CONFIG_MTD=y
CONFIG_MTD_W25QXXXJV=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE=2048
CONFIG_PREALLOC_TIMERS=4
CONFIG_PTHREAD_STACK_DEFAULT=2048
CONFIG_RAMMTD=y
CONFIG_RAM_SIZE=245760
CONFIG_RAM_START=0x20010000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_RTC_ALARM=y
CONFIG_RTC_DATETIME=y
CONFIG_RTC_DRIVER=y
CONFIG_SCHED_WAITPID=y
CONFIG_SPI=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2011
CONFIG_STM32H7_PWR=y
CONFIG_STM32H7_QSPI_INTERRUPTS=y
CONFIG_STM32H7_QUADSPI=y
CONFIG_STM32H7_RTC=y
CONFIG_STM32H7_USART1=y
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_NSH_STACKSIZE=2048
CONFIG_TASK_NAME_SIZE=0
CONFIG_USART1_SERIAL_CONSOLE=y
CONFIG_W25QXXXJV_QSPI_FREQUENCY=50000000
66 changes: 66 additions & 0 deletions boards/arm/stm32h7/linum-stm32h753bi/configs/nxffs/defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#
# 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_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_NSH_QUOTE is not set
# CONFIG_STANDARD_SERIAL is not set
# CONFIG_STM32H7_USE_LEGACY_PINMAP is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="linum-stm32h753bi"
CONFIG_ARCH_BOARD_LINUM_STM32H753BI=y
CONFIG_ARCH_CHIP="stm32h7"
CONFIG_ARCH_CHIP_STM32H753BI=y
CONFIG_ARCH_CHIP_STM32H7=y
CONFIG_ARCH_CHIP_STM32H7_CORTEXM7=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARMV7M_DCACHE=y
CONFIG_ARMV7M_DCACHE_WRITETHROUGH=y
CONFIG_ARMV7M_DTCM=y
CONFIG_ARMV7M_ICACHE=y
CONFIG_BOARD_LOOPSPERMSEC=43103
CONFIG_BUILTIN=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_EXAMPLES_ALARM=y
CONFIG_FS_NXFFS=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBM=y
CONFIG_MM_DEFAULT_ALIGNMENT=4
CONFIG_MM_REGIONS=4
CONFIG_MTD=y
CONFIG_MTD_W25QXXXJV=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAMMTD=y
CONFIG_RAM_SIZE=245760
CONFIG_RAM_START=0x20010000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_RTC_ALARM=y
CONFIG_RTC_DATETIME=y
CONFIG_RTC_DRIVER=y
CONFIG_SCHED_WAITPID=y
CONFIG_SPI=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2011
CONFIG_STM32H7_PWR=y
CONFIG_STM32H7_QSPI_INTERRUPTS=y
CONFIG_STM32H7_QUADSPI=y
CONFIG_STM32H7_RTC=y
CONFIG_STM32H7_USART1=y
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_TESTING_NXFFS=y
CONFIG_TESTING_NXFFS_MOUNTPT="/mnt"
CONFIG_USART1_SERIAL_CONSOLE=y
CONFIG_W25QXXXJV_QSPI_FREQUENCY=50000000
16 changes: 14 additions & 2 deletions boards/arm/stm32h7/linum-stm32h753bi/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@

/* OTGFS */

#define GPIO_OTGFS_DM (GPIO_OTGFS_DM_0 | GPIO_SPEED_100MHz)
#define GPIO_OTGFS_DP (GPIO_OTGFS_DP_0 | GPIO_SPEED_100MHz)
#define GPIO_OTGFS_DM (GPIO_OTGFS_DM_0 | GPIO_SPEED_100MHz) /* PA11 */
#define GPIO_OTGFS_DP (GPIO_OTGFS_DP_0 | GPIO_SPEED_100MHz) /* PA12 */

/* SDMMC1 - Used SD Card memory */

Expand Down Expand Up @@ -411,6 +411,18 @@
#define GPIO_CAN2_RX (GPIO_CAN2_RX_2|GPIO_SPEED_50MHz) /* PB5 - D11 */
#define GPIO_CAN2_TX (GPIO_CAN2_TX_2|GPIO_SPEED_50MHz) /* PB6 - D1 */

/* QSPI Mapping */

#define GPIO_QSPI_CS (GPIO_QUADSPI_BK1_NCS_2 | GPIO_FLOAT | GPIO_PUSHPULL | GPIO_SPEED_100MHz) /* PG6 */
#define GPIO_QSPI_IO0 (GPIO_QUADSPI_BK1_IO0_1 | GPIO_FLOAT | GPIO_PUSHPULL | GPIO_SPEED_100MHz) /* PF8 */
#define GPIO_QSPI_IO1 (GPIO_QUADSPI_BK1_IO1_1 | GPIO_FLOAT | GPIO_PUSHPULL | GPIO_SPEED_100MHz) /* PF9 */
#define GPIO_QSPI_IO2 (GPIO_QUADSPI_BK1_IO2_2 | GPIO_FLOAT | GPIO_PUSHPULL | GPIO_SPEED_100MHz) /* PF7 */
#define GPIO_QSPI_IO3 (GPIO_QUADSPI_BK1_IO3_3 | GPIO_FLOAT | GPIO_PUSHPULL | GPIO_SPEED_100MHz) /* PF6 */
#define GPIO_QSPI_SCK (GPIO_QUADSPI_CLK_2 | GPIO_FLOAT | GPIO_PUSHPULL | GPIO_SPEED_100MHz) /* PF10 */

/* Select PLL2R to source clock of QSPI */
#define BOARD_QSPI_CLK RCC_D1CCIPR_QSPISEL_PLL2

/****************************************************************************
* Public Data
****************************************************************************/
Expand Down
4 changes: 4 additions & 0 deletions boards/arm/stm32h7/linum-stm32h753bi/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ if(CONFIG_PWM)
list(APPEND SRCS stm32_pwm.c)
endif()

if(CONFIG_MTD_W25QXXXJV)
list(APPEND SRCS stm32_w25q.c)
endif()

target_sources(board PRIVATE ${SRCS})

set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")
12 changes: 8 additions & 4 deletions boards/arm/stm32h7/linum-stm32h753bi/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ CSRCS = stm32_boot.c stm32_bringup.c

ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += stm32_autoleds.c
endif

ifeq ($(CONFIG_USERLED),y)
CSRCS += stm32_userleds.c
else
ifeq ($(CONFIG_USERLED),y)
CSRCS += stm32_userleds.c
endif
endif

ifeq ($(CONFIG_STM32H7_OTGFS),y)
Expand All @@ -50,6 +50,10 @@ ifeq ($(CONFIG_PWM),y)
CSRCS += stm32_pwm.c
endif

ifeq ($(CONFIG_MTD_W25QXXXJV),y)
CSRCS += stm32_w25q.c
endif

ifeq ($(CONFIG_BOARDCTL),y)
CSRCS += stm32_appinitialize.c
endif
Expand Down
17 changes: 14 additions & 3 deletions boards/arm/stm32h7/linum-stm32h753bi/src/linum-stm32h753bi.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void weak_function stm32_usbinitialize(void);
* Name: stm32_dma_alloc_init
*
* Description:
* Called to create a FAT DMA allocator
* Called to create a FAT DMA allocator.
*
* Returned Value:
* 0 on success or -ENOMEM
Expand All @@ -156,7 +156,7 @@ int stm32_dma_alloc_init(void);
* Name: stm32_sdio_initialize
*
* Description:
* Initialize SDIO-based MMC/SD card support
* Initialize SDIO-based MMC/SD card support.
*
****************************************************************************/

Expand All @@ -168,7 +168,7 @@ int stm32_sdio_initialize(void);
* Name: stm32_at24_init
*
* Description:
* Initialize and register the EEPROM for 24XX driver.
* Initialize and register the EEPROM for 24XX driver.
*
****************************************************************************/

Expand All @@ -187,5 +187,16 @@ int stm32_at24_init(char *path);
#ifdef CONFIG_PWM
int stm32_pwm_setup(void);
#endif
/****************************************************************************
* Name: stm32_n25qxxx_setup
*
* Description:
* Initialize and register the FLash for N25QXXX driver.
*
****************************************************************************/

#ifdef CONFIG_MTD_W25QXXXJV
int stm32_w25qxxx_setup(void);
#endif

#endif /* __BOARDS_ARM_STM32H7_LINUM_STM32H753BI_SRC_LINUM_STM32H753BI_H */
8 changes: 8 additions & 0 deletions boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ int stm32_bringup(void)
stm32_fdcansockinitialize(1);
# endif

#endif

#ifdef CONFIG_MTD_W25QXXXJV
ret = stm32_w25qxxx_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_n25qxxx_setup failed: %d\n", ret);
}
#endif

return OK;
Expand Down
Loading

0 comments on commit 5e3cbd1

Please sign in to comment.