Can't access SDCard via SPI on Wisblock RAK4631

Hi,

I'm using a custom code I developed to save all console logs to an SD card based on the Zephyr architecture. I originally developed it for the Thingy:52 and have also used it successfully on the nRF52 DK and nRF52840 DK boards.

Recently, I tried running it on the WisBlock RAK4631, but it didn’t work. I tried several fixes, but none of them solved the issue. At first, I attempted to use the available pins on the WisBlock, but none of them worked. Then, I tried soldering the four SD pins to the QSPI pins on the pinout (P0.03, P0.30, P0.29, P0.26), since I found somewhere that these pins could also be configured for SPI.

Here’s the code I tried:

"sd_card.c"

#include "sd_card.h"

LOG_MODULE_REGISTER(SD_CARD, LOG_LEVEL_INF);

FATFS fatfs;

static struct fs_mount_t fatfs_mnt = {
    .type = FS_FATFS,
    .mnt_point = MOUNT_POINT,
    .fs_data = &fatfs,
};

void init_sd_card() {
    static const char *disk_pdrv = "SD";
    uint64_t memory_size_mb;
    uint32_t block_count;
    uint32_t block_size;

    uint32_t err = disk_access_init(disk_pdrv);
    if (err != 0) {
        LOG_ERR("Storage init Error! %d", err);
        k_sleep(K_MSEC(REBOOT_INTERVAL));
        sys_reboot(SYS_REBOOT_COLD);
    }

    if (disk_access_ioctl(disk_pdrv, DISK_IOCTL_GET_SECTOR_COUNT, &block_count)) {
        LOG_ERR("Unable to get sector count");
        k_sleep(K_MSEC(REBOOT_INTERVAL));
        sys_reboot(SYS_REBOOT_COLD);
    }

    if (disk_access_ioctl(disk_pdrv, DISK_IOCTL_GET_SECTOR_SIZE, &block_size)) {
        LOG_ERR("Unable to get sector size");
        k_sleep(K_MSEC(REBOOT_INTERVAL));
        sys_reboot(SYS_REBOOT_COLD);
    }

    memory_size_mb = (uint64_t)block_count * block_size;
    LOG_INF("Memory Size %uMB", (uint32_t)(memory_size_mb >> 20));

    int res = fs_mount(&fatfs_mnt);

    if (res == FR_OK) {
        LOG_INF("Disk mounted");
    } else {
        LOG_ERR("Error mounting disk (E: %i)", res);
        k_sleep(K_MSEC(REBOOT_INTERVAL));
        sys_reboot(SYS_REBOOT_COLD);
    }
}
"sd_card.h"
#ifndef SD_CARD_H
#define SD_CARD_H

#include <zephyr/storage/disk_access.h>
#include <zephyr/logging/log.h>
#include <zephyr/logging/log_backend.h>
#include <zephyr/fs/fs.h>
#include <zephyr/sys/reboot.h>
#include <ff.h>

#define MOUNT_POINT "/SD:"          ///< Mount point for the SD card
#define REBOOT_INTERVAL (2 * 1000)  ///< Delay before reboot (ms)

extern FATFS fatfs;             ///< File system object for the SD card


/**
 * @brief Initializes the SD Card functionality.
 *
 * This function verifies if the SD Card device is ready for operation.
 * If the device is not ready or some error occours in mouting, an error
 * is logged, and the system reboots after a short delay defined by REBOOT_INTERVAL.
 *
 * If the device is ready, a confirmation message is logged.
 *
 * @return void This function does not return a value.
 */
void init_sd_card();

#endif // SD_CARD_H


"main.c"

#include "sd_card.h"

LOG_MODULE_REGISTER(MAIN, LOG_LEVEL_INF);
int main() {
    LOG_INF("Running on board: %s", CONFIG_BOARD);
    k_sleep(K_SECONDS(2));
    init_sd_card();
    LOG_INF("Test Application Started");

    return 0;
}
"proj.conf"
CONFIG_I2C=n
CONFIG_LOG=y

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_MAIN_STACK_SIZE=2048          

CONFIG_REBOOT=y          

CONFIG_MULTITHREADING=y      

CONFIG_VOLTAGE_DIVIDER=y        
CONFIG_ADC=y                        

CONFIG_DISK_ACCESS=y                        
CONFIG_FILE_SYSTEM=y                        
CONFIG_FAT_FILESYSTEM_ELM=y                
CONFIG_LOG_BACKEND_FS=y                    
CONFIG_LOG_BACKEND_FS_OUTPUT_TEXT=y        
CONFIG_LOG_BACKEND_FS_DIR="/SD:"            
CONFIG_LOG_BACKEND_FS_FILE_PREFIX="log"    
CONFIG_LOG_BACKEND_FS_FILES_LIMIT=512      
CONFIG_LOG_BACKEND_FS_FILE_SIZE=8388608    
CONFIG_LOG_BACKEND_FS_OVERWRITE=y          

If you could help me figure out what might be wrong or suggest how to make it work on the RAK4631, I’d be very grateful.

Related