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

nRF51822 gcc unknown errors.

SDK: 12.3.0

SOFTDEVICE: s130_nrf51_2.0.1_softdevice

CHIP: nrf51822 AC 256K flash 32K ram

GCC flags:

# C flags common to all targets
CFLAGS += -DBOARD_CUSTOM
CFLAGS += -DSOFTDEVICE_PRESENT
CFLAGS += -DNRF51
CFLAGS += -DS130
CFLAGS += -DBLE_STACK_SUPPORT_REQD
CFLAGS += -DSWI_DISABLE0
CFLAGS += -DNRF51422
CFLAGS += -DNRF_SD_BLE_API_VERSION=2
CFLAGS += -mcpu=cortex-m0
CFLAGS += -mthumb -mabi=aapcs
#CFLAGS += -Wall -Werror
CFLAGS += -O3 -Os -g3
#CFLAGS += -O3 -Os -g3
# CFLAGS += -Wint-conversion -Wint-to-pointer-cast
CFLAGS += -mfloat-abi=soft
# keep every function in separate section, this allows linker to discard unused ones
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin --short-enums
CFLAGS += -DDEBUG
CFLAGS += -DDEBUG_NRF
Keil:
DEBUG_NRF DEBUG BLE_STACK_SUPPORT_REQD NRF51422 BOARD_CUSTOM NRF_SD_BLE_API_VERSION=2 S130 NRF51 SOFTDEVICE_PRESENT SWI_DISABLE0

hi, I have used both keil and gcc for nRF51822 development.

I found some strange situation. keil compiled product has no problem.

but, gcc product has some problem.

first, when ble connected, hardfault error occur sometimes. 

second, In ble connected state or just after disconnect event triggered, I have called ble_advertising_start(BLE_ADV_MODE_IDLE) function for triggering idle event.

but, gcc code always stuck somewhere. never out ble_advertising_start function.

The more weird thing is that second problem disappear after removing CFLAGS optimization flags -O3 -Os -g3 in Makefile.

and I again attached CFLAGS optimization flags -O3 -Os -g3. but second problem never occur. but The first problem still occurs.

I don't understand this situation and I can not be sure of the completeness of the product.

Thank you for your advice.

Parents
  • problem disappear after removing CFLAGS optimization

    That almost always points to a flaw in your code - you are relying on something that you shouldn't, and the optimisation catches you out on that.

    A very common example is failure to use 'volatile' where it is needed.

    The other is timing.

    You're going to have to instrument your code, and/or use the debugger to find what's happening ...

  • this hardfault error only occur in gcc production...

    and I found something.

    first, when ble connected, hardfault error occur sometimes. --> this error always occur in second connection. first connection never. 

    so I remove all sd_ flash write and erase function. ( I believed these functions related on this issue). 

    then another error occur.

    //-----------------------------------------------------------------------------
    static void conn_params_error_handler(uint32_t nrf_error)
    {
      APP_ERROR_HANDLER(nrf_error); <=========[ERROR 0x7 [NRF_ERROR_INVALID_PARAM]]
    }
    /**@brief Function for initializing the Connection Parameters module.
    */
    static void conn_params_init(void)
    {
      uint32_t err_code;
      ble_conn_params_init_t cp_init;

      memset(&cp_init, 0, sizeof(cp_init));

      cp_init.p_conn_params = NULL;
      cp_init.first_conn_params_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY;
      cp_init.next_conn_params_update_delay = NEXT_CONN_PARAMS_UPDATE_DELAY;
      cp_init.max_conn_params_update_count = MAX_CONN_PARAMS_UPDATE_COUNT;
      cp_init.start_on_notify_cccd_handle = BLE_GATT_HANDLE_INVALID;
      cp_init.disconnect_on_fail = false;
      cp_init.evt_handler = on_conn_params_evt;
      cp_init.error_handler = conn_params_error_handler;

      err_code = ble_conn_params_init(&cp_init);
      APP_ERROR_CHECK(err_code);
    }
    error in conn_params_error_handler function,  code is ERROR 0x7 [NRF_ERROR_INVALID_PARAM].
    only occur in second connection.
    So. I increase APP_TIMER_OP_QUEUE_SIZE enough. but It doesn't work.
    How do you think about?
Reply
  • this hardfault error only occur in gcc production...

    and I found something.

    first, when ble connected, hardfault error occur sometimes. --> this error always occur in second connection. first connection never. 

    so I remove all sd_ flash write and erase function. ( I believed these functions related on this issue). 

    then another error occur.

    //-----------------------------------------------------------------------------
    static void conn_params_error_handler(uint32_t nrf_error)
    {
      APP_ERROR_HANDLER(nrf_error); <=========[ERROR 0x7 [NRF_ERROR_INVALID_PARAM]]
    }
    /**@brief Function for initializing the Connection Parameters module.
    */
    static void conn_params_init(void)
    {
      uint32_t err_code;
      ble_conn_params_init_t cp_init;

      memset(&cp_init, 0, sizeof(cp_init));

      cp_init.p_conn_params = NULL;
      cp_init.first_conn_params_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY;
      cp_init.next_conn_params_update_delay = NEXT_CONN_PARAMS_UPDATE_DELAY;
      cp_init.max_conn_params_update_count = MAX_CONN_PARAMS_UPDATE_COUNT;
      cp_init.start_on_notify_cccd_handle = BLE_GATT_HANDLE_INVALID;
      cp_init.disconnect_on_fail = false;
      cp_init.evt_handler = on_conn_params_evt;
      cp_init.error_handler = conn_params_error_handler;

      err_code = ble_conn_params_init(&cp_init);
      APP_ERROR_CHECK(err_code);
    }
    error in conn_params_error_handler function,  code is ERROR 0x7 [NRF_ERROR_INVALID_PARAM].
    only occur in second connection.
    So. I increase APP_TIMER_OP_QUEUE_SIZE enough. but It doesn't work.
    How do you think about?
Children
Related