Dear DevZone,
I am trying to integrate the fatfs example in my custom FW project, to be run on a custom board.
I first tried to upload only the fatfs example code on my custom board. I used a 2GB micro-SD card and I was able to successfully run the example (Nordic.txt file was correctly generated)
Then, I tried to integrate the example in my custom FW project. To do this, I followed the usual steps, such as including all files and directories to the project, and configuring the SPI parameters as they are set in the fatfs example, such as SPI pins, SPI instances (in my custom code I am using 1 while in the fatfs example the 0 is used, but even changing to 0 it does not work).
The code correctly builds. However, when I try to run it in debug, what happens is that the disk initialization fails.
NRF_LOG_INFO("Initializing disk 0 (SDC)...");
for (uint32_t retries = 3; retries && disk_state; --retries)
{
disk_state = disk_initialize(0);
}
if (disk_state)
{
NRF_LOG_INFO("Disk initialization failed.");
return;
}
Going inside the disk_initialize function during debug, what I find is that usually neither
/* Unsupported block size. */
/* SDC instance is busy. */
errors are reported (see the code snippet below)
static ret_code_t block_dev_sdc_init(nrf_block_dev_t const * p_blk_dev, nrf_block_dev_ev_handler ev_handler, void const * p_context) { ASSERT(p_blk_dev); nrf_block_dev_sdc_t const * p_sdc_dev = CONTAINER_OF(p_blk_dev, nrf_block_dev_sdc_t, block_dev); nrf_block_dev_sdc_work_t * p_work = p_sdc_dev->p_work; if (p_sdc_dev->sdc_bdev_config.block_size != SDC_SECTOR_SIZE) { /* Unsupported block size. */ return NRF_ERROR_NOT_SUPPORTED; } if (m_active_sdc_dev) { /* SDC instance is busy. */ return NRF_ERROR_BUSY; } p_work->p_context = p_context; p_work->ev_handler = ev_handler; m_active_sdc_dev = p_sdc_dev; ret_code_t err_code = NRF_SUCCESS; err_code = app_sdc_init(&p_sdc_dev->sdc_bdev_config.sdc_config, sdc_handler); if (err_code == NRF_SUCCESS) {
What do you think can be the issue?
Note that in the board I share the SPI buses with other 2 slaves, but for the first tests I am not using them: I commented out the old SPI initialization function and I put the fatfs example call before everything related to other SPI devices in the main.
(In other words, I know that from https://devzone.nordicsemi.com/f/nordic-q-a/63517/interfacing-between-nrf52840-and-bme680-i2c-or-spi/258966#258966 the sharing of SPI buses between SD card and other slaves is not suggested, but: 1) for the time being this should not be the cause of the issue since I commented out everything related to other slaves , 2) in a second moment I will have to deal with this sharing since at this point the HW cannot be changed )
Thank you very much in advance,
best regards,
Gianluca