For the nRF54 series, how to write logs into ZMS just by changing prj.conf

I am porting a ncs project from nrf52832 into nrf54l15 

If want to reuse existing Log functions of system of zephyr, like supported by NVS, is there any way to do it? 

Nordic AI said nrf54l15 should use ZMS to protect flash, and need to manually implement zms_log_store() function to replace all places of zephyr LOG_INF() .Is it the latest truth?

Thanks & Best Regards

-Shawn

Parents
  • Hello Shawn,

    It's correct as you say that we recommend to use ZMS instead of flash storage for the nRF54L and nRF54H devices. As described in https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/app_dev/device_guides/nrf54l/zms.html, which is probably what the Kapa chat bot sourced it's statement from, " ZMS utilizes a flexible data management system that reduces write and erase cycles, extending the lifespan of non-volatile memory.", meaning that ZMS is tailored to fit both SRAM and MRAM better than the flash memory storage options.

    If want to reuse existing Log functions of system of zephyr, like supported by NVS, is there any way to do it? 

    Could you give me an example/reference to clarify if I'm on the same page as you w.r.t "existing Log functions.."? Is it the <zephyr/logging/log.h> api you're referring to, or is it something else?

    Kind regards,
    Andreas

  • Thanks for your reply Andreas.

    Yes, I meant to use <zephyr/logging/log.h> api functions such as LOG_INF() ,LOG_ERR().

    In my understanding, with nrf52 series, if to redirect log into file on soc flash, developer doesn't need to specific code for that, and changes in prj.conf and overlay should be enough, with following example for nrf52832:

    -----------------conf.prj-------------

    # Enable Zephyr logging
    CONFIG_LOG=y
    CONFIG_LOG_BACKEND_FS=y
    CONFIG_LOG_BACKEND_FS_FILE_SIZE=4096
    CONFIG_LOG_BACKEND_FS_FILES_LIMIT=4
    CONFIG_LOG_BACKEND_FS_DIR="/log"
    CONFIG_LOG_DEFAULT_LEVEL=3  # Info level

    # Enable LittleFS and flash support
    CONFIG_FILE_SYSTEM=y
    CONFIG_FILE_SYSTEM_LITTLEFS=y
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_MAIN_STACK_SIZE=2048

    --------main.c-----------

    #include <zephyr/kernel.h>
    #include <zephyr/logging/log.h>
    #include <zephyr/fs/fs.h>
    #include <zephyr/fs/littlefs.h>

    LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);

    void main(void)
    {
        LOG_INF("Hello World! Logging to file system.");
        while (1) {
            LOG_INF("Periodic log message.");
            k_sleep(K_SECONDS(5));
        }
    }

    ----------------nrf52832.overlay-------------

    / {
        chosen {
            zephyr,flash-controller = &flash0;
        };

        /* LittleFS partition (adjust address/size as needed) */
        littlefs_storage: partition@7c000 {
            label = "storage";
            reg = <0x0007c000 0x00004000>;
        };
    };

    &flash0 {
        partitions {
            compatible = "fixed-partitions";
            #address-cells = <1>;
            #size-cells = <1>;

            /* ... other partitions ... */

            storage_partition: partition@7c000 {
                label = "storage";
                reg = <0x0007c000 0x00004000>;
            };
        };
    };

    ----------------------

    So ideally, if this simplicity applies for ZMS as well, it would be wonderful.

    Could your provide a helloworld example with above 3 files for same functionality shown above, based on nrf54l15+ncs 3.1.1? I believe it would make the answer very clear.

    Thanks a lot!

    -Shawn

Reply
  • Thanks for your reply Andreas.

    Yes, I meant to use <zephyr/logging/log.h> api functions such as LOG_INF() ,LOG_ERR().

    In my understanding, with nrf52 series, if to redirect log into file on soc flash, developer doesn't need to specific code for that, and changes in prj.conf and overlay should be enough, with following example for nrf52832:

    -----------------conf.prj-------------

    # Enable Zephyr logging
    CONFIG_LOG=y
    CONFIG_LOG_BACKEND_FS=y
    CONFIG_LOG_BACKEND_FS_FILE_SIZE=4096
    CONFIG_LOG_BACKEND_FS_FILES_LIMIT=4
    CONFIG_LOG_BACKEND_FS_DIR="/log"
    CONFIG_LOG_DEFAULT_LEVEL=3  # Info level

    # Enable LittleFS and flash support
    CONFIG_FILE_SYSTEM=y
    CONFIG_FILE_SYSTEM_LITTLEFS=y
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_MAIN_STACK_SIZE=2048

    --------main.c-----------

    #include <zephyr/kernel.h>
    #include <zephyr/logging/log.h>
    #include <zephyr/fs/fs.h>
    #include <zephyr/fs/littlefs.h>

    LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);

    void main(void)
    {
        LOG_INF("Hello World! Logging to file system.");
        while (1) {
            LOG_INF("Periodic log message.");
            k_sleep(K_SECONDS(5));
        }
    }

    ----------------nrf52832.overlay-------------

    / {
        chosen {
            zephyr,flash-controller = &flash0;
        };

        /* LittleFS partition (adjust address/size as needed) */
        littlefs_storage: partition@7c000 {
            label = "storage";
            reg = <0x0007c000 0x00004000>;
        };
    };

    &flash0 {
        partitions {
            compatible = "fixed-partitions";
            #address-cells = <1>;
            #size-cells = <1>;

            /* ... other partitions ... */

            storage_partition: partition@7c000 {
                label = "storage";
                reg = <0x0007c000 0x00004000>;
            };
        };
    };

    ----------------------

    So ideally, if this simplicity applies for ZMS as well, it would be wonderful.

    Could your provide a helloworld example with above 3 files for same functionality shown above, based on nrf54l15+ncs 3.1.1? I believe it would make the answer very clear.

    Thanks a lot!

    -Shawn

Children
  • Hi Shawn,

    Apologies for the long wait. It's been quite a week..

    First things first, no there's no ZMS logging backend. But you can add your own backend that uses the logging which is based on ZMS API: https://docs.zephyrproject.org/latest/services/logging/index.html#logging-backends 

    ZMS supports FS functions such as :

    • zms_mount(): Mounts a ZMS file system onto the device specified in the fs structure.
    • zms_clear(): Clears the ZMS file system from the device.
    • zms_write(): Writes an entry to the file system.
    • zms_delete(): Deletes an entry from the file system.
    • zms_read(): Reads an entry from the file system.
    • zms_read_hist(): Reads a history entry from the file system.

    All these functions operate on a pointer to a file system structure (struct zms_fs *fs), confirming that ZMS provides file system-level operations and management functions ZMS API Functions.

    So to conclude, there's no config that does handles this for you out of the box, but it is possible to use ZMS and logging together. If you wish, you can request this as a feature request through your regional sales manager and/or investigate if anyone else in the Zephyr discord forums have been doing the same, but I've not been able to find anything internally stating that this is something that we will prioritize to add support for as of yet

    Kind regards,
    Andreas 

  • Thanks Andreas for your detailed answer. You triggered me to re-consider whether following believes with NCS logging system is correct:

    1.<zephyr/logging/log.h> api is a mainstream logging module in NCS

    2.nrf54l15 is a mainstream chip from Nordic

    3.nrf54l15 need to use ZMS, if developer want to use zephyr logging API

    if above three statements are true, then how do developers write logging? I can only think of 2 options:

    option 1.it is not mainstream behavior of using zephyr logging api based on nrf54l15. If so, which NCS sample can be referred as recommended practice for dealing with that?

    option 2.most of teams working with nrf54l15, need to invent the wheel for ZMS backend. And from Nordic technical team's perspective, it is a acceptable design, unless sales department get involved.

    Please correct me if I miss anything...

    Thanks & Best Regards

    -Shawn

  • Hi Shawn, 

    I'm sorry for potentially causing an existential crisis heh

    listplot3d_dev said:
    1.<zephyr/logging/log.h> api is a mainstream logging module in NCS

    Yes, it is

    listplot3d_dev said:
    2.nrf54l15 is a mainstream chip from Nordic

    Yes it is

    listplot3d_dev said:
    3.nrf54l15 need to use ZMS, if developer want to use zephyr logging API

    It doesn't need to do this, but it is strongly recommended due to it using RRAM and not Flash 

    listplot3d_dev said:
    if above three statements are true, then how do developers write logging? I can only think of 2 options:

    Logging is done regularly with zephyr logging API, but the issue we're discussing in this case is how to "use the logging to file system together with ZMS". This does not have any built in backend per now. Logging over UART/serial is not an issue since this does not use logging to a ZMS file system.

    Does this make sense to you? I'm more than happy to dive deeper into this. I don't want to have caused any misunderstandings here

    Kind regards,
    Andreas

  • Thanks Andreas, here is my latest conclusion:)

    for logging API with nRF54L15, there are 3 scenarios:

    1. output to UART/serial.

       no problem at all. everybody is happy about that.

    2.output to local file, with existing prj.conf options

       mainstream market is happy about that, while Noridc strongly recommends another option

    3.output to ZMS file

       which is recommended by Nordic. But currently, only project with scenarios picky enough or with developers geeky enough, would choose this option.

    Please correct me if anything wrong

    Thanks & Best Regards

    -Shawn

  • Hi again Shawn

    listplot3d_dev said:

    2.output to local file, with existing prj.conf options

       mainstream market is happy about that, while Noridc strongly recommends another option

    I'll just reiterate the previous comment I made about this with one an addition: ZMS is developed and intended to be used to store data in RRAM and not as a logging backend to a file system. If you wish, you can use the FS logging backend instead, but that will introduce extra wear and tear on the RRAM due to this solution isn't using any ZMS implementation. The issue is with the implementation that has the appropriate algorithm to handle reading and writing to RRAM (which the nRF54L15 SoC uses).

    listplot3d_dev said:

    3.output to ZMS file

       which is recommended by Nordic. But currently, only project with scenarios picky enough or with developers geeky enough, would choose this option.

    I've never said "we recommend you to a ZMS file". What we've said is that ZMS is better to use with RRAM, but there is no built in logging to file-system backend. 

    Kind regards,
    Andreas

Related