This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

HELP! I cannot change the value of a variable???

nrf52840, S140.

So for the past 1 or 2 weeks I have been fighting with this problem:

Now it turned out that the connection handle may actually be INVALID, it's 0!

So I debugged the wind out of the whole thing and found that I cannot change the value of the active connection handle"m_active_conn_handle", which I use to pass as the active connection handle to a variety of functions including for example sd_ble_hvx().

Here is the program:

else if (p_ble_evt->header.evt_id == BLE_GAP_EVT_CONNECTED)
    {
		uint32_t* error_code = &m_active_conn_handle;
		m_active_conn_handle = (uint16_t)p_ble_evt->evt.gap_evt.conn_handle;
		//m_active_conn_handle = 0x1234;
	
		
		error_code = sd_ble_gatts_sys_attr_set(p_ble_evt->evt.gatts_evt.conn_handle, NULL, 0, 0);

 
    }

I set a breakpoint at:

m_active_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;

and then pressed F10. Instead of the right value (0x8e4), the m_active_conn_handle got set to 0x0000.

This is really strange? Making an uneducated guess, is this caused by allocating m_active_conn_handle at the wrong address, like some sort of read only RAM region? Or stack region? Or is this caused by RAM_BASE_ADDRESS not configured properly?

Also, a lot of error code won't show unless I play some "tricks", for example:

err_code = sd_ble_gatts_hvx(m_active_conn_handle, &hvx_params);

the err_code will not show when breakpointed, it will simply display "out of scope" in keil's watch window but if I write:

err_code_address = & err_code;

below it, and set the breakpoint there, the err_code_address will NOT display the address of err_code, still "out of scope", but err_code will now properly display if you move your mouse cursor over it!

All of these lead me to believe I have set certain memory address wrong, but then again, that's just my uneducated guess, here is my config in the magic wand:

image description image description

Also, when calling

error_code = sd_ble_enable(&ble_enable,&USER_APP_RAM_BASE);

I'm using USER_APP_RAM_BASE = 0, which I know is a really, really bad idea but I can't modify its value to anything other than that either, for the same reason I can't modify the active connection handle's value.

Can someone please tell me what the whirlwind is going on??? Please help! Many thanks!

edit @endnode can you help me??

Edit: Quick answer: turn off optimization, and the problems "unable to change value, values not properly being displayed etc. are all gone.

Parents
  • A connection handle of 0x8e5, or 0x8e4, makes no sense. Connection handles start at 0 and go up (that's not guaranteed but that's how it actually works in practice with this softdevice).

    So it sounds to me like your actual issues are these

    1. you've convinced yourself that something to do with a connection handle is the cause of your bug and that's caused you to head into a different piece of functional code and start questioning it.

    2. keil sounds like a total POS. Are you actually compiling with debug and full debugging symbols (don't ask me how you do that in keil I don't use it) If you aren't the values you're seeing are probably not correct.

    If all else fails you could always drop down to the assembly and see what's in the registers and that will tell you what's really being passed to where.

    still think the assignment of 0 to the connection handle sounds completely right.

Reply
  • A connection handle of 0x8e5, or 0x8e4, makes no sense. Connection handles start at 0 and go up (that's not guaranteed but that's how it actually works in practice with this softdevice).

    So it sounds to me like your actual issues are these

    1. you've convinced yourself that something to do with a connection handle is the cause of your bug and that's caused you to head into a different piece of functional code and start questioning it.

    2. keil sounds like a total POS. Are you actually compiling with debug and full debugging symbols (don't ask me how you do that in keil I don't use it) If you aren't the values you're seeing are probably not correct.

    If all else fails you could always drop down to the assembly and see what's in the registers and that will tell you what's really being passed to where.

    still think the assignment of 0 to the connection handle sounds completely right.

Children
No Data
Related