<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Monitor mode debugging - Incorrect values in Watch</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/98494/monitor-mode-debugging---incorrect-values-in-watch</link><description>Hi, 
 
 I was trying to add monitor mode debugging to a firmware: nRF5 SDK 15.3.0 running on Acconeer XM122 Radar module, and after I encountered the issue I also tried it on nRF5 SDK 17.0.2 with nRF52840 DK, I got the same result. 
 
 Basically, I have</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 10 May 2023 15:24:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/98494/monitor-mode-debugging---incorrect-values-in-watch" /><item><title>RE: Monitor mode debugging - Incorrect values in Watch</title><link>https://devzone.nordicsemi.com/thread/424938?ContentTypeID=1</link><pubDate>Wed, 10 May 2023 15:24:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b054f45-4d1e-47c9-b7dd-9f76bab70691</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I don&amp;#39;t know if it is impossible, but I think the base assumption is that MMD is currently not able to. The easy solution is to use statically allocated variables if you need to debug them with MMD.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Monitor mode debugging - Incorrect values in Watch</title><link>https://devzone.nordicsemi.com/thread/424857?ContentTypeID=1</link><pubDate>Wed, 10 May 2023 12:45:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bca1838d-6159-4711-9f8b-4a31d564835e</guid><dc:creator>enukic</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/haakonsh"&gt;haakonsh&lt;/a&gt;&amp;nbsp;&lt;br /&gt;Thank you for the detailed response.&lt;br /&gt;&lt;br /&gt;And sorry for my very long delay with the followup.&lt;/p&gt;
&lt;p&gt;To conclude, it&amp;#39;s not possible to watch local variables with MMD?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Monitor mode debugging - Incorrect values in Watch</title><link>https://devzone.nordicsemi.com/thread/420291?ContentTypeID=1</link><pubDate>Thu, 13 Apr 2023 14:16:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d0c5b8f-6f32-4edc-8bf4-0f419aeec76f</guid><dc:creator>haakonsh</dc:creator><description>[quote user="enukic"]If I declare it as static or static volatile, I&amp;#39;m getting the correct value in the Watch when the program pauses at a breakpoint.&lt;br /&gt;If I only set it to volatile, the value in Watch becomes wrong.[/quote]
&lt;p&gt;I think that observation fits well with your disassembly, though my understanding of assembly is limited:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int mainlocal = 0;
    2300        movs r3, #0
    9301        str r3, [sp, #4]
--- main.c -- 321 ------------------------------------------&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I think the snippet above describes that the compiler/linker have placed the &amp;#39;mainlocal&amp;#39; variable at t&lt;span&gt;he 2nd word of the current stack frame [sp, #4], and&lt;/span&gt;&amp;nbsp;how&amp;nbsp;the initial value of &amp;#39;0&amp;#39; is written to it. This means that a new instance of the local varable &amp;#39;mainlocal&amp;#39; is created for each unique invocation of the function &amp;#39;main&amp;#39; and stored&amp;nbsp;in its stack frame.&amp;nbsp;&lt;span style="font-family:inherit;"&gt;As far as I know there is no compile-time mechanism that prevents you from calling &amp;#39;main&amp;#39; as many times as you&amp;#39;d like (&amp;nbsp;often leading to stack-overflow).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;When debugging without MMD and the CPU is halted by a breakpoint, the debugger will have easy access to the breakpoint&amp;#39;s&amp;nbsp;stack frame since it is the current/last stack frame in use.&amp;nbsp;That means&amp;nbsp;that the debugger will allways&amp;nbsp;know&amp;nbsp;where&amp;nbsp;the instance of the local variable &amp;#39;mainlocal&amp;#39; is stored. In this case the address of the Stack pointer + 4. No matter how many invocations of &amp;#39;main&amp;#39; you create the address of &amp;#39;mainlocal&amp;#39; is static with respect to&amp;nbsp;its&amp;nbsp;stack frame, and the debugger will always be able to access it.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;When debugging with MMD and the CPU is halted by a breakpoint,&amp;nbsp;&lt;/span&gt;the debugger jumps into the MMD ISR and it loses access to the stack frame&amp;nbsp;that triggered the breakpoint (loss of context). At this point the debugger knows that &amp;#39;mainlocal&amp;#39; is at address SP + 4, but it does not know what the address of the &amp;#39;breakpoint&amp;#39;s SP is, and is therefore unable to display it, or worse, it displays the value it reads from SP + 4 where SP is the MMD ISR&amp;#39;s Stack Pointer.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This is where the keyword &amp;#39;static&amp;#39; comes into play. A variable that is statically allocated to memory will be allocated a piece of memory by the linker, the size of its type and&amp;nbsp;placed at an immutable address within&amp;nbsp;a block of memory dedicated to the statically allocated variables.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A global variable&amp;#39;s memory is always statically allocated, and a local variable will be statically allocated if it is decleared with the &amp;#39;static&amp;#39; keyword. Only one instance of a statically allocated variable will be created and all stack frames&amp;nbsp;that accesses it will have to share it. This also means that statically allocated variables are not thread-safe btw.&lt;/p&gt;
&lt;p&gt;The debugger will always know the address of a&amp;nbsp;statically allocated variable(.elf file) regardless of the state of the Stack.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The &amp;#39;volatile&amp;#39; keyword lets the compiler know that you expect the value of a variable to change at any given point in time outside of the scope of the current stack frame, and that you need the compiler to not to optimize the code by caching the value of the variable for future use and instead make sure that its value is read from memory every time it is to be used in a calculation.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The &amp;#39;volatile&amp;#39; and &amp;#39;static&amp;#39; test i asked of you tested whether the debugger&amp;nbsp;was able to resolve &amp;#39;mainlocal&amp;#39;s address, and whether it actually access that address or just cached the variable in a general CPU reg.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Monitor mode debugging - Incorrect values in Watch</title><link>https://devzone.nordicsemi.com/thread/420087?ContentTypeID=1</link><pubDate>Thu, 13 Apr 2023 06:16:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4751413e-ea91-4448-b871-56ad6022b7c7</guid><dc:creator>enukic</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/haakonsh"&gt;haakonsh&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Here is the disassembly&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    110F        asrs r7, r1, #4
    9800        ldr r0, [sp]
    F7F9F9F4    bl 0x00028E18 &amp;lt;app_error_handler&amp;gt;
--- main.c -- 269 ------------------------------------------
{
ret_code_t err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
app_timer_create(&amp;amp;myTim, APP_TIMER_MODE_REPEATED, myTimCb);
    4A08        ldr r2, =0x0002F9FD &amp;lt;myTimCb&amp;gt;
    2101        movs r1, #1
    4808        ldr r0, =0x00032520 &amp;lt;myTim&amp;gt;
    F7F9FD8B    bl 0x00029550 &amp;lt;app_timer_create&amp;gt;
--- main.c -- 274 ------------------------------------------
app_timer_start(myTim, APP_TIMER_TICKS(1000), NULL);
    4B08        ldr r3, =0x20002230 &amp;lt;myTim_data&amp;gt;
    2200        movs r2, #0
    F44F4180    mov.w r1, #0x4000
    4618        mov r0, r3
    F7F9FDB8    bl 0x000295B8 &amp;lt;app_timer_start&amp;gt;
--- main.c -- 275 ------------------------------------------
}
    BF00        nop
    B003        add sp, sp, #12
    F85DFB04    pop.w {pc}
    00032524    .word 0x00032524
    0002F9FD    .word 0x0002F9FD
    00032520    .word 0x00032520
    20002230    .word 0x20002230
--- main.c -- 277 ------------------------------------------
/**@brief Function for initializing power management.
*/
static void power_management_init(void)
{
    B500        push {lr}
    B083        sub sp, sp, #12
--- main.c -- 282 ------------------------------------------
ret_code_t err_code;
err_code = nrf_pwr_mgmt_init();
    F7FBFB32    bl 0x0002B0CC &amp;lt;nrf_pwr_mgmt_init&amp;gt;
    9001        str r0, [sp, #4]
--- main.c -- 284 ------------------------------------------
APP_ERROR_CHECK(err_code);
    9B01        ldr r3, [sp, #4]
    9300        str r3, [sp]
    9B00        ldr r3, [sp]
    2B00        cmp r3, #0
    D005        beq 0x0002FA80
    4A04        ldr r2, =0x00032524
    F44F718E    mov.w r1, #0x011C
    9800        ldr r0, [sp]
    F7F9F9CC    bl 0x00028E18 &amp;lt;app_error_handler&amp;gt;
--- main.c -- 285 ------------------------------------------
}
    BF00        nop
    B003        add sp, sp, #12
    F85DFB04    pop.w {pc}
    00032524    .word 0x00032524
--- main.c -- 289 ------------------------------------------
*
* @details If there is no pending log operation, then sleep until next the next event occurs.
*/
static void idle_state_handle(void)
{
    B508        push {r3, lr}
--- main.c -- 294 ------------------------------------------
if (NRF_LOG_PROCESS() == false)
    F7F8FA8D    bl 0x00027FAC &amp;lt;nrf_log_frontend_dequeue&amp;gt;
    4603        mov r3, r0
    F0830301    eor r3, r3, #1
    B2DB        uxtb r3, r3
    2B00        cmp r3, #0
    D001        beq 0x0002FAA2
--- main.c -- 295 ------------------------------------------
{
nrf_pwr_mgmt_run();
    F7FBFB2B    bl 0x0002B0F8 &amp;lt;nrf_pwr_mgmt_run&amp;gt;
--- main.c -- 297 ------------------------------------------
}
}
    BF00        nop
    BD08        pop {r3, pc}
    0000        movs r0, r0
--- main.c -- 299 ------------------------------------------
static void changeCtx(int * p_mainlocal, int * p_varGlobal)
{
    B500        push {lr}
    B083        sub sp, sp, #12
    9001        str r0, [sp, #4]
    9100        str r1, [sp]
--- main.c -- 302 ------------------------------------------
if(*p_mainlocal &amp;gt; 10)
    9B01        ldr r3, [sp, #4]
    681B        ldr r3, [r3]
    2B0A        cmp r3, #10
    DD27        ble 0x0002FB08
--- main.c -- 303 ------------------------------------------
{
*p_mainlocal = 0;
    9B01        ldr r3, [sp, #4]
    2200        movs r2, #0
    601A        str r2, [r3]
--- main.c -- 305 ------------------------------------------
NRF_LOG_INFO(&amp;quot;reset p_mainlocal&amp;quot;);
    4A14        ldr r2, =0x000314C4 &amp;lt;m_nrf_log_app_logs_data_const&amp;gt;
    4B14        ldr r3, =0x0003149C &amp;lt;__nrf_balloc_end__&amp;gt;
    1AD3        subs r3, r2, r3
    08DB        lsrs r3, r3, #3
    041B        lsls r3, r3, #16
    F0430303    orr r3, r3, #3
    4912        ldr r1, =0x00032564
    4618        mov r0, r3
    F7F8FA10    bl 0x00027EF4 &amp;lt;nrf_log_frontend_std_0&amp;gt;
--- main.c -- 306 ------------------------------------------
NRF_LOG_INFO(&amp;quot;p_varGlobal %d&amp;quot;, *p_varGlobal);
    4A0E        ldr r2, =0x000314C4 &amp;lt;m_nrf_log_app_logs_data_const&amp;gt;
    4B0F        ldr r3, =0x0003149C &amp;lt;__nrf_balloc_end__&amp;gt;
    1AD3        subs r3, r2, r3
    08DB        lsrs r3, r3, #3
    041B        lsls r3, r3, #16
    F0430003    orr r0, r3, #3
    9B00        ldr r3, [sp]
    681B        ldr r3, [r3]
    461A        mov r2, r3
    490C        ldr r1, =0x00032578
    F7F8FA11    bl 0x00027F10 &amp;lt;nrf_log_frontend_std_1&amp;gt;
--- main.c -- 307 ------------------------------------------
NRF_LOG_INFO(&amp;quot;varStaticGlobal %d&amp;quot;, varStaticGlobal);
    4A08        ldr r2, =0x000314C4 &amp;lt;m_nrf_log_app_logs_data_const&amp;gt;
    4B08        ldr r3, =0x0003149C &amp;lt;__nrf_balloc_end__&amp;gt;
    1AD3        subs r3, r2, r3
    08DB        lsrs r3, r3, #3
    041B        lsls r3, r3, #16
    F0430303    orr r3, r3, #3
    4A08        ldr r2, =0x20002288 &amp;lt;varStaticGlobal&amp;gt;
    6812        ldr r2, [r2]
    4908        ldr r1, =0x00032588
    4618        mov r0, r3
    F7F8FA04    bl 0x00027F10 &amp;lt;nrf_log_frontend_std_1&amp;gt;
--- main.c -- 308 ------------------------------------------
}
}
    BF00        nop
    B003        add sp, sp, #12
    F85DFB04    pop.w {pc}
    000314C4    .word 0x000314C4
    0003149C    .word 0x0003149C
    00032564    .word 0x00032564
    00032578    .word 0x00032578
    20002288    .word 0x20002288
    00032588    .word 0x00032588
--- main.c -- 311 ------------------------------------------
/**
* @brief Function for application main entry.
*/
int main(void)
{
    B500        push {lr}
    B083        sub sp, sp, #12
--- main.c -- 316 ------------------------------------------
#if CONFIG_JLINK_MONITOR_ENABLED
NVIC_SetPriority(DebugMonitor_IRQn, _PRIO_APP_HIGH);
    2102        movs r1, #2
    F06F0003    mvn r0, #3
    F7FFFE2B    bl 0x0002F78C &amp;lt;__NVIC_SetPriority&amp;gt;
--- main.c -- 318 ------------------------------------------
#endif
int mainlocal = 0;
    2300        movs r3, #0
    9301        str r3, [sp, #4]
--- main.c -- 321 ------------------------------------------
// Initialize.
log_init();
    F7FFFF2D    bl 0x0002F998 &amp;lt;log_init&amp;gt;
--- main.c -- 324 ------------------------------------------
timers_init();
    F7FFFF67    bl 0x0002FA10 &amp;lt;timers_init&amp;gt;
--- main.c -- 325 ------------------------------------------
leds_init();
    F7FFFF43    bl 0x0002F9CC &amp;lt;leds_init&amp;gt;
--- main.c -- 326 ------------------------------------------
power_management_init();
    F7FFFF8B    bl 0x0002FA60 &amp;lt;power_management_init&amp;gt;
--- main.c -- 327 ------------------------------------------
ble_stack_init();
    F7FFFEEF    bl 0x0002F92C &amp;lt;ble_stack_init&amp;gt;
--- main.c -- 328 ------------------------------------------
advertising_init();
    F7FFFE61    bl 0x0002F814 &amp;lt;advertising_init&amp;gt;
--- main.c -- 329 ------------------------------------------
// Start execution.
NRF_LOG_INFO(&amp;quot;Beacon example started.&amp;quot;);
    4A1D        ldr r2, =0x000314C4 &amp;lt;m_nrf_log_app_logs_data_const&amp;gt;
    4B1D        ldr r3, =0x0003149C &amp;lt;__nrf_balloc_end__&amp;gt;
    1AD3        subs r3, r2, r3
    08DB        lsrs r3, r3, #3
    041B        lsls r3, r3, #16
    F0430303    orr r3, r3, #3
    491B        ldr r1, =0x0003259C
    4618        mov r0, r3
    F7F8F9C6    bl 0x00027EF4 &amp;lt;nrf_log_frontend_std_0&amp;gt;
--- main.c -- 332 ------------------------------------------
advertising_start();
    F7FFFEB6    bl 0x0002F8D8 &amp;lt;advertising_start&amp;gt;
--- main.c -- 333 ------------------------------------------
// Enter main loop.
for (;; )
{
idle_state_handle();
    F7FFFF8E    bl 0x0002FA8C &amp;lt;idle_state_handle&amp;gt;
--- main.c -- 338 ------------------------------------------
if(mySem)
    4B18        ldr r3, =0x20002287
    781B        ldrb r3, [r3]
    2B00        cmp r3, #0
    D0F9        beq 0x0002FB6C
--- main.c -- 340 ------------------------------------------
{
mySem = false;
    4B16        ldr r3, =0x20002287
    2200        movs r2, #0
    701A        strb r2, [r3]
--- main.c -- 342 ------------------------------------------
NRF_LOG_INFO(&amp;quot;main local %d&amp;quot;, mainlocal++);
    4A12        ldr r2, =0x000314C4 &amp;lt;m_nrf_log_app_logs_data_const&amp;gt;
    4B12        ldr r3, =0x0003149C &amp;lt;__nrf_balloc_end__&amp;gt;
    1AD3        subs r3, r2, r3
    08DB        lsrs r3, r3, #3
    041B        lsls r3, r3, #16
    F0430003    orr r0, r3, #3
    9B01        ldr r3, [sp, #4]
    1C5A        adds r2, r3, #1
    9201        str r2, [sp, #4]
    461A        mov r2, r3
    4910        ldr r1, =0x000325B4
    F7F8F9BB    bl 0x00027F10 &amp;lt;nrf_log_frontend_std_1&amp;gt;
--- main.c -- 343 ------------------------------------------
NRF_LOG_INFO(&amp;quot;static global %d&amp;quot;, varStaticGlobal++);
    4A0B        ldr r2, =0x000314C4 &amp;lt;m_nrf_log_app_logs_data_const&amp;gt;
    4B0B        ldr r3, =0x0003149C &amp;lt;__nrf_balloc_end__&amp;gt;
    1AD3        subs r3, r2, r3
    08DB        lsrs r3, r3, #3
    041B        lsls r3, r3, #16
    F0430003    orr r0, r3, #3
    4B0C        ldr r3, =0x20002288 &amp;lt;varStaticGlobal&amp;gt;
    681B        ldr r3, [r3]
    1C5A        adds r2, r3, #1
    490B        ldr r1, =0x20002288 &amp;lt;varStaticGlobal&amp;gt;
    600A        str r2, [r1]
    461A        mov r2, r3
    490A        ldr r1, =0x000325C4
    F7F8F9AB    bl 0x00027F10 &amp;lt;nrf_log_frontend_std_1&amp;gt;
--- main.c -- 344 ------------------------------------------
changeCtx(&amp;amp;mainlocal, &amp;amp;varStaticGlobal);
    AB01        add r3, sp, #4
    4907        ldr r1, =0x20002288 &amp;lt;varStaticGlobal&amp;gt;
    4618        mov r0, r3
    F7FFFF72    bl 0x0002FAA8 &amp;lt;changeCtx&amp;gt;
--- main.c -- 337 ------------------------------------------
idle_state_handle();
    E7D2        b 0x0002FB6C
    BF00        nop
    000314C4    .word 0x000314C4
    0003149C    .word 0x0003149C
    0003259C    .word 0x0003259C
    20002287    .word 0x20002287
    000325B4    .word 0x000325B4
    20002288    .word 0x20002288
    000325C4    .word 0x000325C4
--- SEGGER_RTT.c -- 276 ------------------------------------
*/
#define INIT() do { \
if (_SEGGER_RTT.acID[0] == &amp;#39;\0&amp;#39;) { _DoInit(); } \
} while (0)
static void _DoInit(void) {
    B500        push {lr}
    B083        sub sp, sp, #12
--- SEGGER_RTT.c -- 281 ------------------------------------
SEGGER_RTT_CB* p;
//
// Initialize control block
//
p = &amp;amp;_SEGGER_RTT;
    4B1F        ldr r3, =0x2000228C &amp;lt;_SEGGER_RTT&amp;gt;
    9301        str r3, [sp, #4]
--- SEGGER_RTT.c -- 286 ------------------------------------
p-&amp;gt;MaxNumUpBuffers = SEGGER_RTT_MAX_NUM_UP_BUFFERS;
    9B01        ldr r3, [sp, #4]
    2202        movs r2, #2
    611A        str r2, [r3, #16]
--- SEGGER_RTT.c -- 287 ------------------------------------
p-&amp;gt;MaxNumDownBuffers = SEGGER_RTT_MAX_NUM_DOWN_BUFFERS;
    9B01        ldr r3, [sp, #4]
    2202        movs r2, #2
    615A        str r2, [r3, #20]
--- SEGGER_RTT.c -- 288 ------------------------------------
//
// Initialize up buffer 0
//
p-&amp;gt;aUp[0].sName = &amp;quot;Terminal&amp;quot;;
    9B01        ldr r3, [sp, #4]
    4A1C        ldr r2, =0x000325D8
    619A        str r2, [r3, #24]
--- SEGGER_RTT.c -- 292 ------------------------------------
p-&amp;gt;aUp[0].pBuffer = _acUpBuffer;
    9B01        ldr r3, [sp, #4]
    4A1B        ldr r2, =0x20002304 &amp;lt;_acUpBuffer&amp;gt;
    61DA        str r2, [r3, #28]
--- SEGGER_RTT.c -- 293 ------------------------------------
p-&amp;gt;aUp[0].SizeOfBuffer = sizeof(_acUpBuffer);
    9B01        ldr r3, [sp, #4]
    F44F7200    mov.w r2, #0x0200
    621A        str r2, [r3, #32]
--- SEGGER_RTT.c -- 294 ------------------------------------
p-&amp;gt;aUp[0].RdOff = 0u;
    9B01        ldr r3, [sp, #4]
    2200        movs r2, #0
    629A        str r2, [r3, #0x28]
--- SEGGER_RTT.c -- 295 ------------------------------------
p-&amp;gt;aUp[0].WrOff = 0u;
    9B01        ldr r3, [sp, #4]
    2200        movs r2, #0
    625A        str r2, [r3, #0x24]
--- SEGGER_RTT.c -- 296 ------------------------------------
p-&amp;gt;aUp[0].Flags = SEGGER_RTT_MODE_DEFAULT;
    9B01        ldr r3, [sp, #4]
    2200        movs r2, #0
    62DA        str r2, [r3, #0x2C]
--- SEGGER_RTT.c -- 297 ------------------------------------
//
// Initialize down buffer 0
//
p-&amp;gt;aDown[0].sName = &amp;quot;Terminal&amp;quot;;
    9B01        ldr r3, [sp, #4]
    4A12        ldr r2, =0x000325D8
    649A        str r2, [r3, #0x48]
--- SEGGER_RTT.c -- 301 ------------------------------------
p-&amp;gt;aDown[0].pBuffer = _acDownBuffer;
    9B01        ldr r3, [sp, #4]
    4A13        ldr r2, =0x20002504 &amp;lt;_acDownBuffer&amp;gt;
    64DA        str r2, [r3, #0x4C]
--- SEGGER_RTT.c -- 302 ------------------------------------
p-&amp;gt;aDown[0].SizeOfBuffer = sizeof(_acDownBuffer);
    9B01        ldr r3, [sp, #4]
    2210        movs r2, #16
    651A        str r2, [r3, #0x50]
--- SEGGER_RTT.c -- 303 ------------------------------------
p-&amp;gt;aDown[0].RdOff = 0u;
    9B01        ldr r3, [sp, #4]
    2200        movs r2, #0
    659A        str r2, [r3, #0x58]
--- SEGGER_RTT.c -- 304 ------------------------------------
p-&amp;gt;aDown[0].WrOff = 0u;
    9B01        ldr r3, [sp, #4]
    2200        movs r2, #0
    655A        str r2, [r3, #0x54]
--- SEGGER_RTT.c -- 305 ------------------------------------
p-&amp;gt;aDown[0].Flags = SEGGER_RTT_MODE_DEFAULT;
    9B01        ldr r3, [sp, #4]
    2200        movs r2, #0
    65DA        str r2, [r3, #0x5C]
--- SEGGER_RTT.c -- 307 ------------------------------------
// Finish initialization of the control block.
// Copy Id string in three steps to make sure &amp;quot;SEGGER RTT&amp;quot; is not found
// in initializer memory (usually flash) by J-Link
//
strcpy(&amp;amp;p-&amp;gt;acID[7], &amp;quot;RTT&amp;quot;);
    9B01        ldr r3, [sp, #4]
    3307        adds r3, #7
    490C        ldr r1, =0x000325E4
    4618        mov r0, r3
    F001FBBA    bl 0x000313C2 &amp;lt;strcpy&amp;gt;
--- SEGGER_RTT.c -- 312 ------------------------------------
strcpy(&amp;amp;p-&amp;gt;acID[0], &amp;quot;SEGGER&amp;quot;);
    9B01        ldr r3, [sp, #4]
    490A        ldr r1, =0x000325E8
    4618        mov r0, r3
    F001FBB5    bl 0x000313C2 &amp;lt;strcpy&amp;gt;
--- SEGGER_RTT.c -- 313 ------------------------------------
p-&amp;gt;acID[6] = &amp;#39; &amp;#39;;
    9B01        ldr r3, [sp, #4]
    2220        movs r2, #32
    719A        strb r2, [r3, #6]
--- SEGGER_RTT.c -- 314 ------------------------------------
}
    BF00        nop
    B003        add sp, sp, #12
    F85DFB04    pop.w {pc}
    BF00        nop
    2000228C    .word 0x2000228C
    000325D8    .word 0x000325D8
    20002304    .word 0x20002304
    20002504    .word 0x20002504
    000325E4    .word 0x000325E4
    000325E8    .word 0x000325E8
--- SEGGER_RTT.c -- 331 ------------------------------------
*
* Return value
* &amp;gt;= 0 - Number of bytes written into buffer.
*/
static unsigned _WriteBlocking(SEGGER_RTT_BUFFER_UP* pRing, const char* pBuffer, unsigned NumBytes) {
    B500        push {lr}
    B089        sub sp, sp, #0x24
    9003        str r0, [sp, #12]
    9102        str r1, [sp, #8]
    9201        str r2, [sp, #4]
--- SEGGER_RTT.c -- 342 ------------------------------------
#endif
//
// Write data to buffer and handle wrap-around if necessary
//
NumBytesWritten = 0u;
    2300        movs r3, #0
    9306        str r3, [sp, #24]
--- SEGGER_RTT.c -- 347 ------------------------------------
WrOff = pRing-&amp;gt;WrOff;
    9B03        ldr r3, [sp, #12]
    68DB        ldr r3, [r3, #12]
    9305        str r3, [sp, #20]
--- SEGGER_RTT.c -- 348 ------------------------------------
do {
RdOff = pRing-&amp;gt;RdOff; // May be changed by host (debug probe) in the meantime
    9B03        ldr r3, [sp, #12]
    691B        ldr r3, [r3, #16]
    9304        str r3, [sp, #16]
--- SEGGER_RTT.c -- 350 ------------------------------------
if (RdOff &amp;gt; WrOff) {
    9A04        ldr r2, [sp, #16]
    9B05        ldr r3, [sp, #20]
    429A        cmp r2, r3
    D905        bls 0x0002FCAE
--- SEGGER_RTT.c -- 351 ------------------------------------
NumBytesToWrite = RdOff - WrOff - 1u;
    9A04        ldr r2, [sp, #16]
    9B05        ldr r3, [sp, #20]
    1AD3        subs r3, r2, r3
    3B01        subs r3, #1
    9307        str r3, [sp, #28]
    E007        b 0x0002FCBE
--- SEGGER_RTT.c -- 352 ------------------------------------
} else {
NumBytesToWrite = pRing-&amp;gt;SizeOfBuffer - (WrOff - RdOff + 1u);
    9B03        ldr r3, [sp, #12]
    689A        ldr r2, [r3, #8]
    9904        ldr r1, [sp, #16]
    9B05        ldr r3, [sp, #20]
    1ACB        subs r3, r1, r3
    4413        add r3, r2
    3B01        subs r3, #1
    9307        str r3, [sp, #28]
--- SEGGER_RTT.c -- 354 ------------------------------------
}
NumBytesToWrite = MIN(NumBytesToWrite, (pRing-&amp;gt;SizeOfBuffer - WrOff)); // Number of bytes that can be written until buffer wrap-around
    9B03        ldr r3, [sp, #12]
    689A        ldr r2, [r3, #8]
    9B05        ldr r3, [sp, #20]
    1AD3        subs r3, r2, r3
    9A07        ldr r2, [sp, #28]
    4293        cmp r3, r2
    BF28        it cs
    4613        movcs r3, r2
    9307        str r3, [sp, #28]
--- SEGGER_RTT.c -- 356 ------------------------------------
NumBytesToWrite = MIN(NumBytesToWrite, NumBytes);
    9A07        ldr r2, [sp, #28]
    9B01        ldr r3, [sp, #4]
    4293        cmp r3, r2
    BF28        it cs
    4613        movcs r3, r2
    9307        str r3, [sp, #28]
--- SEGGER_RTT.c -- 362 ------------------------------------
while (NumBytesToWrite--) {
*pDst++ = *pBuffer++;
};
#else
SEGGER_RTT_MEMCPY(pRing-&amp;gt;pBuffer + WrOff, pBuffer, NumBytesToWrite);
    9B03        ldr r3, [sp, #12]
    685A        ldr r2, [r3, #4]
    9B05        ldr r3, [sp, #20]
    4413        add r3, r2
    9A07        ldr r2, [sp, #28]
    9902        ldr r1, [sp, #8]
    4618        mov r0, r3
    F001FB0E    bl 0x0003130A &amp;lt;__aeabi_memcpy&amp;gt;
--- SEGGER_RTT.c -- 367 ------------------------------------
NumBytesWritten += NumBytesToWrite;
    9A06        ldr r2, [sp, #24]
    9B07        ldr r3, [sp, #28]
    4413        add r3, r2
    9306        str r3, [sp, #24]
--- SEGGER_RTT.c -- 368 ------------------------------------
pBuffer += NumBytesToWrite;
    9A02        ldr r2, [sp, #8]
    9B07        ldr r3, [sp, #28]
    4413        add r3, r2
    9302        str r3, [sp, #8]
--- SEGGER_RTT.c -- 369 ------------------------------------
NumBytes -= NumBytesToWrite;
    9A01        ldr r2, [sp, #4]
    9B07        ldr r3, [sp, #28]
    1AD3        subs r3, r2, r3
    9301        str r3, [sp, #4]
--- SEGGER_RTT.c -- 370 ------------------------------------
WrOff += NumBytesToWrite;
    9A05        ldr r2, [sp, #20]
    9B07        ldr r3, [sp, #28]
    4413        add r3, r2
    9305        str r3, [sp, #20]
--- SEGGER_RTT.c -- 371 ------------------------------------
#endif
if (WrOff == pRing-&amp;gt;SizeOfBuffer) {
    9B03        ldr r3, [sp, #12]
    689B        ldr r3, [r3, #8]
    9A05        ldr r2, [sp, #20]
    429A        cmp r2, r3
    D101        bne 0x0002FD1C
--- SEGGER_RTT.c -- 373 ------------------------------------
WrOff = 0u;
    2300        movs r3, #0
    9305        str r3, [sp, #20]
--- SEGGER_RTT.c -- 374 ------------------------------------
}
pRing-&amp;gt;WrOff = WrOff;
    9B03        ldr r3, [sp, #12]
    9A05        ldr r2, [sp, #20]
    60DA        str r2, [r3, #12]
--- SEGGER_RTT.c -- 376 ------------------------------------
} while (NumBytes);
    9B01        ldr r3, [sp, #4]
    2B00        cmp r3, #0
    D1B5        bne 0x0002FC94
--- SEGGER_RTT.c -- 377 ------------------------------------
//
return NumBytesWritten;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Interrupt priorities&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&amp;#39;m not sure how I can set the main() priority. Could you guide me on where to read/set this?&lt;/p&gt;
&lt;p&gt;Timer ISR priority is set to 6:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;#define APP_TIMER_CONFIG_IRQ_PRIORITY 6&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I tried with different MMD priorities, none of them worked. I hope that this is is what you are referring to:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;NVIC_SetPriority(DebugMonitor_IRQn, _PRIO_APP_HIGH);&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;As for the mainlocal as static/volatile:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If I declare it as static or static volatile, I&amp;#39;m getting the correct value in the Watch when the program pauses at a breakpoint.&lt;br /&gt;If I only set it to volatile, the value in Watch becomes wrong.&lt;/p&gt;
&lt;p&gt;Please let me know if you need any additional info.&lt;br /&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Monitor mode debugging - Incorrect values in Watch</title><link>https://devzone.nordicsemi.com/thread/419815?ContentTypeID=1</link><pubDate>Tue, 11 Apr 2023 18:51:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da790398-461b-4d7f-8309-c823c3deaf8f</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Can you share a dissasembly of your program?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can you share your interrupt priorities? We need to know at what priority main(), timer ISR, and MMD ISR runs at.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What happens if you declare &amp;#39;mainlocal&amp;#39; as &amp;#39;volatile&amp;#39;&amp;nbsp;or &amp;#39;static&amp;#39;, or both?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Monitor mode debugging - Incorrect values in Watch</title><link>https://devzone.nordicsemi.com/thread/419480?ContentTypeID=1</link><pubDate>Mon, 10 Apr 2023 11:44:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7462993f-24d2-40de-9f5d-d5feba9c8169</guid><dc:creator>enukic</dc:creator><description>&lt;p&gt;HI Martin &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f60a.svg" title="Blush"&gt;&amp;#x1f60a;&lt;/span&gt;&lt;br /&gt;Thanks for the reply. &lt;br /&gt;&lt;br /&gt;Compiler optimization was off during initial testing.&lt;br /&gt;I tested again, using various optimization levels, but it made no difference.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Monitor mode debugging - Incorrect values in Watch</title><link>https://devzone.nordicsemi.com/thread/419422?ContentTypeID=1</link><pubDate>Fri, 07 Apr 2023 04:36:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a7858d1e-059f-49bf-ba98-cf8ffa2bdcf8</guid><dc:creator>mtsunstrum</dc:creator><description>&lt;p&gt;Do you have compiler optimizations on or off ?&lt;/p&gt;
&lt;p&gt;For `mainlocal` it seems like it may have been optimized to be a register variable. The debugger may then have problem inspecting such variables.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>