cancel
Showing results for 
Search instead for 
Did you mean: 

No timer interrrupt after switch to user application

sde c.1
Senior II

STM32G473VC, custom board.

I use an own bootloader which resides at address 0x00000000 , the user application resides at 0x00008000.

I did set external files correct to use the bootloader

in user application

system_stm32g4xx.c : #define VECT_TAB_OFFSET     0x00008000U 

STM32G473VCTX_FLASH.ld : FLASH  (rx)  : ORIGIN = 0x8008000,  LENGTH = 220K

in bootload application

STM32G473VBTX_FLASH.ld : FLASH  (rx)  : ORIGIN = 0x8000000,  LENGTH = 32K

in bootloader we use this code to jump to the user application

void deinitEverything()
{
	//-- reset peripherals to guarantee flawless start of user application
	HAL_TIM_Base_DeInit(&htim6);
	HAL_CRC_DeInit(&hcrc);
	HAL_SPI_DeInit(&hspi2);
	HAL_NVIC_DisableIRQ(DMA1_Channel2_IRQn);
	HAL_NVIC_DisableIRQ(DMA1_Channel1_IRQn);
	HAL_NVIC_DisableIRQ(EXTI15_10_IRQn);
	HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1);
	HAL_RCC_DeInit();
	HAL_DeInit();
	SysTick->CTRL = 0;
	SysTick->LOAD = 0;
	SysTick->VAL = 0;
}
 
static void jumpToApp(const uint32_t address)
{
	const JumpStruct* vector_p = (JumpStruct*)address;
 
	deinitEverything();
 
	/* let's do The Jump! */
    /* Jump, used asm to avoid stack optimization */
    asm("msr msp, %0; bx %1;" : : "r"(vector_p->stack_addr), "r"(vector_p->func_p));
}

In user application we use this code to jump to bootloader

HAL_NVIC_SystemReset();

timer 7 is used as Timebase Source, FreeRTOS is also running.

We used this bootloader setup successfully in many other projects , but in this one the timer 7 interrupt stops interrupting if we jump to bootload code and back to user application.

This cause HAL_IncTick() not getting called, and uwTick staying at 0 . Which cause HAL_MspInit() ... HAL_SYSCFG_EnableVREFBUF() run in an endless loop.

The only different with other projects is that we use SPI in this bootloader to bootload , where we use UART in all other projects.

I checked the timer 7 registers which seems all fine .

0693W00000KZvjDQAT.pngthe strange thing is that both bootloader and user application runs correctly after a reset or power down - up cycle. Bootloader starts first and starts user application which runs fine. But when i use (SPI) commands to switch to bootloader and back to user application, then the TMR7 interrupt stops working.

What else can i check to find out why timer 7 is not firing an interrupt?

1 ACCEPTED SOLUTION

Accepted Solutions

i have removed __disable_irq which i have added the past days in the bootloader code while i was searching for a solution... now it works.

i don't understand 100% why, i guess i need more knowledge about the STM32 NVIC interrupt system to know whats going on. But good documentation about this part is hard to get .

anyway , Thank you for assisting !

View solution in original post

11 REPLIES 11
TDK
Guru

Do you set SCB->VTOR to the correct value within your application? Are interrupts enabled globally? Is the timer's NVIC interrupt enabled?

If you feel a post has answered your question, please click "Accept as Solution".

SCB->VTOR shows the expected 0x8008000 in debugger.

interrupts are enabled in NVIC settings

as a test i have added this code in the beginning of the user application, which did not help.

int main(void)
{
  /* USER CODE BEGIN 1 */
   HAL_NVIC_EnableIRQ(TIM7_DAC_IRQn);
  /* USER CODE END 1 */

sde c.1
Senior II

i've read all i can about NVIC and have found some extra information trough debugger.

The moment the interrupts are not firing NVIC_ISER1 has value 0x800100, which means EXTI15_10_IRQn and TIM7_DAC_IRQn interrupts are activated. While timer 7 DIER and CR1 registers are also correctly initialized .

The NVIC_ICER1 contains the same value.

NVIC ISPR1 and ICPR1 (pending set and reset) contains also set bits, while these are all 0 when everything works fine. Can that be the cause no interrupts are fired?

I did not find a way to reset these registers at the start of the user application.

I found out no interrupt at all is fired while i EXTI interrupts and TMR7 should interrupt. Is there a register which can block all interrupts?

__enable_irq() and __disable_irq() will globally control interrupts.
If you feel a post has answered your question, please click "Accept as Solution".
sde c.1
Senior II

can't find whats wrong, __enable_irq() at the first line of main, does not help neither. Timer is activated and interrupt tmr7 is enabled in timer 7 registers.

the NVIC registers are the same compared with a working version.

What else is needed to execute an interrupt ? All registers looks correct, but there comes no signal handler ....

Read out SBC_ICSR and check/post.

JW

TDK
Guru

Are you jumping to the app from within an interrupt? If so, it's still in the interrupt so others won't fire unless they have higher priority.

If you feel a post has answered your question, please click "Accept as Solution".

this was the case, i have changed the code now so i jump to application when no interrupt is serving, but the outcome is the same

It's a state machine, gotta be an answer somewhere. Interrupts don't stop firing for no reason, we've covered all the possible reasons above.
If you feel a post has answered your question, please click "Accept as Solution".