This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Reading SD card on nRF9160dk

Hello,

I want to read two files from SD card using nRF9160dk. I tried this code ncs/zephyr/samples/subsys/fs/fat_fs.

The Code:

/*
 * Copyright (c) 2019 Tavish Naruka <[email protected]>
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/* Sample which uses the filesystem API and SDHC driver */

#include <zephyr.h>
#include <device.h>
#include <disk/disk_access.h>
#include <logging/log.h>
#include <fs/fs.h>
#include <ff.h>

LOG_MODULE_REGISTER(main);

static int lsdir(const char *path);

static FATFS fat_fs;
/* mounting info */
static struct fs_mount_t mp = {
	.type = FS_FATFS,
	.fs_data = &fat_fs,
};

/*
*  Note the fatfs library is able to mount only strings inside _VOLUME_STRS
*  in ffconf.h
*/
static const char *disk_mount_pt = "/SD:";

void main(void)
{
	/* raw disk i/o */
	do {
		static const char *disk_pdrv = "SD";
		u64_t memory_size_mb;
		u32_t block_count;
		u32_t block_size;

		if (disk_access_init(disk_pdrv) != 0) {
			LOG_ERR("Storage init ERROR!");
			break;
		}

		if (disk_access_ioctl(disk_pdrv,
				DISK_IOCTL_GET_SECTOR_COUNT, &block_count)) {
			LOG_ERR("Unable to get sector count");
			break;
		}
		LOG_INF("Block count %u", block_count);

		if (disk_access_ioctl(disk_pdrv,
				DISK_IOCTL_GET_SECTOR_SIZE, &block_size)) {
			LOG_ERR("Unable to get sector size");
			break;
		}
		printk("Sector size %u\n", block_size);

		memory_size_mb = (u64_t)block_count * block_size;
		printk("Memory Size(MB) %u\n", (u32_t)memory_size_mb>>20);
	} while (0);

	mp.mnt_point = disk_mount_pt;

	int res = fs_mount(&mp);

	if (res == FR_OK) {
		printk("Disk mounted.\n");
		lsdir(disk_mount_pt);
	} else {
		printk("Error mounting disk.\n");
	}

	while (1) {
		k_sleep(1000);
	}
}

static int lsdir(const char *path)
{
	int res;
	struct fs_dir_t dirp;
	static struct fs_dirent entry;

	/* Verify fs_opendir() */
	res = fs_opendir(&dirp, path);
	if (res) {
		printk("Error opening dir %s [%d]\n", path, res);
		return res;
	}

	printk("\nListing dir %s ...\n", path);
	for (;;) {
		/* Verify fs_readdir() */
		res = fs_readdir(&dirp, &entry);

		/* entry.name[0] == 0 means end-of-dir */
		if (res || entry.name[0] == 0) {
			break;
		}

		if (entry.type == FS_DIR_ENTRY_DIR) {
			printk("[DIR ] %s\n", entry.name);
		} else {
			printk("[FILE] %s (size = %zu)\n",
				entry.name, entry.size);
		}
	}

	/* Verify fs_closedir() */
	fs_closedir(&dirp);

	return res;
}

I am getting the following error:

***** Booting Zephyr OS build v1.14.99-ncs3-snapshot2-2647-gd6e67554cfeb *****
[00:00:00.024,078] <inf> spi_nrfx_spim: CS control inhibited (no GPIO device)
[00:00:05.039,306] <err> main: Storage init ERROR!
Error mounting disk.
[00:00:10.054,565] <err> fs: fs mount error (-5)

nrf9160_pca10090ns.overlay:

/*
 * Copyright (c) 2019 Tavish Naruka <[email protected]>
 *
 * SPDX-License-Identifier: Apache-2.0
 */

&spi3 {
        status = "okay";
        cs-gpios = <&gpio0 16 0>;

        sdhc0: sdhc@0 {
                compatible = "zephyr,mmc-spi-slot";
                reg = <0>;
                status = "okay";
                label = "SDHC0";
                spi-max-frequency = <24000000>;
        };
};

&spi3 {
        status = "okay";
        sck-pin = <19>;
        mosi-pin = <18>;
        miso-pin = <17>;
};

I checked the voltage levels at SPI_3 pins. Pin 16, 17, 18 shows 3V but 19 which is SCK is at 0V. I am not understanding why it is at 0V.

Why there is error? What else I need to do?

Parents
  • Hello, 

    What version of NCS are you using? 

    Kind regards,
    Øyvind

  • The error while opening the SES

    Loading solution mqtt_uart_gnss.emProject
    Executing load commands
    cmake -GNinja -DBOARD=nrf9160_pca10090ns -DBOARD_DIR=C:/ncs/zephyr/boards/arm/nrf9160_pca10090 -DZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb -DGNUARMEMB_TOOLCHAIN_PATH=C:/gnuarmemb -BC:/ncs/nrf/samples/jagruti_codes/mqtt_uart_gnss/build_nrf9160_pca10090ns -HC:/ncs/nrf/samples/jagruti_codes/mqtt_uart_gnss -DDTC_OVERLAY_FILE=C:/ncs/nrf/samples/jagruti_codes/mqtt_uart_gnss/nrf9160_pca10090ns.overlay -DEXTRA_KCONFIG_TARGETS=menuconfig_ses -DEXTRA_KCONFIG_TARGET_COMMAND_FOR_menuconfig_ses=D:/nRF9160-DK/EmbeddedStudio_ARM_Nordic_v420a_win_x64/arm_segger_embedded_studio_v420a_win_x64_nordic/html/configure_nordic_project_menuconfig.py
    -- Using application from 'C:/ncs/nrf/samples/jagruti_codes/mqtt_uart_gnss'
    Zephyr version: 2.0.99
    -- Selected BOARD nrf9160_pca10090ns
    -- Found west: C:/Python37/Scripts/west.exe (found suitable version "0.6.2", minimum required is "0.6.0")
    CMake Error at C:/ncs/zephyr/cmake/zephyr_module.cmake:45 (message):
      validation.invalid
    
       --- All found errors ---
    
      ["Cannot find required key 'build'.  Path: ''", "Key 'samples' was not
      defined.  Path: ''"]
    
      ERROR: Malformed "build" section in file:
      C:/ncs/bootloader/mcuboot\zephyr/module.yml
    
      <SchemaError: error code 2: Schema validation failed:
    
       - Cannot find required key 'build'. Path: ''.
       - Key 'samples' was not defined. Path: ''.: Path: '/'>
    
    Call Stack (most recent call first):
      C:/ncs/zephyr/cmake/app/boilerplate.cmake:251 (include)
      CMakeLists.txt:10 (include)
    
    
    -- Configuring incomplete, errors occurred!
    See also "C:/ncs/nrf/samples/jagruti_codes/mqtt_uart_gnss/build_nrf9160_pca10090ns/CMakeFiles/CMakeOutput.log".
    See also "C:/ncs/nrf/samples/jagruti_codes/mqtt_uart_gnss/build_nrf9160_pca10090ns/CMakeFiles/CMakeError.log".
    Project load failed
    Reported error: solution load command failed (1)
    

  • Did you remember to run west update after git checkout v1.1.0? 

    If so, please provide the following:
    "C:/ncs/nrf/samples/jagruti_codes/mqtt_uart_gnss/build_nrf9160_pca10090ns/CMakeFiles/CMakeOutput.log".
    "C:/ncs/nrf/samples/jagruti_codes/mqtt_uart_gnss/build_nrf9160_pca10090ns/CMakeFiles/CMakeError.log".

  • Also, is there a reason for why you did not try git stash when you did git checkout v1.2.0? Be aware that a lot of bug fixes are included in the latest version

  • Hi,

    SES is working properly with ncs tag v1.2.0

    I tried few samples and it is working fine.

    But the error is same as v1.0.0

    *** Booting Zephyr OS build v2.1.99-ncs1  ***
    [00:00:00.004,211] <inf> spi_nrfx_spim: CS control inhibited (no GPIO device)
    [00:00:05.006,469] <err> main: Storage init ERROR!
    Error mounting disk.
    [00:00:10.008,789] <err> fs: fs mount error (-5)

    Why it always shows CS control inhibited (no GPIO device)? It means CS pin is not getting configured. I have defined the pin in overlay file.

  • One more thing is, this example is written for nrf52840_blip board. But I want to use fatfs library for nrf9160dk. 

    In the zephyr documentation it is written;

    This sample can be built for an nrf52840_blip board. It requires both the nrf52840_blip.overlay and the dts_fixup.h for nrf52840_blip to work:
    So that's why I added nrf9160_pca10090ns.overlay for the project and removed nrf52840_blip.overlay file

    But I think the C Code should remain same as it is using FATFS library.

    Is it ok to use this code and FATFS library for nrf9160dk? Are there any changes required to use it on nrf9160dk?

Reply
  • One more thing is, this example is written for nrf52840_blip board. But I want to use fatfs library for nrf9160dk. 

    In the zephyr documentation it is written;

    This sample can be built for an nrf52840_blip board. It requires both the nrf52840_blip.overlay and the dts_fixup.h for nrf52840_blip to work:
    So that's why I added nrf9160_pca10090ns.overlay for the project and removed nrf52840_blip.overlay file

    But I think the C Code should remain same as it is using FATFS library.

    Is it ok to use this code and FATFS library for nrf9160dk? Are there any changes required to use it on nrf9160dk?

Children
Related