This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Start scaning right after starting advertising.

I use sdk 9.0.0, softdevice s130, nrf51422_xxac. In my application I have to both scan and advertise. When I start one of them (scanning or advertising) application starts running properly but when I start them both my application not always starts executing properly (sometimes it looks like processor is executing total mess and I have to restart it, using button, few times till it starts executing properly). In my code I call starting functions consecutively:

err = ble_advertising_start(BLE_ADV_MODE_FAST); 
APP_ERROR_CHECK(err);
err = sd_ble_gap_scan_start(&scan_params); 

The order of calling these 2 functions does not change anything. In ble_gap.h I did not realize any function for checking if softdevice is ready to start next functionality. I lack ideas what is the reason of such behaviour.

  • I have made some investigation today and first of all I have to apologize to you. Application crashes also when I start only one of scanning or advertising but it is much more in these cases, it only has 100% correct execution when neither advertising nor scanning is started. In my application I have static variable (uart_counter) which is changed whenever I want to send something using uart. There are only two functions that modifies this value. When program went buggy I stopped it with gdb and it occurred that uart_counter was equal to some huge value thats why almost whole RAM is sent. I init uart and start sending before calling ble_advertising_start and ble_scan_start. Is it possible that softdevice may change value of static variable or automatic variable of function that was interrupted by softdevice ?

  • no need to apologize ... it good that you managed to narrow down the source of the problem. softdevice RAM address space and application RAM address space is different. If you believe it is a RAM corruption then i am almost sure that it is not the softdevice. Softdevice is compiled with fixed RAM space and if there is a stack corruption, it should be in the lower side of rhe RAM address space and not into the application RAM address space. Softdevice does not use heap memory.

    I think the application has sent the address of an uninitialized pointer or similar. If you are using KEIL, you can set a breakpoint on uart_counter with a condition to see what has set the variable to such a high value.

  • I use Linux so my debugging tool is arm-none-eabi-gdb. I have tried watch uart_count if uart_count > 100 to stop my program to see when this value gets so high. Unfortunately gdb stops every time uart_count is changed but because of active soft device I got into hard fault after long breaks. I know that cortex M0 supports hardware watchpoints but do you know if supporting conditional hardware watchpoints is something else ?

  • First of all, vrey sorry for coming back to you so late. This thread somehow lost its visibility : ( instead of watchpoints, i guess it useful to insert conditional breakpoints. There is an interesting discussion here and look for the comments from DaveR

    Instead of watching the value whe it equals a specific value; you should set a conditional break point on the line where you want to check the value of var1. This should effectively have the same effect

    e.g. (gdb) break main.c:123 if (var1 == 0)

Related