Hi
I'm facing a Hard fault on the softdevice when trying to call sd_ble_gattc_write(). SDK15, SD140
I have a Multilink central connected to UART using app_uart. when a certain code arrives through the UART, it sends a command to BLE Peripherial using NUS like service.
that's the function that gets the command from UART:
void uart_evt_handle(app_uart_evt_t *p_event) { ret_code_t err_code; static uint8_t command[UART_MAX_MESSAGE_SIZE]=""; static uint16_t index=0; switch (p_event->evt_type) { case APP_UART_DATA_READY: { if (index >= UART_MAX_MESSAGE_SIZE) { NRF_LOG_DEBUG("Max Command Size"); index = 0; return; } err_code = app_uart_get(&command[index]); if (err_code == NRF_SUCCESS) { if (command[index] == '\r' || command[index] == '\n') // for command end { NRF_LOG_DEBUG("UART Message:"); NRF_LOG_HEXDUMP_DEBUG(command, index); handler(command); index = 0; } else { index++; if (index > UART_MAX_MESSAGE_SIZE) { NRF_LOG_ERROR("Max Character Size Recieved Without Termination. Cleaning Buffer"); index = 0; } } } else NRF_LOG_ERROR("Failed Recieveing Character"); } break; } }
where handler is function pointer that points to the next function:
void uart_com_evt_handler(uint8_t * message) { ret_code_t err_code; uint8_t ble_command[13]; sprintf(ble_command, "L1"); err_code = ble_nus_c_string_send(&m_nus_c, ble_command, 2); APP_ERROR_CHECK(err_code); }
as you can see, in this version there's no connection between what I'm getting on the UART and what I'm sending on the NUS. this is just for testing purpose.
what happens when I run this software, waits for connection and sends a string on the UART is that I get hard faulted on the sd_ble_gattc_write() function inside ble_nus_c_string_send()function. I've double checked that all function parameters passed to sd_ble_gattc_write() are correct.
the strange thing is that if I'm calling uart_com_evt_handler() from main.c once connection established, the ble_nus_c_string_send() function works. another thing I tried is using a timer of 1 sec to call ble_nus_c_string_send(). that also worked.
I don't really know how to start analyzing this problem and would be happy for an advice.
thanks