Hello. I want to use microSD card mounted in my device tree overlay on SPI3 as "zephyr,mmc-spi-slot" instead of onboard NOR flash for full modem firmware update. Hovewer, during FMFU initialization in function call tree:
Hello. I want to use microSD card mounted in my device tree overlay on SPI3 as "zephyr,mmc-spi-slot" instead of onboard NOR flash for full modem firmware update. Hovewer, during FMFU initialization in function call tree:
Hi,
Do you plan to download the new modem images via the nRF9160, or is the idea that the user will place the image on the SD card themselves?
I don't think you can use the SD card directly with the dfu_target or fmfu_fdev libraries, as they assume you can access a random part of the flash directly, rather than having to read it in blocks. The libraries also don't account for any file system, so that might also cause problems.
However, you should be able to use the full modem update API directly from the modem library, where the application handles reading (and writing if necessary) from the SD card itself.
See the documentation here for how to perform a full modem update.
Best regards,
Didrik
Idea in that there is no spi NOR flash on my board, but it is only on nRF9160DK board. On my board there is only SD card. The aim is to make Zephyr consider a single file on sd card as an external flash where it can write/read FMFU binary file, using as buffer.
Now I written a driver code with implemented flash_driver_api functionality. This driver writes and read in a single opened file on FAT formatted SD card. However, my driver is not initialized by Zephyr, I dont know how exactly to add it to device tree overlay file. To spi3? Or to sdhc0: sdhc@0, which I put to spi3? How to make Zephyr see and initialize my driver?
You will probably have to write a bindings file, so that you can define your own device tree node.
That way, the device tree node can be tied to your flash driver, so that Zephyr knows that it should initialize it.
You can read more about how it is done here:
https://iwasz.pl/electronics/2021-06-18-out-of-tree-zephyr-module.md/
https://github.com/martelmy/NCS_examples/tree/main/devicetree/devicetree_custom_device
Yes, I just created it "my,file-flash-drive.yaml" , but how to tell build system where to search for this file?
description: | Raw flash storage emulation based on a single file in FAT-FS formatted SD card compatible: "my,file-flash-drive" include: ["base.yaml"]
list(APPEND DTS_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src/file_flash_drive) list(APPEND EXTRA_ZEPHYR_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/src/file_flash_drive)
dev = device_get_binding(DT_LABEL(DT_INST(0, my_file_flash_drive)));
/ { file-flash-drive { compatible = "my,file-flash-drive"; status = "okay"; }; };
UPD: I make it recognizable by Zephyr, however, I found that fatfs is initialized later than my driver. My driver has priority
But fs system is defined inside of SDK as
What level (e.g. POST_KERNEL, APPLICATION) is your driver initialized at?
Do you need your driver to be initialized that early, or can you initialize it after the fatfs driver?
To initialize it after the fatfs driver, you can set the level to POST_KERNEL and the priority to something higher than CONFIG_KERNEL_INIT_PRIORITY_DEFAULT (the default value for this symbol is 40. Note that you cannot write an expression, so you cannot use e.g. "CONFIG_KERNEL_INIT_PRIORITY_DEFAULT + 1").
Otherwise, you will have to change the fatfs driver to be initialized earlier, but that might cause problems if it depends on other drivers or features that haven't been initialized at that point. The easiest will be to change the initialization level and priority of your driver.
Thanks for mentioning priorities. I set my driver's level and priority to APPLICATION and CONFIG_KERNEL_INIT_PRIORITY_DEVICE, and its worked.
Also I had to set SPI frequency to 4 MHz and add at the beginning of my driver init() function:
gpio_dev_ptr = device_get_binding("GPIO_0"); gpio_flags_t flags = GPIO_PULL_UP|GPIO_OUTPUT|GPIO_DS_ALT_HIGH|GPIO_DS_ALT_LOW; gpio_pin_configure(gpio_dev_ptr, SPI_SCK_PIN, flags); gpio_pin_configure(gpio_dev_ptr, SPI_MOSI_PIN, flags);
However, fs_mount returns -5, (f_mount returns -13). After some debugging with logic analyzer and oscilloscope I found that the f_mkfs() returns 0, but during f_mount() which is called after f_mkfs(), the received 512 bytes of data are all zeros. I think its incorrect, dont know why there are all zeros instead of first sector data for FAT32. I use 32GB microSD SDHC Class 10 card inserted to "Nordic internal debugging interface" after small SMD additions to it (added pullup resistors to VCC, disconnect card's DAT2 and connect CMD to its pad on the PCB, and also changed dts file accordingly. The card can communicate, and return correct nonzero CRC, can receive commands and send command execution status codes, but the data of the first 512 bytes is 0 after formatting.
Here is the logic diagram of first 512 byte sector reading during f_mkfs:
Thanks for mentioning priorities. I set my driver's level and priority to APPLICATION and CONFIG_KERNEL_INIT_PRIORITY_DEVICE, and its worked.
Also I had to set SPI frequency to 4 MHz and add at the beginning of my driver init() function:
gpio_dev_ptr = device_get_binding("GPIO_0"); gpio_flags_t flags = GPIO_PULL_UP|GPIO_OUTPUT|GPIO_DS_ALT_HIGH|GPIO_DS_ALT_LOW; gpio_pin_configure(gpio_dev_ptr, SPI_SCK_PIN, flags); gpio_pin_configure(gpio_dev_ptr, SPI_MOSI_PIN, flags);
However, fs_mount returns -5, (f_mount returns -13). After some debugging with logic analyzer and oscilloscope I found that the f_mkfs() returns 0, but during f_mount() which is called after f_mkfs(), the received 512 bytes of data are all zeros. I think its incorrect, dont know why there are all zeros instead of first sector data for FAT32. I use 32GB microSD SDHC Class 10 card inserted to "Nordic internal debugging interface" after small SMD additions to it (added pullup resistors to VCC, disconnect card's DAT2 and connect CMD to its pad on the PCB, and also changed dts file accordingly. The card can communicate, and return correct nonzero CRC, can receive commands and send command execution status codes, but the data of the first 512 bytes is 0 after formatting.
Here is the logic diagram of first 512 byte sector reading during f_mkfs:
UPD: This was a hardware issue. I didnt switch SW9 on my DK, which selects between 1.8V and 3V for logic voltage which also used to power SD card. For SD card 1.8V is not sufficient, so after I switched it to 3V, everything become ok. You can close issue. Thanks!