STM32L062 hard fault with timer enabled
I am using Segger Embedded Studio 6.32 to develop a project for the STM32L062K8U6. While there are some start-up files created by the SES project wizard, I am not using any pre-built libraries and developing all my own code based on information from the "RM0376 Reference manual Ultra-low-power STM32L0x2 advanced Arm®-based 32-bit MCUs" and related docs.
I am having a problem with a hard fault occurring every time I enable one of the timers. I have code to run a 500us timer delay that I have tested with timers 2, 6, 21, and 22 with the same result in each case. The main loop toggles an IO pin every time the overflow flag is set. Watching the output on the o'scope I can see that I am getting a correct 500us period, but no matter what timer is used, after 48 seconds of operation I end up in the default hard fault exception handler. I am at a loss to explain this behavior and have not had this issue with timers on other ST Cortex M0 chips.
Internet searches on this topic turn up a lot of threads that suggest that the problem may lie with the processor calling an ISR that doesn't exist. However, if that applies in my case it raises a lot of questions:
* Interrupts are not enabled globally, so why would the code attempt to vector to an ISR, and even then, why a hard fault instead of the default ISR created by the project wizard?
* If it's a timer based ISR, why does the code continue to operate with no errors for 48 seconds instead of doing the hard fault immediately after the first 500us?
* Problem happens if the UIE bit for the timer is set or not.
* Problem happens if WDT is enabled or not, and a WDT timer reset would be expected to restart the code rather than hard fault.
For an example state when I'm in the hard fault handler using TIM2 :
CR1 = 0x00000001
CR2 = 0x00000000
DIER = 0x00000001
DMAR = 0x00000001
SR = 0x0000001FAny thoughts would be appreciated.
