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

Enabling SD Card in asset_tracker V1

Hi

I am trying to get the SDHC/Disk access with FAT working on the nRF9160 dev platform and Asset_Tracker V1 app

It is shown to be connected on the TRACE connector

so P0.21 to P0.25 and the DBG_CMD going to U1B pin 125 if soldered

So I have bought the correct socket and soldered it down

I am only using the 9140 for this

In the config I turn on SDHC

and I have tried the following code added to the asset_tracker v1 app

#include <fs/fs.h>
#include <ff.h>
#include <disk/disk_access.h>

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

static const char *disk_mount_pt = "/SD:";

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;
}

static void init_disk(void)
{
    /* raw disk i/o */
    do {
            static const char *disk_pdrv = "SD";
            uint64_t memory_size_mb;
            uint32_t block_count;
            uint32_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 = (uint64_t)block_count * block_size;
            printk("Memory Size(MB) %u\n", (uint32_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");
    }
}

void main(void)
{
	LOG_INF("Asset tracker started");
	k_work_q_start(&application_work_q, application_stack_area,
		       K_THREAD_STACK_SIZEOF(application_stack_area),
		       CONFIG_APPLICATION_WORKQUEUE_PRIORITY);
	if (IS_ENABLED(CONFIG_WATCHDOG)) {
		watchdog_init_and_start(&application_work_q);
	}

#if defined(CONFIG_USE_UI_MODULE)
	ui_init(ui_evt_handler);
#endif

#if defined(CONFIG_LWM2M_CARRIER)
	k_sem_take(&nrf_modem_lib_initialized, K_FOREVER);
#else
	handle_nrf_modem_lib_init_ret();
#endif


//TRY THE DISK
  init_disk();

	cloud_api_init();

	work_init();
	
	............

But I have no luck.

Do I also need to configure a SPI port in hal_nordic? and specify the pins in use somewhere?

Is there a working example of the SDCard socket being used anywhere that I can refer to?

Parents Reply Children
No Data
Related