Define a section to consistently place rtt

NCS 2.7 with sysbuild + mcuboot

NRF52840 (custom boards)

In my previous projects with NRF5 SDK I found it was very helpful to define a section in the linker so the rtt control block is always placed in the same place.  This way when updating between different versions of the application or when running through the bootloader (if rtt output is enabled) the debugger always find the rtt control block.

How would I define this in zephyr?  It seems like I need to add a linker ld script.

I tried adding it to my pm_static.yml but it doesn't appear to interface all the way to the linker.

rtt:
  address: 0x2003F800
  end_address: 0x2003FC00
  region: sram_primary
  size: 0x400

  • I think I have this working.  In my board dts file I added:

    / {
        sram@2003FB00 {
            compatible = "zephyr,memory-region";
            reg = <0x2003FB00 0x500>;
            zephyr,memory-region = "rtt";
            status = "okay";
        };
    };
    In my application CMakeLists.txt  I added:
    zephyr_compile_definitions(SEGGER_RTT_SECTION="rtt")
    When I run a single image build I see this in my zephyr/zephyr_pre0.map
    rtt             0x000000002003fb00      0x4b8
                    0x000000002003fb00                __rtt_start = .
     *(SORT_BY_ALIGNMENT(rtt))
     rtt            0x000000002003fb00      0x4b8 modules/segger/libmodules__segger.a(SEGGER_RTT.c.obj)
                    0x000000002003ff10                _SEGGER_RTT
     *(SORT_BY_ALIGNMENT(rtt.*))
                    0x000000002003ffb8                __rtt_end = .
                    0x00000000000004b8                __rtt_size = (__rtt_end - __rtt_start)
                    0x000000002003fb00                __rtt_load_start = LOADADDR (rtt)
  • I also need to get this to work with sysbuild for a multi image build.  I'm hoping this will work in my pm_static.yml:

    rtt:
    address: 0x2003FB00
    end_address: 0x20040000
    region: sram_primary
    size: 0x500

  • I didn't need to add anything for the rtt block in the partition manager static configuration.  The zephyr,memory-region did it all.

  •   

    Hi, I tried to place the RTT control block as per your note above.

    In the project folder's CMakeLists.txt, I added:

    zephyr_compile_definitions(SEGGER_RTT_SECTION="rtt")

    and in the overlay in the project boards folder, added:

    / {
        sram@2003FB00 {
            compatible = "zephyr,memory-region";
            reg = <0x2003FB00 0x500>;
            zephyr,memory-region = "rtt";
            status = "okay";
        };
    };




    However, I got the following in the zephyr_pre0.map and the SEGGER_RTT isn't being located to the specified address. I'm using NCS 2.9.0.


    What am I missing? How do we specify SEGGER_RTT to use the "rtt" memory region?


    btw - I have RTT logging both for the app and MCUBoot. Other than a minor glitch, app/MCUBoot logging seems to ok.

    *** Booting MCUboot v2.1.0-dev-12e5ee106034 ***
    *** Using nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    I: Starting bootloader
    I: Primary image: magic=good, swap_type=0x4, copy_done=0x1, image_ok=0x1
    I: Secondary image: magic=good, swap_type=0x2, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Image index: 0, Swap type: test
    I: Starting swap using move algorithm.
    I: Bootloader chainload address offset: 0x16000
    I: Jumping to the first image slot
    44] <inf> mcumgr_img_grp: Erased 0x1000 bytes of image slot trailer
    [00:02:37.191,741] <inf> mcuboot_util: Image index: 0, Swap type: none
    [00:02:37.192,108] <inf> mcuboot_util: Image index: 0, Swap type: test
    [00:02:46.936,798] <inf> mcuboot_util: Image index: 0, Swap type: test
    0m
    [00:34:59.613,952] <inf> mcuboot_util: Image index: 0, Swap type: revert
    *** Booting My Application v1.3.0 - unknown commit ***
    *** Using nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    [00:00:08.496,063] <inf> mcuboot_util: Image index: 0, Swap type: revert


    Thanks!


  • I'm using NCS 2.6.0, possibly its a difference in the versions.  

    In my environment I find  in modules/debug/segger/SEGGER/SEGGER_RTT.c this code:

    #ifndef SEGGER_RTT_BUFFER_SECTION
    #if defined(SEGGER_RTT_SECTION)
    #define SEGGER_RTT_BUFFER_SECTION SEGGER_RTT_SECTION
    #endif
    #endif
    
    <snip>
    
    #if defined(SEGGER_RTT_SECTION) || defined (SEGGER_RTT_BUFFER_SECTION)
    #if ((defined __GNUC__) || (defined __clang__))
    #define SEGGER_RTT_PUT_SECTION(Var, Section) __attribute__ ((section (Section))) Var
    #elif (defined __ICCARM__) || (defined __ICCRX__)
    #define SEGGER_RTT_PUT_SECTION(Var, Section) RTT_PRAGMA(location=Section) \
    Var
    #elif (defined __CC_ARM)
    #define SEGGER_RTT_PUT_SECTION(Var, Section) __attribute__ ((section (Section), zero_init)) Var
    #else
    #error "Section placement not supported for this compiler."
    #endif
    #else
    #define SEGGER_RTT_PUT_SECTION(Var, Section) Var
    #endif
    
    <snip>
    
    
    
    #if defined(SEGGER_RTT_SECTION)
    #define SEGGER_RTT_PUT_CB_SECTION(Var) SEGGER_RTT_PUT_SECTION(Var, SEGGER_RTT_SECTION)
    #else
    #define SEGGER_RTT_PUT_CB_SECTION(Var) Var
    #endif
    
    #if defined(SEGGER_RTT_BUFFER_SECTION)
    #define SEGGER_RTT_PUT_BUFFER_SECTION(Var) SEGGER_RTT_PUT_SECTION(Var, SEGGER_RTT_BUFFER_SECTION)
    #else
    #define SEGGER_RTT_PUT_BUFFER_SECTION(Var) Var
    #endif

    Does your environment have the same?  

Related