Hi,
My setup:
* nRF52 DK
* nRF5_SDK_15.0.0_a53641a
* s132_nrf52_6.0.0
* SES V3.34b 64-bit.
I am struggling to properly use FDS module. I am using multiperipheral example, just for a training I would like to make something like this:
* write data to flash after button being pressed
* read data from flash after getting disconnected from a device.
I have followed lib_fds_usage and my code looks like this:
main.c
globals:
static fds_record_desc_t record_desc;
function definitions:
static void button_event_handler(uint8_t pin_no, uint8_t button_action) { ret_code_t err_code; switch (pin_no) { case LEDBUTTON_BUTTON: err_code = led_status_send_to_all(button_action); if (err_code == NRF_SUCCESS) { NRF_LOG_INFO("Sent button state change to all connected centrals."); /* ---- */ uint32_t const m_deadbeef = 0xDEADBEEF; static char const m_hello[] = "Hello, world!"; fds_record_t record; record.file_id = 0x0003; record.key = 0x3111; record.data.p_data = &m_deadbeef; record.data.length_words = 1; // jedno slowo to 4 bajty ret_code_t rc; rc = fds_record_write(&record_desc, &record); if(rc != FDS_SUCCESS) { NRF_LOG_INFO("write error"); } /* ---- */ //[pawel] } break; default: APP_ERROR_HANDLER(pin_no); break; } }
static void on_disconnected(ble_gap_evt_t const * const p_gap_evt) { ret_code_t err_code; uint32_t periph_link_cnt = ble_conn_state_peripheral_conn_count(); // Number of peripheral links. NRF_LOG_INFO("Connection 0x%x has been disconnected. Reason: 0x%X", p_gap_evt->conn_handle, p_gap_evt->params.disconnected.reason); if (periph_link_cnt == 0) { bsp_board_led_off(CONNECTED_LED); err_code = app_button_disable(); APP_ERROR_CHECK(err_code); } if (periph_link_cnt == (NRF_SDH_BLE_PERIPHERAL_LINK_COUNT - 1)) { // Advertising is not running when all connections are taken, and must therefore be started. advertising_start(); } /* -------- */ fds_flash_record_t flash_record; // fds_record_desc_t record_desc; fds_find_token_t ftok; //uint32_t *content; uint32_t *content = (uint32_t *) malloc (sizeof(uint32_t)); uint8_t iter = 0; /* It is required to zero the token before first use. */ memset(&ftok, 0x00, sizeof(fds_find_token_t)); /* Loop until all records with the given key and file ID have been found. */ while (fds_record_find(0x0003, 0x3111, &record_desc, &ftok) == FDS_SUCCESS) { iter++; if (fds_record_open(&record_desc, &flash_record) != FDS_SUCCESS) { /* Handle error. */ NRF_LOG_INFO("error opening"); } /* Access the record through the flash_record structure. */ content = (uint32_t *)(flash_record.p_data); //memcpy(zawartosc, flash_record.p_data, sizeof(uint32_t*)); /* Close the record when done. */ if (fds_record_close(&record_desc) != FDS_SUCCESS) { /* Handle error. */ NRF_LOG_INFO("error closing"); } } NRF_LOG_INFO("content %d %x" , iter, *(content)); /* --------- */ }
I get no errors, my terminal log looks like this:
<info> app: Multiperipheral example started.
<info> app: Connection with link 0x0 established.
<info> app: Sent button state change to all connected centrals.
<info> app: Sent button state change to all connected centrals.
<info> app: Connection 0x0 has been disconnected. Reason: 0x13
<info> app: content 26 2000FEB8
Why is it 0x2000FEB8 instead of 0xDEADBEEF? Where do I make a mistake?