Skip to main content

app_easy_timer not working on user_app_on_init

4 weeks ago

app_easy_timer not working on user_app_on_init

Posted bygustavo.laureano65 points 5 replies
0 upvotes

Hi,

I followed this guide:

http://lpccs-docs.dialog-semiconductor.com/Tutorial_SDK6/adv_data.html

to make the advertising data dynamic, but for some reason the timer is not started when called from user_app_on_init, but works when called from another place (like on_disconnect)

The function in being called inside app_on_init (checked with breakpoint) and it is not falling into the "return EASY_TIMER_INVALID_TIMER" (also checked with breakpoint)

Any ideas why would the timer not start from init?

Thanks

Best Regards
Gustavo

accepted answer!

3 weeks ago

PM_Dialog

Hi Gustavo,

谢谢你的问题。我会recommend setting up the timer after the user_app_on_init(). Please try the following changes:

In user_config.h :

#define USER_ADVERTISE_DATA "\x12\x21\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x00"

In user_callback_config.h :

.default_operation_adv = user_app_adv_start, .app_on_init = user_app_on_init,

In user_empty_peripheral_template.h :

void user_app_adv_start(void); void user_app_on_init(void);

In user_empty_peripheral_template.c :

uint8_t my_counter __SECTION_ZERO("retention_mem_area0") ; // @RETENTION MEMORY timer_hnd app_adv_data_update_timer_used __SECTION_ZERO("retention_mem_area0"); void update_adv_data() { my_counter++; // Copy the counter value into the advertising data (ignore the scan response data) uint8_t adv_data[USER_ADVERTISE_DATA_LEN]; memcpy(&adv_data, USER_ADVERTISE_DATA, USER_ADVERTISE_DATA_LEN); // Load the counter value into the last octet of the advertising data adv_data[USER_ADVERTISE_DATA_LEN -1] = my_counter; // Update the advertising data app_easy_gap_update_adv_data(adv_data, USER_ADVERTISE_DATA_LEN, NULL, NULL); // Restart the timer app_adv_data_update_timer_used = app_easy_timer(100, update_adv_data); // One second one-shot timer } void user_app_adv_start(void) { app_adv_data_update_timer_used = app_easy_timer(100, update_adv_data); // One second one-shot timer app_easy_gap_undirected_advertise_start(); } void user_app_on_init() { my_counter = 0; // After we have initialized our variable, we call the default handler default_app_on_init(); }

Thanks, PM_Dialog

3 weeks ago

gustavo.laureano 65 points

Hi PM_Dialog

Thanks, It works when I start from the adv_start user callback, the only change I made was to always cancel any previous timer, otherwise it was generating multiple timer instances running in parallel:

void user_app_adv_start(void) { app_easy_timer_cancel(app_adv_data_update_timer_used); app_adv_data_update_timer_used = app_easy_timer(APP_ADV_DATA_UPDATE_TO, adv_data_update_timer_cb); // One second one-shot timer app_easy_gap_undirected_advertise_start(); }

But do you have any idea why the timer cannot be started from the app_init callback?
I searched the documentation and there is no explicit reason why it would not work..

And another (unrelated) question:
I had problems using the UART RX interrupt when using the UART ROM code on the DA14531 (with #undef CFG_UART1_SDK), it never calls the registered callback, and only works when I set to use the SDK UART implementation (#define CFG_UART1_SDK), but I found no information stating why the ROM code would not work, is this a bug on the ROM code? or am I required to always use the compiled driver when dealing with interrupts?

Thanks!
Gustavo

3 weeks ago

PM_Dialog

Hi gustavo.laureano,

Can you please share the user_app_on_init() and the UART function that you are using in your side?

Thanks, PM_Dialog

3 weeks ago

gustavo.laureano 65 points

Here are the relevant parts:

Peripheral initialization on user_periph_setup.c

静态常量uart_cfg_t uart_cfg = {.baud_rate =UART_BAUDRATE_115200, .data_bits = UART_DATABITS_8, .parity = UART_PARITY_NONE, .stop_bits = UART_STOPBITS_1, .auto_flow_control = UART_AFCE_DIS, .use_fifo = UART_FIFO_DIS, .tx_fifo_tr_lvl = UART_TX_FIFO_LEVEL_0, .rx_fifo_tr_lvl = UART_RX_FIFO_LEVEL_0, .intr_priority = 2, }; void periph_init(void) { // In Boost mode enable the DCDC converter to supply VBAT_HIGH for the used GPIOs syscntl_dcdc_turn_on_in_boost(SYSCNTL_DCDC_LEVEL_3V0); // ROM patch patch_func(); // Initialize peripherals uart_initialize(UART1, &uart_cfg); GPIO_ConfigurePin(UARTx_TX_GPIO_PORT, UARTx_TX_GPIO_PIN, OUTPUT, PID_UART1_TX, false); GPIO_ConfigurePin(UARTx_RX_GPIO_PORT, UARTx_RX_GPIO_PIN, INPUT, PID_UART1_RX, false); // Enable the pads GPIO_set_pad_latch_en(true); }

Code on my user.c:

static void uart_read_cb(uint16_t length) { // Push the received byte into the ring-buffer ringbuffer_add(&ringbuffer_inst_rx, &rxbuf_cb); // Start the next asynchronous read of 1 character. uart_receive(UART1, &rxbuf_cb, 1, UART_OP_INTR); } void user_app_on_init(void) { ringbuffer_init(&ringbuffer_inst_rx, ringbufer_buffer_rx, sizeof(uint8_t), 64); uart_register_rx_cb(UART1, uart_read_cb); uart_receive(UART1, &rxbuf_cb, 1, UART_OP_INTR); /* Start UART reception */ default_app_on_init(); }

Sending data (with uart_send in blocking mode) always works, but receiving data with interrupts only works when I #define CFG_UART1_SDK , otherwise uart_read_cb is never called

2 weeks ago

PM_Dialog

Hi gustavo.laureano,

Thanks for your comment. In order to use the uart_register_rx_cb(), the CFG_UART1_SDK macro should be defined. The ROM driver is different that’s why you see this behavior.

Thanks, PM_Dialog