Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Bugs in ble_app_hrs_freertos example?

Some bugs in ble_app_hrs_freertos example from the SDK when handling buttons:
(at the end of this listing are same tests but with ble_app_hrs (no rtos) and buttons are handled as expected)
Tests were made with pca10040 / SDK 16.0.0 and SES 4.30b

Could you point where is the problem, please, because I've used some parts of this code as base for one my app and it handles buttons Ok in Release mode, but in Debug mode first pass through the button handler passes, but then the app stalls without reporting any error :(
Thanks
---------------------------------

ble_app_hrs_freertos_pca10040_s132

Turn On the PCA10040 board:
<info> app: HRS FreeRTOS example started.
<info> app: Fast advertising.

Press Btn1: ->Sleep
Press Btn1 or Btn2 or Btn3 or Btn4:
<info> app: HRS FreeRTOS example started.
<info> app: Fast advertising.

While advertising:
Press Btn2:
<error> hardfault: HARD FAULT at 0x00000004
<error> hardfault: R0: 0x200067E4 R1: 0x20006738 R2: 0x200072E0 R3: 0x200072E0
<error> hardfault: R12: 0x20007138 LR: 0x00000004 PSR: 0x6000000E
<error> hardfault: Cause: The processor has attempted to execute an instruction that makes illegal use of the EPSR.
<info> app: HRS FreeRTOS example started.
<info> app: Fast advertising.

Press Btn3 or Btn4:
<error> hardfault: HARD FAULT at 0x00000002
<error> hardfault: R0: 0x20007098 R1: 0x20006FF8 R2: 0x200072E0 R3: 0x200072E0
<error> hardfault: R12: 0x200065D4 LR: 0x00000002 PSR: 0x6000000E
<error> hardfault: Cause: The processor has attempted to execute an instruction that makes illegal use of the EPSR.
<info> app: HRS FreeRTOS example started.
<info> app: Fast advertising.


While Connected (not paired):
<info> app: Connected

Press Btn2:
<error> hardfault: HARD FAULT at 0x00000004
<error> hardfault: R0: 0x200067E4 R1: 0x20006738 R2: 0x200072E0 R3: 0x200072E0
<error> hardfault: R12: 0x20007138 LR: 0x00000004 PSR: 0x6000000E
<error> hardfault: Cause: The processor has attempted to execute an instruction that makes illegal use of the EPSR.
<info> app: HRS FreeRTOS example started.
<info> app: Fast advertising.


<info> app: Connected
Press Btn3 or Btn4:
<error> hardfault: HARD FAULT at 0x00000002
<error> hardfault: R0: 0x20007098 R1: 0x20006FF8 R2: 0x200072E0 R3: 0x200072E0
<error> hardfault: R12: 0x20007138 LR: 0x00000002 PSR: 0x6000000E
<error> hardfault: Cause: The processor has attempted to execute an instruction that makes illegal use of the EPSR.
<info> app: HRS FreeRTOS example started.
<info> app: Fast advertising.

--- When Paired:
restart:
<info> app: HRS FreeRTOS example started.
<info> app: Fast advertising.

Connect:
<info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update, no change
<info> app: Connected
<info> peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 0, procedure: Encryption
<info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update, no change
<info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update
<info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update

Press Btn1 Or Btn2 or Btn3 or Btn4:
For Btn1 and 2 (with some minor diffs in the values):
<error> hardfault: HARD FAULT at 0x00000004
<error> hardfault: R0: 0x200067E4 R1: 0x20006738 R2: 0x200072E0 R3: 0x200072E0
<error> hardfault: R12: 0x20007138 LR: 0x00000004 PSR: 0x6000000E
<error> hardfault: Cause: The processor has attempted to execute an instruction that makes illegal use of the EPSR.
<info> app: HRS FreeRTOS example started.
<info> app: Fast advertising.

For Btn3 and 3 (with some minor diffs in the values):
<error> hardfault: HARD FAULT at 0x00000002
<error> hardfault: R0: 0x20007098 R1: 0x20006FF8 R2: 0x200072E0 R3: 0x200072E0
<error> hardfault: R12: 0x20007138 LR: 0x00000002 PSR: 0x6000000E
<error> hardfault: Cause: The processor has attempted to execute an instruction that makes illegal use of the EPSR.
<info> app: HRS FreeRTOS example started.
<info> app: Fast advertising.


==============================================================================
ble_app_hrs_pca10040_s132: (here everything works Ok so far)

Press Btn1: ->Sleep
Press Btn1:
<info> app_timer: RTC: initialized.
<info> app: Heart Rate Sensor example started.
<info> app: Fast advertising.

Long press Btn2:
<info> app: Fast advertising.

Press Btn1: ->Sleep
Press Btn2:
<info> app_timer: RTC: initialized.
<info> app: Heart Rate Sensor example started.
<info> app: Erase bonds!
<info> peer_manager_handler: All peers deleted.
<info> app: Fast advertising.

Pressing Btn2,Btn3, Btn4 while advertising or connected - no any effect

Parents
  • The problems I posted are from the very original NOT modified anyhow ble_app_hrs_freertos example supplied with SDK16.0.0

  • Hi samsam, 

    I am not seeing any issues running the ble_app_hrs_freertos_pca10040_s132 from SDK 16.0.0 in the Debug configuration. Which logging backend are you using RTT or UART?

  • Hi bjorn-spockeli,
    If I compile the example with Debug config setting, I dont see the error messages neither, but the messages appears always when compiled in Release config (this I think was the initial setting the way how was the example provided).
    In both modes waking up from sleep mode with Btn2 doesn't work (as supposed to - with clear bonding) and this problem I still didn't trace root cause, else the problem with the other errors that I've posted before - you were right - have to increase timer task stack to somewhere 130 minimum and errors disappear (but if I set 180 - some other crashes start - didnt trace where was the problem yet though)
    I used UART for the result I posted last time - not sure the RTT was enabled, because on the other example I tried before was not enabled and I had to enabled it myself)
    Thank you and best regards

Reply
  • Hi bjorn-spockeli,
    If I compile the example with Debug config setting, I dont see the error messages neither, but the messages appears always when compiled in Release config (this I think was the initial setting the way how was the example provided).
    In both modes waking up from sleep mode with Btn2 doesn't work (as supposed to - with clear bonding) and this problem I still didn't trace root cause, else the problem with the other errors that I've posted before - you were right - have to increase timer task stack to somewhere 130 minimum and errors disappear (but if I set 180 - some other crashes start - didnt trace where was the problem yet though)
    I used UART for the result I posted last time - not sure the RTT was enabled, because on the other example I tried before was not enabled and I had to enabled it myself)
    Thank you and best regards

Children
  • I am not seeing any Hardfaults or similar when using the Release configuration. I have been using the UART backend for logging as well. 

    According to the Heart Rate Application documentation, its Button 1 that is used to wake up the chip from System OFF, not Button 2. 

  • Hi bjorn-spockeli,

    I'm comparing ble_app_hrs_pca10040_s132 with ble_app_hrs_freertos_pca10040_s132

    with ble_app_hrs_pca10040_s132 when:
    Press Btn2 from sleep mode::
    <info> app_timer: RTC: initialized.
    <info> app: Heart Rate Sensor example started.
    <info> app: Erase bonds!
    <info> peer_manager_handler: All peers deleted.
    <info> app: Fast advertising.


    with ble_app_hrs_freertos_pca10040_s132
    Press Btn2 from sleep mode get only these:
    <info> app: HRS FreeRTOS example started.
    <info> app: Fast advertising.

    And bonding is not deleted - I tested it and other way with deleting bonding in the Android client, and after this cant reconnect, because old bonding stays in nRF. I didn't go in details through the code, but because of the documentation for HRS FreeRTOS example says: "See Heart Rate Application for a detailed description of the example scenario." I assume the functionality of the both applications should be the same?

    Any idea how can track the problem reported with the first posting: something related to nRF chip version (I have  PCA10040/ V1.1.1/2016.35) or is the SDK16.0.0  only unique release or there sub versions under the same number 16.0.0? I have nRF5_SDK_16.0.0_98a08e2

    This is IDE I'm using: SEGGER Embedded Studio for ARM/Release 4.30b  Build 2019111305.40571/Windows x64

    What is the value configTIMER_TASK_STACK_DEPTH in your test ( 80 )?

    BTW when I was trying to find proper value for configTIMER_TASK_STACK_DEPTH:
    At value 100, Btn 3 and Btn4 stopped giving hardfaults, but Btn2 make nRF to stall 

    --- if I rise timer stack: 80 ->100
    <info> app: HRS FreeRTOS example started.
    <info> app: Fast advertising.
    If I press Btn3 or 4 no any effect or error, but if I press Btn2 while advertising - nRF stalls and need restart

    --- if I rise timer stack: 80 ->180
    <info> app: HRS FreeRTOS example started.
    <error> app: Fatal error
    <warning> app: System reset
    (cycling the same non stop)

    Thanks

  • Hi samsam, 

     

    samsam said:
    And bonding is not deleted - I tested it and other way with deleting bonding in the Android client, and after this cant reconnect, because old bonding stays in nRF. I didn't go in details through the code, but because of the documentation for HRS FreeRTOS example says: "See Heart Rate Application for a detailed description of the example scenario." I assume the functionality of the both applications should be the same?

     Yes, I am able to reproduce the issue when using the release configuration. I agree that the functionality should be the same as the non-FreeRTOS example.

     

    samsam said:

    Any idea how can track the problem reported with the first posting: something related to nRF chip version (I have  PCA10040/ V1.1.1/2016.35) or is the SDK16.0.0  only unique release or there sub versions under the same number 16.0.0? I have nRF5_SDK_16.0.0_98a08e2

    This is IDE I'm using: SEGGER Embedded Studio for ARM/Release 4.30b  Build 2019111305.40571/Windows x64

    The hardware I am using is a PCA10040 v1.2.4 2018.39

    There is only one unique release of SDK v16.0.0, i.e. nRF5_SDK_16.0.0_98a08e2.  I am using SEGGER Embedded Studio for ARM Release 4.40  Build 2020011001.41059 Windows x64

     

    samsam said:

    What is the value configTIMER_TASK_STACK_DEPTH in your test ( 80 )?

    BTW when I was trying to find proper value for configTIMER_TASK_STACK_DEPTH:
    At value 100, Btn 3 and Btn4 stopped giving hardfaults, but Btn2 make nRF to stall 

    --- if I rise timer stack: 80 ->100
    <info> app: HRS FreeRTOS example started.
    <info> app: Fast advertising.
    If I press Btn3 or 4 no any effect or error, but if I press Btn2 while advertising - nRF stalls and need restart

     Yes, I was using configTIMER_TASK_STACK_DEPTH set to 80. I am seeing the Hardfaults when using button 3 and 4 in this configuration. Increasing configTIMER_TASK_STACK_DEPTH to 100 resolves the button 3 and 4 issues. However, I see the same issue as you with button 2 with configTIMER_TASK_STACK_DEPTH set to 80 and 100

     

    samsam said:

    --- if I rise timer stack: 80 ->180
    <info> app: HRS FreeRTOS example started.
    <error> app: Fatal error
    <warning> app: System reset
    (cycling the same non stop)

     Yes, increasing configTIMER_TASK_STACK_DEPTH to 180 results in 

    <info> app: HRS FreeRTOS example started.
    <error> app: Fatal error
    <warning> app: System reset

    If I add DEBUG to the preprocessor definitions in SES, then i get the following output

    <info> app: HRS FreeRTOS example started.
    <error> app: ERROR 15 [NRF_ERROR_FORBIDDEN] at C:\Nordic_Semiconductor\SDK_repository\nRF5_SDK_16.0.0_684aa2c\examples\ble_peripheral\ble_app_hrs_freertos\main.c:983
    PC at: 0x000333F5
    <error> app: End of error report

    Which means that vTaskStartScheduler returns. Debugging the function I see that xTimerCreateTimerTask returns -1. Which means that  the kernel could not be started,
    because there was not enough FreeRTOS heap to create the idle task or the timer task. 

    Increasing configTOTAL_HEAP_SIZE to 8192 from 4096 solved this issue and after doing this change I do not get a stall when pressing button 2. However, I do not see the bonds being erased, so there is apparently something that isnt configured correctly.

  • Hi bjorn-spockeli,

    regarding not erasing the bonds - I just go through the code - there is some mess with variable that suppose to trigger bond erasing procedure: in hrs_freertos there is one extra variable bool delete_bonds  which has only one assignment to false when is declared,   then the same name is used as the function static void delete_bonds(void) .... tomorrow will try to debug to see how to fix without side effects as now here is too late ;)

    BTW - your forum is also buggy - now I could answer only to myself :(

  • The erase_bond variable is set by buttons_leds_init(bool * p_erase_bonds), which calls bsp_btn_ble_init(NULL, &startup_event), which in turn calls startup_event_extract()

    static void startup_event_extract(bsp_event_t * p_startup_event)
    {
        // React to button states
        if (bsp_button_is_pressed(BTN_ID_WAKEUP_BOND_DELETE))
        {
            *p_startup_event = BSP_EVENT_CLEAR_BONDING_DATA;
        }
        else if (bsp_button_is_pressed(BTN_ID_WAKEUP))
        {
            *p_startup_event = BSP_EVENT_WAKEUP;
        }
        else
        {
            *p_startup_event = BSP_EVENT_NOTHING;
        }
    }

    In the end of buttons_leds_init() you set  *p_erase_bonds = (startup_event == BSP_EVENT_CLEAR_BONDING_DATA);

    Dont see why that shouldnt work. The startup_event_extract() function simply reads the pin...

    Best regards
    Bjørn

Related