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?
  • this error always occur in second connection. first connection never

    So there must be something you're not properly tidying-up after the first connection.

    As noted before, this could be a missing 'volatile', or some uninitialised variable(s), or suchlike - which could well behave differently with & without optimisation.

    You really need to narrow down what is the difference between when it works & when it fails.

    I believed these functions related on this issue

    What makes you think that?

    What have you done to prove your theory?

    www.8052mcu.com/.../120313

    www.avrfreaks.net/.../2418156

    I remove all sd_ flash write and erase function

    You can't just go arbitrarily hacking out chunks of code - you need to check carefully that there are no dependencies on that code.

    then another error occur

    probably because there are dependencies on that code!

    How to properly post source code:

Reply
  • this error always occur in second connection. first connection never

    So there must be something you're not properly tidying-up after the first connection.

    As noted before, this could be a missing 'volatile', or some uninitialised variable(s), or suchlike - which could well behave differently with & without optimisation.

    You really need to narrow down what is the difference between when it works & when it fails.

    I believed these functions related on this issue

    What makes you think that?

    What have you done to prove your theory?

    www.8052mcu.com/.../120313

    www.avrfreaks.net/.../2418156

    I remove all sd_ flash write and erase function

    You can't just go arbitrarily hacking out chunks of code - you need to check carefully that there are no dependencies on that code.

    then another error occur

    probably because there are dependencies on that code!

    How to properly post source code:

Children
  • My application has used sd_ write and erase for storing application data. the address is from bootloader start address to 8 flash page top down. I just remove all these functions in my application level.

    --> hardfault doesn't occur. 

    My theory is that It is overlap between my application data address and somewhat ble_ sdk.

    so first connection is always succeed. and my application data write this area. and then sdk hardfault.

    Is there are flash area in ble sdk? I have used the peripheral role.

    should I use fstorage libraries? 

  • farther debugging,

     

    hardfault error occur also keil.

    I try to this way

    Is SP+0x14 value 0x00021E95? and I doesn't found 0x00021E95 function address in .map file.

    Could you recommend a way step by step to trace the cause of a hardfault error?

Related