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

ble_app_hrs_freertos Increassing MTU Fatal error

Hi,

Using SDK 15.3.0 , example "ble_app_hrs_freertos", pca10040 with armgcc.

I want to increase MTU and GAP data length.

I started with MTU to 247, and when I try to connect, on log :

<debug> nrf_sdh_freertos: Creating a SoftDevice task.
<info> app: HRS FreeRTOS example started.
<debug> nrf_sdh_freertos: Enter softdevice_task.
<info> app: Fast advertising.
<error> hardfault: HARD FAULT at 0x0002C004
<error> hardfault:   R0:  0x20008214  R1:  0x002A821C  R2:  0x20008214  R3:  0x20008208
<error> hardfault:   R12: 0x00000000  LR:  0x0002AAF1  PSR: 0x8100020E
<error> hardfault: Cause: Data bus error (PC value stacked for the exception return points to the instruction that caused the fault).
<error> hardfault: Bus Fault Address: 0x002A8228

The modifications I have done to the code are :

diff --git a/config/FreeRTOSConfig.h b/config/FreeRTOSConfig.h
index ae2167d..6dee317 100644
--- a/config/FreeRTOSConfig.h
+++ b/config/FreeRTOSConfig.h
@@ -63,7 +63,7 @@
 #define configTICK_RATE_HZ                                                        1024
 #define configMAX_PRIORITIES                                                      ( 3 )
 #define configMINIMAL_STACK_SIZE                                                  ( 60 )
-#define configTOTAL_HEAP_SIZE                                                     ( 4096 )
+#define configTOTAL_HEAP_SIZE                                                     ( 8192 )
 #define configMAX_TASK_NAME_LEN                                                   ( 4 )
 #define configUSE_16_BIT_TICKS                                                    0
 #define configIDLE_SHOULD_YIELD                                                   1
diff --git a/pca10040/s132/config/sdk_config.h b/pca10040/s132/config/sdk_config.h
index 8edaaed..715d28d 100644
--- a/pca10040/s132/config/sdk_config.h
+++ b/pca10040/s132/config/sdk_config.h
@@ -39,6 +39,9 @@
  */


+#ifndef DEBUG
+#define DEBUG 1
+#endif

 #ifndef SDK_CONFIG_H
 #define SDK_CONFIG_H
@@ -7432,7 +7435,7 @@
 // <e> NRF_LOG_BACKEND_RTT_ENABLED - nrf_log_backend_rtt - Log RTT backend
 //==========================================================
 #ifndef NRF_LOG_BACKEND_RTT_ENABLED
-#define NRF_LOG_BACKEND_RTT_ENABLED 0
+#define NRF_LOG_BACKEND_RTT_ENABLED 1
 #endif
 // <o> NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE - Size of buffer for partially processed strings.
 // <i> Size of the buffer is a trade-off between RAM usage and processing.
@@ -7465,7 +7468,7 @@
 // <e> NRF_LOG_BACKEND_UART_ENABLED - nrf_log_backend_uart - Log UART backend
 //==========================================================
 #ifndef NRF_LOG_BACKEND_UART_ENABLED
-#define NRF_LOG_BACKEND_UART_ENABLED 1
+#define NRF_LOG_BACKEND_UART_ENABLED 0
 #endif
 // <o> NRF_LOG_BACKEND_UART_TX_PIN - UART TX pin
 #ifndef NRF_LOG_BACKEND_UART_TX_PIN
@@ -7582,7 +7585,7 @@
 // <4=> Debug

 #ifndef NRF_LOG_DEFAULT_LEVEL
-#define NRF_LOG_DEFAULT_LEVEL 3
+#define NRF_LOG_DEFAULT_LEVEL 4
 #endif

 // <q> NRF_LOG_DEFERRED  - Enable deffered logger.
@@ -7632,7 +7635,7 @@
 // <e> NRF_LOG_USES_COLORS - If enabled then ANSI escape code for colors is prefixed to every string
 //==========================================================
 #ifndef NRF_LOG_USES_COLORS
-#define NRF_LOG_USES_COLORS 0
+#define NRF_LOG_USES_COLORS 1
 #endif
 // <o> NRF_LOG_COLOR_DEFAULT  - ANSI escape code prefix.

@@ -11069,12 +11072,12 @@

 // <o> NRF_SDH_BLE_GATT_MAX_MTU_SIZE - Static maximum MTU size.
 #ifndef NRF_SDH_BLE_GATT_MAX_MTU_SIZE
-#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 23
+#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 247
 #endif

 // <o> NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE - Attribute Table size in bytes. The size must be a multiple of 4.
 #ifndef NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE
-#define NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 1408
+#define NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 2000
 #endif

 // <o> NRF_SDH_BLE_VS_UUID_COUNT - The number of vendor-specific UUIDs.

I also modified "nrf_sdh_freertos.c" :

#define NRF_BLE_FREERTOS_SDH_TASK_STACK 256 to 512

(not sur it is useful ?)

I also have seen normal ble_app_hrs is with 247 MTU and 251 GAP data lenth, and it works !

Regards,

Parents
  • Hi Matthiew,

    I would assume that you need large stack allocation for your application tasks and also try to increase configTOTAL_HEAP_SIZE a bit more. The issue you are having is very likely related to memory allocation and many other users in this forum had this issue which went away after increasing stack/heap size. Please search this forum for similar issues and please let me know if this did you help you.

Reply
  • Hi Matthiew,

    I would assume that you need large stack allocation for your application tasks and also try to increase configTOTAL_HEAP_SIZE a bit more. The issue you are having is very likely related to memory allocation and many other users in this forum had this issue which went away after increasing stack/heap size. Please search this forum for similar issues and please let me know if this did you help you.

Children
  • Hi,

    As said I already tried to increase : #define NRF_BLE_FREERTOS_SDH_TASK_STACK 256 to 512
    And it is the only task !
    I just tried with 2096, and it is not better ... :

    <debug> nrf_sdh_ble: RAM starts at 0x20002B88
    <debug> nrf_sdh_freertos: Creating a SoftDevice task.
    <info> app: HRS FreeRTOS example started.
    <debug> nrf_sdh_freertos: Enter softdevice_task.
    <info> app: Fast advertising.
    <debug> nrf_sdh_ble: BLE event: 0x10.
    <debug> nrf_ble_gatt: Requesting to update ATT MTU to 247 bytes on connection 0x0.
    <debug> nrf_ble_gatt: Updating data length to 251 on connection 0x0.
    <info> app: Connected
    <debug> nrf_sdh_ble: BLE event: 0x24.
    <debug> nrf_ble_gatt: Data length updated to 27 on connection 0x0.
    <debug> nrf_ble_gatt: max_rx_octets: 27
    <debug> nrf_ble_gatt: max_tx_octets: 27
    <debug> nrf_ble_gatt: max_rx_time: 328
    <debug> nrf_ble_gatt: max_tx_time: 328
    <debug> nrf_sdh_ble: BLE event: 0x3A.
    <debug> nrf_ble_gatt: ATT MTU updated to 247 bytes on connection 0x0 (response).
    <error> hardfault: HARD FAULT at 0x0002C194
    <error> hardfault:   R0:  0x200075E4  R1:  0x002B75EC  R2:  0x200075E4  R3:  0x200075D8
    <error> hardfault:   R12: 0x00000000  LR:  0x0002AC81  PSR: 0x8100020E
    <error> hardfault: Cause: Data bus error (PC value stacked for the exception return points to the instruction that caused the fault).
    <error> hardfault: Bus Fault Address: 0x002B75F8

    It should be very easy to change only the few parameters from the SDK example to make it work !
    And as I said, it works with all other profile I have tried ...

  • I reproduced it, At first i thought nRF52832 has little heap memory is spare to be able to support 247 MTU size, so I tested this on nRF52840 with huge heap space in reserve. But I still managed to replicate it, I will take a look into this tomorrow to see where the stack corruption is happening.

Related