cancel
Showing results for 
Search instead for 
Did you mean: 

How to Disable all Interrupts before jumping to Application.

dhiry2k1
Associate II
Posted on November 12, 2015 at 19:13

Hi All,

I am working on boot loader for STM32 and using DMA interrupts on USART1 for receiving and Transmitting Data. The same USART is used in Application as well with the same settings. I was using below code to jump to application:

LOG_INFO(''BootLoader Jumping to Application'');
timer_->Timer_Sleep(100);
// deinit interrupts, set address to reset handler, set stack pointer, and jump
uint32_t jumpAddress = 0x00000000;
__disable_irq();
typedef void (*pFunction)(void);
pFunction jumpToApp;
uint32_t startAddress = bootloaderUtilities_.getApplicationStartAddress();
NVIC_SetVectorTable(NVIC_VectTab_FLASH, startAddress - 0x08000000);
jumpAddress = *(__IO uint32_t*)(startAddress + 4);
jumpToApp = (pFunction)jumpAddress;
__set_MSP(*(__IO uint32_t*)startAddress);
jumpToApp();

But THIS does not work. when I jump to Application, it does jump to application but stuck in the application itself. if i change the code and disable that particular USART Rx Interrupt , Code works flawless below is the working code:

LOG_INFO(''BootLoader Jumping to Application'');
timer_->Timer_Sleep(100);
NVIC_InitTypeDef NVIC_InitStructure;
/* Disable the USART DMA Rx Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
NVIC_Init(&NVIC_InitStructure);
uint32_t jumpAddress = 0x00000000;
typedef void (*pFunction)(void);
pFunction jumpToApp;
uint32_t appStartAddress = getApplicationStartAddress();
NVIC_SetVectorTable(NVIC_VectTab_FLASH, appStartAddress - USER_FLASH_START_ADDRESS);
jumpAddress = *(__IO uint32_t*)(appStartAddress + 4);
jumpToApp = (pFunction)jumpAddress;
__set_MSP(*(__IO uint32_t*)appStartAddress);
jumpToApp();

But this is not the correct way to disable . Any one has any idea how can I disable all interrupts in Bootloader and then jump to Application and configure again. #stm32 #stm32 #dma #bootloader #usart
2 REPLIES 2
Posted on November 12, 2015 at 19:56

Ok, and what's the issue with switching off the interrupts at a peripheral level? You need code on the app side to be able to immediately service something it's not set itself up to handle otherwise. The RAM variables and stack are likely to be totally different, and unrelated, in the application vs the loader.

This is awfully tortured

NVIC_SetVectorTable(NVIC_VectTab_FLASH, appStartAddress - USER_FLASH_START_ADDRESS);

Surely just

SCB->VTOR = appStartAddress;

or

NVIC_SetVectorTable(appStartAddress, 0);

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
dhiry2k1
Associate II
Posted on November 12, 2015 at 21:47

Thanks Clive for your Response. yes I have disabled all the interrupts one by one and let the application handle those separately. I don’t want to bound application to specific boot loader or the peripheral , so my application is generic.

However in my boot loader, before jumping to my application, i have disabled all the peripheral i have used for my boot loader, so that Application is independent to chose which one it need to initialise or not.

Thanks a ton