Associate III
August 5, 2023
Question
inline assembly macro inconsistent
- August 5, 2023
- 14 replies
- 5346 views
I am using the STM32F746VET6. I am aware that assembly instructions do not have a guaranteed in execution time, however I am surprised how consistently inconsistent my inline assembly macro is behaving. I'm really hoping there is just a mistake in the macro that I can fix. My IVT is in ITCM (memory address 0x0) and the ISR is also in ITCM (memory address 0x200). The 1st, 2nd, 4th, 5th, and 6th pin states show very close to the same delay every time. The 3rd and 7th pin states are always ~1.7x the others, however.
This is the macro:
#define nop_delay_def(delay_var) __asm volatile (".Lloop%=: \n\t" \
" subs %[delay], #1 \n\t" \
" bne.n .Lloop%= " \
: \
: [delay] "r" (delay_var))
And this is the ISR:
void __attribute__((optimize("O0"), section(".itcm_text"))) TIM1_TRG_COM_TIM11_IRQHandler(void) {
PULSER1_GPIO_Port->ODR |= PULSER1_IN1_POS_Pin;
nop_delay_def(60);
PULSER1_GPIO_Port->ODR |= PULSER1_IN2_POS_Pin;
nop_delay_def(60);
PULSER1_GPIO_Port->ODR &= ~PULSER1_IN1_POS_Pin;
nop_delay_def(60);
PULSER1_GPIO_Port->ODR &= ~PULSER1_IN2_POS_Pin;
nop_delay_def(60);
PULSER1_GPIO_Port->ODR |= PULSER1_IN1_POS_Pin;
nop_delay_def(60);
PULSER1_GPIO_Port->ODR |= PULSER1_IN2_POS_Pin;
nop_delay_def(60);
PULSER1_GPIO_Port->ODR &= ~PULSER1_IN1_POS_Pin;
nop_delay_def(60);
PULSER1_GPIO_Port->ODR &= ~PULSER1_IN2_POS_Pin;
HAL_IWDG_Refresh(&hiwdg); // kick the watch dog since FreeRTOS is suspended
TIM11->SR = 0;
}// TIM1_TRG_COM_TIM11_IRQHandler
I have attached a scope shot at the bottom. There is no jitter or variation in the pulses. They show that the macro is inconsistent consistently.
