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

nRF9160 DK: Logging to external memory

Hey,

I noticed that in the SDK v1.6.0 a Kconfig option CONFIG_LOG_BACKEND_FS was added. However, I cannot find any information on how to use it.

I would like to be able to store the logs on an SD-card/memory chip on the nRF9160 DK (v.1.0.2). I tried simply adding the config and it's requirements to the Zephyr littlefs sample but I couldn't get it to work. Is there some additional things I need to change? Or a sample that is easy to try it on?

Also the Kconfig help states that it uses LittleFS, but is it possible to use another filesystem such as FAT? It would be easier to export the data to a Windows machine for analyzing. On this Zephyr PR it is stated that it will support any FS that is supported by VFS API. So I assume it could be possible. If it is possible, does it automatically use the FS that was configured, despite the Kconfig information only mentioning LittleFS?

Thanks in advance!

Parents
  • It does not seem like there are any samples that demonstrates how to use this feature. However, it's made a test for it here: https://github.com/nrfconnect/sdk-zephyr/tree/0944459b5b622048a08ad1f8cf8a044c135fd0d3/tests/subsys/logging/log_backend_fs

    This should give you an idea how to enable LittleFS backend logging in your sample

    Don't overlook these files:

    Add similar files for your board (nrf9160dk_nrf9160ns I guess?) in your sample as well

    If you don't get it to work, please let me know and I will try to get it working myself.

    Best regards,

    Simon

  • Hey Simon,

    I tried the test, but I couldn't get it to work. I am able to build and run it but mounting the filesystem fails:

    *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
    Running test suite test_log_backend_fs
    ===================================================================
    START - test_fs_nonexist
     Assertion failed at ../src/log_fs_test.c:47: test_fs_nonexist: (rc not equal to 0)
     Can not mount FS.
     FAIL - test_fs_nonexist in 0.10 seconds
     ===================================================================
     START - test_wipe_fs_logs
     PASS - test_wipe_fs_logs in 0.1 seconds
     ===================================================================
     START - test_log_fs_file_content
     Assertion failed at ../src/log_fs_test.c:103: test_log_fs_file_content: (fs_open(&file, fname, FS_O_READ) not equal to 0)
     Can not open log file.
     FAIL - test_log_fs_file_content in 0.14 seconds
     ===================================================================
     START - test_log_fs_file_size
     Assertion failed at ../src/log_fs_test.c:145: test_log_fs_file_size: (fs_stat(fname, &entry) not equal to 0)
     Can not get file info. 
     FAIL - test_log_fs_file_size in 0.13 seconds
     ===================================================================
     START - test_log_fs_files_max
     Assertion failed at ../src/log_fs_test.c:212: test_log_fs_files_max: (rc not equal to 0)
     Can not open directory. 
     FAIL - test_log_fs_files_max in 0.12 seconds
     ===================================================================
     Test suite test_log_backend_fs failed.
     ===================================================================
    PROJECT EXECUTION FAILED

    I made .conf and .overlay files for nrf9160dk: nrf9160dk_nrf9160ns.conf, 4743.nrf9160dk_nrf9160ns.overlay

    Is there something wrong with these? Or is there something I need to change in the code? I needed to add the MX25R64 in the overlay because it is not included in the common.dts file.

Reply
  • Hey Simon,

    I tried the test, but I couldn't get it to work. I am able to build and run it but mounting the filesystem fails:

    *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
    Running test suite test_log_backend_fs
    ===================================================================
    START - test_fs_nonexist
     Assertion failed at ../src/log_fs_test.c:47: test_fs_nonexist: (rc not equal to 0)
     Can not mount FS.
     FAIL - test_fs_nonexist in 0.10 seconds
     ===================================================================
     START - test_wipe_fs_logs
     PASS - test_wipe_fs_logs in 0.1 seconds
     ===================================================================
     START - test_log_fs_file_content
     Assertion failed at ../src/log_fs_test.c:103: test_log_fs_file_content: (fs_open(&file, fname, FS_O_READ) not equal to 0)
     Can not open log file.
     FAIL - test_log_fs_file_content in 0.14 seconds
     ===================================================================
     START - test_log_fs_file_size
     Assertion failed at ../src/log_fs_test.c:145: test_log_fs_file_size: (fs_stat(fname, &entry) not equal to 0)
     Can not get file info. 
     FAIL - test_log_fs_file_size in 0.13 seconds
     ===================================================================
     START - test_log_fs_files_max
     Assertion failed at ../src/log_fs_test.c:212: test_log_fs_files_max: (rc not equal to 0)
     Can not open directory. 
     FAIL - test_log_fs_files_max in 0.12 seconds
     ===================================================================
     Test suite test_log_backend_fs failed.
     ===================================================================
    PROJECT EXECUTION FAILED

    I made .conf and .overlay files for nrf9160dk: nrf9160dk_nrf9160ns.conf, 4743.nrf9160dk_nrf9160ns.overlay

    Is there something wrong with these? Or is there something I need to change in the code? I needed to add the MX25R64 in the overlay because it is not included in the common.dts file.

Children
  • Update on this:

    I realised I have to route the flash chip to the nRF9160. I followed this thread to do so. I also realised there is an overlay for newer DK's so I removed the spi3 configurations from the "nrf9160dk_nrf9160ns.overlay" file, because I get them when I build it for the new revision.

    However, I am still not able to get it to work.

    I also tested Zephyr's littlefs sample, and it fails to mount the flash as well:

    *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
    Area 0 at 0x0 on MX25R64 for 65536 bytes
    FAIL: mount id 0 at /lfs1: -19
    [00:00:00.252,563] [1B][0m<inf> littlefs: littlefs partition at /lfs1[1B][0m
    [00:00:00.260,620] [1B][0m<inf> littlefs: LittleFS version 2.2, disk version 2.0[1B][0m
    [00:00:00.260,620] [1B][1;31m<err> littlefs: can't get flash device: MX25R64[1B][0m
    [00:00:00.260,650] [1B][1;31m<err> fs: fs mount error (-19)[1B][0m
    

  • I will try to get a hold of an nRF9160 DK v1.0 with external memory and try to get it working.

  • A quick comment. I saw the following message: 

    <err> littlefs: can't get flash device: MX25R64

    This means that these lines failed:

    The call to device_get_binding() can fail due to two reasons

    1. If the label ("MX25R64") it's looking for is not in the generated DTS (which is translated into header files readable to .c files)
    2. If the associated init function failed.

    Regarding 1, can you check the file zephyr/samples/subsys/fs/littlefs/<build folder>/zephyr/zephyr.dts and search for "MX25R64"?

    Regarding 2, to find the associated init function you can look at the compatible field used for the mx25r64, which is "jedec,spi-nor". Then, after searching through NCS for "jedec_spi_nor", I found that the driver zephyr/drivers/flash/spi_nor.c used that compatible field, which contains the init function spi_nor_init(). Can you look into (either through debugging, or adding printk()'s and open a terminal like Termite) spi_nor_init()-->spi_nor_configure() and see if it fails (should return null if succesful)? This is a function run by the kernel before main.c

    Best regards,

    Simon

  • Regarding 1, can you check the file zephyr/samples/subsys/fs/littlefs/<build folder>/zephyr/zephyr.dts and search for "MX25R64"?

    It is mentioned under spi3:

    			spi3: spi@b000 {
    				#address-cells = < 0x1 >;
    				#size-cells = < 0x0 >;
    				reg = < 0xb000 0x1000 >;
    				interrupts = < 0xb 0x1 >;
    				status = "okay";
    				label = "SPI_3";
    				compatible = "nordic,nrf-spim";
    				sck-pin = < 0xd >;
    				mosi-pin = < 0xb >;
    				miso-pin = < 0xc >;
    				cs-gpios = < &gpio0 0x19 0x1 >;
    				mx25r64: mx25r6435f@0 {
    					compatible = "jedec,spi-nor";
    					reg = < 0x0 >;
    					spi-max-frequency = < 0x7a1200 >;
    					label = "MX25R64";
    					jedec-id = [ C2 28 17 ];
    					sfdp-bfp = [ E5 20 F1 FF FF FF FF 03 44 EB 08 6B 08 3B 04 BB EE FF FF FF FF FF 00 FF FF FF 00 FF 0C 20 0F 52 10 D8 00 FF 23 72 F5 00 82 ED 04 CC 44 83 68 44 30 B0 30 B0 F7 C4 D5 5C 00 BE 29 FF F0 D0 FF FF ];
    					size = < 0x4000000 >;
    					has-dpd;
    					t-enter-dpd = < 0x2710 >;
    					t-exit-dpd = < 0x88b8 >;
    					partitions {
    						compatible = "fixed-partitions";
    						#address-cells = < 0x1 >;
    						#size-cells = < 0x1 >;
    						lfs1_part: partition@0 {
    							label = "storage";
    							reg = < 0x0 0x10000 >;
    							phandle = < 0x5 >;
    						};
    					};
    				};
    			};

    Does this seem correct to you?

    Can you debug spi_nor_init() and see if it fails

    I will try debugging tomorrow.

    I also tried attaching an oscilloscope to the SCK-pin (P0.13) but it didn't seem to have any signal on it.

    Thanks for your response Slight smile

Related