analogdevicesinc / msdk

Software Development Kit for Analog Device's MAX-series microcontrollers
Apache License 2.0
60 stars 76 forks source link

Timer flag fails to switch upon first run MAX32690 (BLE) #906

Closed EricB-ADI closed 5 months ago

EricB-ADI commented 5 months ago

I keep running into an issue on the ME18 with the timer upon startup. It gets stuck waiting for an interrupt flag. This only happens upon first run after flash. A reset seems to fix it, and it can be repeatedly seen using the Bluetooth examples. Here is the backtrace

MXC_TMR_RevB_SetCount (tmr=tmr@entry=0x40012000, cnt=cnt@entry=0) at /home/eric-busch/Workspace/msdk/Libraries/CMSIS/../PeriphDrivers/Source/TMR/tmr_revb.c:404
404     while (!(tmr->intfl & MXC_F_TMR_REVB_INTFL_WRDONE_A)) {}
(gdb) bt
#0  MXC_TMR_RevB_SetCount (tmr=tmr@entry=0x40012000, cnt=cnt@entry=0) at /home/eric-busch/Workspace/msdk/Libraries/CMSIS/../PeriphDrivers/Source/TMR/tmr_revb.c:404
#1  0x10002bd6 in MXC_TMR_SetCount (tmr=tmr@entry=0x40012000, cnt=cnt@entry=0) at /home/eric-busch/Workspace/msdk/Libraries/CMSIS/../PeriphDrivers/Source/TMR/tmr_me18.c:338
#2  0x10004532 in MXC_TMR_Common_TO_Stop (tmr=tmr@entry=0x40012000) at /home/eric-busch/Workspace/msdk/Libraries/CMSIS/../PeriphDrivers/Source/TMR/tmr_common.c:54
#3  0x10002bf6 in MXC_TMR_TO_Stop (tmr=tmr@entry=0x40012000) at /home/eric-busch/Workspace/msdk/Libraries/CMSIS/../PeriphDrivers/Source/TMR/tmr_me18.c:358
#4  0x10004550 in MXC_TMR_Common_SW_Stop (tmr=tmr@entry=0x40012000) at /home/eric-busch/Workspace/msdk/Libraries/CMSIS/../PeriphDrivers/Source/TMR/tmr_common.c:95
#5  0x10002c0e in MXC_TMR_SW_Stop (tmr=tmr@entry=0x40012000) at /home/eric-busch/Workspace/msdk/Libraries/CMSIS/../PeriphDrivers/Source/TMR/tmr_me18.c:383
#6  0x10000658 in btnPressHandler (btnId=<optimized out>, state=<optimized out>) at dats_main.c:915
#7  0x100132c0 in palBtnCallback (pb=<optimized out>) at /home/eric-busch/Workspace/msdk/Libraries/Cordio/platform/targets/maxim/build/../../../../platform/targets/maxim/max32690/sources/pal_btn.c:103
#8  0x100044ce in MXC_GPIO_Common_Handler (port=port@entry=4) at /home/eric-busch/Workspace/msdk/Libraries/CMSIS/../PeriphDrivers/Source/GPIO/gpio_common.c:90
#9  0x100023f2 in MXC_GPIO_Handler (port=port@entry=4) at /home/eric-busch/Workspace/msdk/Libraries/CMSIS/../PeriphDrivers/Source/GPIO/gpio_me18.c:370
#10 0x10000cf0 in GPIOWAKE_IRQHandler () at /home/eric-busch/Workspace/msdk/Libraries/Boards/MAX32690/EvKit_V1/Source/board.c:94
#11 <signal handler called>
#12 0x10000fb0 in PB_RegisterCallbackRiseFall (pb=pb@entry=0, callback=callback@entry=0x10013249 <palBtnCallback>) at /home/eric-busch/Workspace/msdk/Libraries/MiscDrivers/PushButton/pb.c:90
#13 0x100132f4 in PalBtnInit (actCback=actCback@entry=0x10000631 <btnPressHandler>) at /home/eric-busch/Workspace/msdk/Libraries/Cordio/platform/targets/maxim/build/../../../../platform/targets/maxim/max32690/sources/pal_btn.c:129
#14 0x10000a70 in DatsStart () at dats_main.c:1027
#15 0x10000c04 in main () at main.c:269

I am gonna try to find the root cause, but I figured I would leave this here if anyone has seen it.

EricB-ADI commented 5 months ago

Here is the bad condition

(gdb) p *tmr
$8 = {
  cnt = 0,
  cmp = 0,
  pwm = 0,
  intfl = 0,
  ctrl0 = 0,
  nolcmp = 0,
  ctrl1 = 0,
  wkfl = 0
}
(gdb) p tmr_id
$9 = 2

This is the dump when it is good

(gdb) p/x *tmr
$5 = {
  cnt = 0x7,
  cmp = 0xefffffff,
  pwm = 0x0,
  intfl = 0x1000100,
  ctrl0 = 0x4060,
  nolcmp = 0x0,
  ctrl1 = 0x80000008,
  wkfl = 0x0
}

It appears the timer is not being enabled? May be a race condition in PalTimer for the BLE stack.

EricB-ADI commented 5 months ago

There is a spurious GPIO interrupt, during the initialization before the timer is enabled.