跳到主要内容

app_easy_timer not working on user_app_on_init

1 month 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

要使广告数据动态,但由于某种原因,在从user_app_on_init调用时无法启动计时器,但在从另一个地方调用时工作(如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)

任何想法为什么要从init开始的计时器?

谢谢

此致
Gustavo

接受答案!

1 month 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(); }

谢谢, PM_Dialog

1 month ago

gustavo.laureano 65 points

嗨PM_DIALOG.

谢谢,它有效,当我从adv_start用户回调开始时,我所做的唯一更改就是始终取消任何以前的计时器,否则它正在生成并行运行的多个计时器实例:

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 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?

谢谢!
Gustavo

1 month 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?

谢谢, PM_Dialog

1 month 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){//在Boost模式下,使DCDC转换器能够为已使用的GPIOS Syscntl_dcdc_turn_oN_in_in_In_Boost提供vbat_high供应Vbat_high(syscntl_dcdc_level_3v0);// rom修补程序patch_func();//初始化外设UART_INITIALIZE(UART1,&UART_CFG);gpio_configurepin(uartx_tx_gpio_port,uartx_tx_gpio_pin,输出,pid_uart1_tx,false);GPIO_CONFIGUREPIN(UARTX_RX_GPIO_PORT,UARTX_RX_GPIO_PIN,INPUT,PID_UART1_RX,FALSE);//启用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

1 month ago

PM_Dialog

Hi gustavo.laureano,

谢谢你的评论。要使用UART_REGISTER_RX_CB(),应定义CFG_UART1_SDK宏。ROM驱动程序与您看到此行为的原因不同。

谢谢, PM_Dialog