2024-01-17 12:35 AM
Good morning,
I am working with a board mounting a STM32L0x3 microcontroller. My SystemCoreClock is 32 MHz and TIM12 is clocked at 4 MHz. TIM12 has been configured in order to work in Capture Mode on Channel 1 (falling edge).
The ISR does what is listed below
void TIM21_IRQHandler(void)
{
/* USER CODE BEGIN TIM21_IRQn 0 */
/* USER CODE END TIM21_IRQn 0 */
GPIOB->BSRR = GPIO_PIN_11 ;
/* USER CODE BEGIN TIM21_IRQn 1 */
/* USER CODE END TIM21_IRQn 1 */
}
To my surprise, using an oscilloscope, I noted that time elapsed since the falling edge of the signal the other pin is set is about 1us.
Why do I have all this latency?
Thanks to all who will support me
2024-01-17 01:19 AM
For an interrupt at least some up to 16 registers need to be pushed on the stack , the IRQ code needs to be fetched from with flash wait state and finally the GPIO needs to be set. This will take some cycles and at 32 MHz 1 microsecond are only 32 cycles.
2024-01-17 01:29 AM
How many clock cyles are needed to fetch the IRQ and set the output?
2024-01-17 02:08 AM - edited 2024-01-17 02:09 AM
2024-01-18 02:24 AM
I have found at this link that the interrupt latency for a CortexM0+ should be 15 clock cycles.
https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/beginner-guide-on-interrupt-latency-and-interrupt-latency-of-the-arm-cortex-m-processors
Even if I consider that this instruction
GPIOB->BSRR = GPIO_PIN_11 ;
could take 5 clock cycles, why should I get 32 cycles you mentioned?
2024-01-18 02:47 AM
Ok, and what did you set as optimizer level ? If you want it fast, need -O2 or -Ofast , otherwise code is not at the expected speed, but good only for debug.
-> project settings
2024-01-18 05:46 AM
Do you count Flash latency?
2024-01-18 05:50 AM
> I have found at this link that the interrupt latency for a CortexM0+ should be 15 clock cycles.
I stand corrected; wasn't aware of the difference in CM0/CM0+. Thanks.
> Even if I consider that this instruction
> GPIOB->BSRR = GPIO_PIN_11 ;
> could take 5 clock cycles,
Why would that be the case?
Post disasm of the ISR.
What's the FLASH latency?
JW
2024-02-15 08:19 AM
Hi @Dave94
The forum moderator had marked your post as needing a little more investigation and direct support. An online support case has been created on your behalf, please stand by for just a moment and you will hear from us.
Regards,
Billy
2024-02-15 09:01 AM