Hi Frank, Your BSP does not reserve any stack for interrupts. RxTimeoutTimer just happened to be corrupted by stack during interrupt handling. If you provide a section .stack somewhere you would probably run to the link problem. So you have to reduce tasks stack size or some variables to fix the issue.
br Jerzy pon., 20 kwi 2020 o 00:54 Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl> napisał(a): > Frank, > > I checked what you wrote about timers on STM32F051C8 and TIM2 was not > working since > there was some case missing in some switch statement, other timers worked > just fine on this MCU. > There is pending PR to fix this TIM2 > https://github.com/apache/mynewt-core/pull/2274 > I tried your code and it works (except that I don't have a lora module). > The only thing that was causing problems was those two lines: > #define MCU_GPIO_NC MCU_GPIO_PORTA(14) > #define SX1276_DIO0 MCU_GPIO_PORTA(13) > which when used mess up SWD lines and the debugger has a major problem. > > br > Jerzy > > > pt., 17 kwi 2020 o 00:18 Frank <myn...@hackdaworld.org> napisał(a): > >> Hi all, >> >> I tried porting MyNewt (apache-mynewt-core 1.8.0) to a custom board >> based on the STM32F051K8 MCU. >> >> Probably irrelevant board details: >> https://github.com/hackdaworld/gmote/tree/master/pcb/arm >> and likely more relevant software details: >> https://github.com/hackdaworld/gmote/tree/master/firmware/mynewt >> >> The first thing I noticed is, that a simple os_time_delay followed by >> console_printf loop only works if TIMER_0_TIM is one of the TIM1{5,6,7} >> timers. It's not working with timers 1, 2, 3, 14 and 6. There is no >> console output at all! >> >> Is there are an obvious reason for that, which I just can't see? >> >> Since timers 15, 16 and 17 work as expected, I continued with >> >> TIMER_0_TIM: 'TIM15' >> TIMER_1_TIM: 'TIM16' >> >> using TIMER_1 for LoRaWAN >> >> LORA_MAC_TIMER_NUM: "1" >> TIMER_1: "1" >> >> which leads to a crash and system restart due to an unhandled interrupt >> while trying an OTAA join: >> >> 000032 GMote on ARM >> 000093 Joining ... >> 001096 Hello World! 0 >> 001575 Unhandled interrupt (3), exception sp 0x20001530 >> 001575 r0:0x20001f2c r1:0x200010ac r2:0x00000627 r3:0x00000000 >> 001575 r4:0x0800515f r5:0x00000000 r6:0x20001738 r7:0x20001758 >> 001575 r8:0x00000000 r9:0x08006101 r10:0xffffffff r11:0xffffffff >> 001575 r12:0x0000003a lr:0x0800583d pc:0x08003a14 psr:0x21000000 >> 001575 ICSR:0x0440f003 >> 001575 task:loramac >> 001575 0x2000155c: 0x0800583d >> 001575 0x20001564: 0x0800b4c9 >> 001575 0x2000156c: 0x08006d43 >> 001575 0x20001570: 0x08000dfe >> 001575 0x2000157c: 0x00000000 >> 001575 0x20001584: 0x080016c5 >> 001575 0x20001588: 0x08006101 >> 001575 0x2000159c: 0x0800171b >> 001575 0x200015a4: 0x08006109 >> 001575 0x200015ac: 0x08000dcd >> >> The pc is at ... >> >> 0x8003a14 is in hal_timer_stop >> (repos/apache-mynewt-core/hw/mcu/stm/stm32_common/src/hal_timer.c:777). >> >> 777 TAILQ_REMOVE(&tmr->sht_timers, timer, link); >> >> which gets called by >> >> 0x800583d is in os_cputime_timer_stop >> (repos/apache-mynewt-core/kernel/os/src/os_cputime.c:113). >> >> and - going back the stack - probably gets called by >> >> 0x800b4c9 is in SX1276SetSleep >> (repos/apache-mynewt-core/hw/drivers/lora/sx1276/src/sx1276.c:911). >> >> 911 os_cputime_timer_stop(&TxTimeoutTimer); >> >> So, again, the timer is involved. And since I do not know much about the >> OS I looked around focusing on timer related stuff. One thing that looks >> wrong to me is the repeated init of the timer that is used for LoRaWAN. >> >> In hal_bsp.c >> - stm32_periph_create is called >> - lora_bsp_enable_mac_timer is provided >> The last one calls hal_timer_init on TIMER_1 at some point. >> But, TIMER_1 is likewise initialized by stm32_periph_create. >> >> However removing the init of TIMER_1 in stm32_periph_create_timers >> yields the same crash. >> >> I am going to investigate this further, since I want to get a better >> understanding of the OS anyways. However, I thought that maybe someone >> here already knows what's up or has a good advice where to look at. Any >> ideas? >> >> Thanks and all the best, >> Frank >> >> PS: More addresses located in stack: >> >> 0x8006d43 is in lora_mac_process_radio_tx >> (repos/apache-mynewt-core/net/lora/node/src/mac/LoRaMac.c:818). >> >> 818 uint32_t curTime = hal_timer_read(LORA_MAC_TIMER_NUM); >> >> 0x8000dfe is in os_arch_restore_sr >> (repos/apache-mynewt-core/hw/cmsis-core/src/ext/cmsis_gcc.h:131). >> >> 129 __STATIC_FORCEINLINE void __enable_irq(void) >> 130 { >> 131 __ASM volatile ("cpsie i" : : : "memory"); >> 132 } >> >> 0x80016c5 is in os_eventq_get >> (repos/apache-mynewt-core/kernel/os/src/os_eventq.c:145). >> >> 145 OS_ENTER_CRITICAL(sr); >> >> 0x8006101 is in lora_mac_task >> (repos/apache-mynewt-core/net/lora/node/src/lora_node.c:402). >> >> 400 void >> 401 lora_mac_task(void *arg) >> 402 { >> 403 /* Process events */ >> 404 while (1) { >> 405 os_eventq_run(&g_lora_mac_data.lm_evq); >> 406 } >> >> 0x800171b is in os_eventq_run >> (repos/apache-mynewt-core/kernel/os/src/os_eventq.c:196). >> >> 196 ev->ev_cb(ev); >> >> 0x8006109 is in lora_mac_task >> (repos/apache-mynewt-core/net/lora/node/src/lora_node.c:405). >> 400 void >> 401 lora_mac_task(void *arg) >> 402 { >> 403 /* Process events */ >> 404 while (1) { >> 405 os_eventq_run(&g_lora_mac_data.lm_evq); >> 406 } >> 407 } >> >> 0x8000dcd is in os_arch_task_return_handler >> (repos/apache-mynewt-core/kernel/os/src/arch/cortex_m0/os_arch_arm.c:154). >> 149 { >> 150 /* >> 151 * If you are stuck here it means that task finished by >> 152 * simple return which is not supported. >> 153 */ >> 154 while (1); >> 155 } >> >