Hi All,
Simply put I am trying to use the Xiao BLE Sense board connected to the Expansion board (with SD card slot) to write audio recorded data from the Xiao embedded PDM microphone to the microSD card.
Development setup:
HW: Apple M2 Ultra (silicon), Xiao BLE Sense (mbed) with 14 header pins soldered by me (appear functional), Xiao Expansion Board, SanDisk Ultra PLUS 64 GB microSD card, USB-C to USB-C cord connecting Xiao Sense to desktop system (cord good condition)
OS: Darwin arm64 23.6.0 (macOS Sonoma 14.6.1)
SW: VS Code 1.98.2, nRF Connect SDK v2.7.0 (not the most recent I know), toolchain 1.5.3
Description of issue:
I am working to access a microSD card formatted with fatfs (FAT 32) filesystem (64 GB capacity) but have been unable to initialize the card (see error log and screenshot below).
I have used the above configuration (Xiao Sense + Expansion board + inserted SD card) and successfully run the "CardInfo.ino" code example in the Arduino environment. From this I assume that the microSD card is usable, formatted correctly (using desktop setup described below), and power/voltage is correct.
There are other Arduino examples accessing/reading/writing an SD card but I have not tried these.
What I want to do is to create a codebase in which I can access (including initialize, open/close, read/write, and de-initialize) an SD card but everything done in the NRF Connect/Zephyr OS environment if at all possible.
I used the nRF Connect "blinky" sample to create the skeleton build configuration for the Xiao Sense and of course this compiled, assembled, linked, and executed as expected. Per multiple tutorials I simply copy the .uf2 file to the Xiao Sense to flash it to the nrf52840. I kept this Blink/LED code in the program to have evidence that the program flashed correctly.
To build the SD functionality I used the fat_fs.c code from the most recent nRF Connect sample and incorporated it into the "blinky" sample (see attached file). I would like to try to access the SD card through SPI (using the disk driver API with the SDMMC subsystem working transparently underneath).
However, when I flash this revised code I receive an error at the if (disk_access_init(disk_pdrv) != 0) {...} system call:
I have tried multiple configurations to solve the problem.
1. rechecked connections and power including that the microSD card is inserted into the SD card slot at all times/power stable to device/card throughout process as this is an fat system
2. tried suggestions from several nRF Connect Forum posts including this one without luck: https://devzone.nordicsemi.com/f/nordic-q-a/109575/xiao-ble-sense-round-display---zephyr-microsd
3. contacted the OP of the post from 2. as they report having resolved an identical (?) issue but I have not received a response
4. in prj.conf I have tried all 4 SPI interfaces (SPI0 through SPI3) though I am under the impression that SPI0 and SPI3 are preferred for SPI (note I am currently using SPI2 but I have received the same error mentioned above in initializing the SD card using all 4 interfaces.
5. I have added the "zephyr,sdmmc-disk" device tree node to each of the SPI interfaces to no avail
6. Adding CONFIG_NFCT_PINS_AS_GPIOS=y to prj.conf but this did not affect the error (got same error)
7. Seeed Studio (maker of Xiao board) Forum has not been helpful (extensive search through posts)
8. tried various filesystems (by enabled in prf.conf) including ext2 and littlefs but there does not seem to be a way to do this at this point
9. considered using NVMe but trying to use PCIe would seem to complicate this situation more
10. considered emulated block device of flash partition support (I assume this means the 2 MB onboard nRF25840 SoC flash) but I need to record/write to SD at least 3 MB of data (approximately 3 minutes of audio data) so this does not seem adequate (though it would be very cool to know how to do this). Of note, I did retain the msc_disk0 device note information (from here: https://docs.nordicsemi.com/bundle/ncs-2.4.3/page/zephyr/services/storage/disk/access.html#disk-access-api) in my overlay file but I am assuming this should not interfere with the spi2 DT configuration.
My related questions are:
* how does the SD host controller figure into this process and am I missing something in the configuration to enable this?
* how to use direct block level access (meaning using DMA?) to the SD card/is this possible as an alternative to using SPI?
* do I need to make changes to yaml and/or .json files in order to enable SD functionality for this board and/or create custom board support for the Xiao?
Any help would be greatly appreciated. If it is known that the Xiao BLE Sense (mbed) board simply cannot be used in the nRF Connect/Zephyr environment to interact with an SD card this would very helpful to know as well (but it seems as if there must be some way to do this). I have the generated VS Code support information .jsonc file that I can send to Nordic staff if that is helpful.
Kind Regards,
Rick
Lastly (in a very long post I know), I tried a somewhat different approach/version of main.c/other codebase (attached below) adapted from a different source but in this case I get a timeout error (errno 116) trying to communicate with the SD card. The main.c, prj.conf, and overlay files for this build are below as well.