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

HardFault error when writing to characteristic in uart interrupt

Hello everyone,

When i get message from uart, i need to update my custom service's characteristic. I tried the code in the below, sd_ble_gatts_value_set function gives me HardFault error.

Am I doing something wrong to add characteristic? how should I do?

S130, SDK11

Code: uart_event_handle function

        case APP_UART_DATA_READY:
        UNUSED_VARIABLE(app_uart_get(&data_array[index]));
		
		if(index == 5) {
			if(data_array[0] == '$') {
				value.len = 5;
				value.offset = 0;
				uint8_t data[5];
				for(int i = 0; i < 5; i++) {
					data[i] = data_array[index + i];
				}
				value.p_value = data;
				if(m_connected) {
					err_code = sd_ble_gatts_value_set(m_kcomms.conn_handle, m_kcomms.product_char_handles.value_handle, &value);
					APP_ERROR_CHECK(err_code);
				}
			}
			index = -1;
		}
		
		index++;
        break;

Characteristic code:

I changed to SET_OPEN from NO_ACCESS , vlen = 1 and to USER from STACK but nothing changed.

    ble_gatts_char_md_t char_md;
ble_gatts_attr_md_t cccd_md;
ble_gatts_attr_md_t attr_md;
    ble_gatts_attr_t    attr_char_value;

ble_uuid_t ble_uuid;

BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
cccd_md.vloc = BLE_GATTS_VLOC_STACK;

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

char_md.char_props.read   = 1;
char_md.char_props.write  = 1;
char_md.p_char_user_desc  = NULL;
char_md.p_char_pf         = NULL;
char_md.p_user_desc_md    = NULL;
char_md.p_cccd_md         = &cccd_md;
char_md.p_sccd_md         = NULL;

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

ble_uuid128_t base_uuid = {0x11, 0xFE, 0xD4, 0x94, 0xEA, 0xFE, 0xEC, 0x82, 0x20, 0x4B, 0x6E, 0x65, 0x1A, 0xC1, 0xCD, 0x9F};
uint32_t err_code;
err_code = sd_ble_uuid_vs_add(&base_uuid, &p_kcomms->uuid_type);
APP_ERROR_CHECK(err_code);

ble_uuid.type = p_kcomms->uuid_type;
ble_uuid.uuid = 0xC11A;

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

BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm);
attr_md.vloc       = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth    = 0;
attr_md.wr_auth    = 0;
attr_md.vlen       = 0;

attr_char_value.p_uuid       = &ble_uuid;
attr_char_value.p_attr_md    = &attr_md;
attr_char_value.init_len     = 0;
attr_char_value.init_offs    = 0;
attr_char_value.max_len      = MAX_CHARACTERISTIC_VALUE;
attr_char_value.p_value     = NULL;

return sd_ble_gatts_characteristic_add(p_kcomms->service_handle, &char_md,
                                           &attr_char_value,
                                           &p_kcomms->stock_info_char_handles);
Parents Reply Children
Related