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 Reply Children
No Data
Related