software: ncs 2.5.0, zephyr/samples/subsys/fs/fs_sample
hardware: nRF52840 (not DK, designed by customer) and nRF52832 (not DK, designed by customer)
Step1: build within nRF52840
prj.conf like this:
CONFIG_DISK_ACCESS=y
CONFIG_LOG=y
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_PRINTK=y
CONFIG_MAIN_STACK_SIZE=2048
overlay file like this:
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
/* Because FAT FS needs at least 64kiB partition and default
* storage_partition is 32kiB for that board, we need to reorgatnize
* partitions to get at least 64KiB.
* This overlay removes image slot partitions and strips each of 64kiB,
* and removes the storage partition to add the additional 2*64kiB to
* it.
*/
/delete-node/ &slot0_partition;
/delete-node/ &slot1_partition;
/delete-node/ &storage_partition;
&flash0 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
slot0_partition: partition@c000 {
reg = <0x0000C000 0x00066000>; // 408 KiB
};
slot1_partition: partition@72000 {
reg = <0x00072000 0x00066000>; // 408 KiB
};
storage_partition: partition@d8000 {
label = "storage";
reg = <0x000d8000 0x00028000>; // 160 KiB
};
};
};
/ {
msc_disk0 {
status="okay";
compatible = "zephyr,flash-disk";
partition = <&storage_partition>;
disk-name = "SD";
/* cache-size == page erase size */
cache-size = <4096>;
};
};
download and run uart console output like this:
*** Booting nRF Connect SDK v2.5.0 *** [00:00:00.774,841] <inf> flashdisk: Initialize device SD [00:00:00.774,841] <inf> flashdisk: offset d8000, sector size 512, page size 4096, volume size 163840 [00:00:00.774,963] <inf> main: Block count 320 Sector size 512 Memory Size(MB) 0 [00:00:00.775,054] <inf> flashdisk: Initialize device SD [00:00:00.775,085] <inf> flashdisk: offset d8000, sector size 512, page size 4096, volume size 163840 Disk mounted. Listing dir /SD: ... [FILE] SOME.DAT (size = 0) [DIR ] SOME
it seems very good, but not my sd card functions.
Step2: build with nRF52832
prj.conf like this(same with nRF52840):
CONFIG_DISK_ACCESS=y CONFIG_LOG=y CONFIG_FILE_SYSTEM=y CONFIG_FAT_FILESYSTEM_ELM=y CONFIG_PRINTK=y CONFIG_MAIN_STACK_SIZE=2048
there is no overlay file.
download and run uart console output error like this:
*** Booting nRF Connect SDK v2.5.0 *** [00:00:00.265,777] <err> main: Storage init ERROR! [00:00:00.265,808] <err> fs: fs mount error (-5) Error mounting disk. [00:00:00.265,838] <err> fs: fs not mounted (mp == 0x20000000)
add overlay file like this(also errors like above):
/delete-node/ &slot0_partition;
/delete-node/ &slot1_partition;
/delete-node/ &storage_partition;
&flash0 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
slot0_partition: partition@0 {
reg = <0x00000000 0x00140000>; // 80 KiB
};
slot1_partition: partition@140000 {
reg = <0x00140000 0x00140000>; // 80 KiB
};
storage_partition: partition@280000 {
label = "storage";
reg = <0x00280000 0x00014000>; // 80 KiB
};
};
};
/{
msc_disk0 {
status = "okay";
compatible = "zephyr,flash-disk";
partition = <&storage_partition>;
disk-name = "SD";
cache-size = <4096>;
};
};
Step2: build with nRF52832 (do as this)
prj.conf like this(add some CONFIG):
CONFIG_DISK_ACCESS=y CONFIG_LOG=y CONFIG_FILE_SYSTEM=y CONFIG_FAT_FILESYSTEM_ELM=y CONFIG_PRINTK=y CONFIG_MAIN_STACK_SIZE=2048 CONFIG_DISK_DRIVER_SDMMC=y CONFIG_SPI=y # SD CONFIG_MMC_STACK=y CONFIG_SD_LOG_LEVEL_DEFAULT=y CONFIG_SPI_NRFX_RAM_BUFFER_SIZE=8 CONFIG_SDHC=y CONFIG_SDHC_LOG_LEVEL_DEFAULT=y CONFIG_NRFX_SPI1=y
overlay file like this:
/ {
pinctrl: pin-controller
{
compatible = "nordic,nrf-pinctrl";
spi1_default: spi1_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 2)>,
<NRF_PSEL(SPIM_MOSI, 0, 4)>,
<NRF_PSEL(SPIM_MISO, 0, 28)>;
};
};
spi1_sleep: spi1_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 2)>,
<NRF_PSEL(SPIM_MOSI, 0, 4)>,
<NRF_PSEL(SPIM_MISO, 0, 28)>;
low-power-enable;
};
};
};
};
&spi1 {
status = "okay";
cs-gpios = < &gpio0 3 GPIO_ACTIVE_LOW>;
sdhc-spi-slot@0 {
compatible = "zephyr,sdhc-spi-slot";
reg = <0x0 >;
spi-max-frequency = <8000000>;
status = "okay";
mmc {
compatible = "zephyr,sdmmc-disk";
status = "okay";
};
};
};
download and run uart console output like this(SUCCESS access SD card):
*** Booting nRF Connect SDK v2.5.0 *** [00:00:00.610,870] <inf> sd: Maximum SD clock is under 25MHz, using clock of 8000000Hz [00:00:00.611,907] <inf> main: Block count 15597568 Sector size 512 Memory Size(MB) 7616 Disk mounted. Listing dir /SD: ... [DIR ] NAVISOFT [DIR ] LOST.DIR [DIR ] SOUNDS [DIR ] ANDROID [FILE] NORDIC.TXT (size = 32)
the DIR is my SD card's DIR, it is very good for me. But I build for nRF52840, only change the SD card pins, overlay like this:
/ {
pinctrl: pin-controller
{
compatible = "nordic,nrf-pinctrl";
spi1_default: spi1_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 23)>,
<NRF_PSEL(SPIM_MOSI, 0, 20)>,
<NRF_PSEL(SPIM_MISO, 0, 21)>;
};
};
spi1_sleep: spi1_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 23)>,
<NRF_PSEL(SPIM_MOSI, 0, 20)>,
<NRF_PSEL(SPIM_MISO, 0, 21)>;
low-power-enable;
};
};
};
};
&spi1 {
status = "okay";
cs-gpios = < &gpio0 19 GPIO_ACTIVE_LOW>;
sdhc-spi-slot@0 {
compatible = "zephyr,sdhc-spi-slot";
reg = <0x0 >;
spi-max-frequency = <24000000>;
status = "okay";
mmc {
compatible = "zephyr,sdmmc-disk";
status = "okay";
};
};
};
but download and run uart console output error like this (same error like this):
*** Booting nRF Connect SDK v2.5.0 *** [00:00:01.026,214] <err> spi_nrfx_spi: Timeout waiting for transfer complete [00:00:01.026,245] <err> sdhc_spi: Card SCLK init sequence failed [00:00:01.026,275] <err> sd: Could not disable card power via SDHC [00:00:01.026,275] <err> main: 1 - Storage init ERROR! [00:00:01.227,508] <err> spi_nrfx_spi: Timeout waiting for transfer complete [00:00:01.227,539] <err> sdhc_spi: Card SCLK init sequence failed [00:00:01.227,539] <err> sd: Could not disable card power via SDHC [00:00:01.227,569] <err> fs: fs mount error (-5) Error mounting disk. [00:00:01.227,600] <err> fs: fs not mounted (mp == 0x20000000)
Question:
how can I change prj.conf and overlay file for nRF52840 access SD card? thanks.