app_timer_set reset the system

7 posts / 0 new
Last post
giuseppe
Offline
Last seen:4 years 7 months ago
Expert
加入:2015-03-25 13:34
app_timer_set reset the system

Goodevening,
I have a problem with app_timer_set.
CFG_WDOG is undef.
I write a code that call periodically a function read_sensor every 300ms.

void read_sensor(.....){

***Reading sensor code***

//plain next wakeup
app_timer_set(SLEEP_OFF_MSG, TASK_APP, 29);
//plain next read after 300ms
app_timer_set(READ_SENSOR_MSG, TASK_APP, 30);

//go to sleep
app_timer_set(SLEEP_ON_MSG, TASK_APP, 0);
}
void sleep_on(...){
app_set_extended_sleep();
app_ble_ext_wakeup_on();
}
void sleep_off(...){
app_force_active_mode();
app_ble_force_wakeup();
app_ble_ext_wakeup_off();
}

The code work for a few seconds (about 20s) and then crashes.
If I delete app_timer_set(SLEEP_ON_MSG, TASK_APP, 0); from read_sensor and insert directly the instructions below then it work.

app_set_extended_sleep();
app_ble_ext_wakeup_on();

可能会出现什么问题?

Device:
YuanhangWu
Offline
Last seen:4 years 9 months ago
Expert
加入:2015-03-25 08:19
Hi, Joined.

Hi, Joined.
I think
app_ble_ext_wakeup_on();
is need external event to trigger.
This is a aspect.
hope to help you.

thanks,YuanhangWu.

giuseppe
Offline
Last seen:4 years 7 months ago
Expert
加入:2015-03-25 13:34
I thought the command app_ble

I thought the command app_ble_ext_wakeup_on(); was ignored when connection are active.
Anyway I removed the command. Now the system always crash every 3 minuts and 20 seconds.
It is shure that there is a problem with app_timer_set?

giuseppe
Offline
Last seen:4 years 7 months ago
Expert
加入:2015-03-25 13:34
I think that the problem is

I think that the problem is ke_timer. In the previous examples I used 3 timers. I try to use ke_timer_clear after that every timer fire, to make sure that resources were freed, but system reset too after 3 minuts and 20 seconds.
If I reduce the timers used to 2 the system crash after about 8 minuts.
If I use one timer the system seems to work....but for how long!!??
So I think there is a kernel bug in the management of the timer (stack underflow/overflow!?). Maybe better to use timer0 interrupt as a clock timer system, it is more reliable.

giuseppe
Offline
Last seen:4 years 7 months ago
Expert
加入:2015-03-25 13:34
I removed all ke_timers and

I removed all ke_timers and the system restart anyway.
After some tests I was able to understand that the problem is caused by the allocation of memory of ke_msg_alloc in the function that periodically was called by timer. This function send a message. In the receiver of the message was missing the return(KE_MSG_CONSUMED). So I conclude that the memory of messages was never released by the kernel and when it was full the MCU was resetted.
In RW-BT-KERNEL-SW-FS datasheet on ke_msg_send description we find:
"Send a message previously allocated with any ke_msg_alloc()-like functions.The kernel will take care of freeing the message memory.".
But only when KE_MSG_CONSUMED is returned the memory is freed.

So I ask.... is there a way to know what causes the reset of the MCU (watchdog stak memory full...etc) without having to go attemps?
Thanks very much

MT_dialog
Offline
Last seen:4 days 16 hours ago
工作人员
加入:2015-06-08 11:34
Hi guiseppe,
giuseppe
Offline
Last seen:4 years 7 months ago
Expert
加入:2015-03-25 13:34
Ok thank you.

Ok thank you.

Topic locked