AnsweredAssumed Answered

Bootloader and interrupts in user application

Question asked by slinko.natali on May 3, 2012
Latest reply on Dec 6, 2012 by Evert
Hello everyone!

Help me, please, to understand where is the problem.
I have my own bootloader, located at 0x08000000. And user application I locate at 0x08019000.
The algorithm of my bootloader is:
1.After reset I have timeout at about 5 sec. If the connection between MCU and PC throught flash loader demonstrator is set, I load program and reboot MCU by NVIC_SystemReset().
2. If there is no connection between MCU and PC and 5 sec left I load user application.
I use for connection between MCU and PC USART2. And in user application I want to use it too, but in another way. 
It is all right when I load symple programm which does not use interrupts, it works correctly. But when I load programm that use USART2 and interrupts from USART2 the programm doesn't work. 
The code is:
void    JumpToApplication   (uint32_t ApplicationAddress)
{
typedef     void        (*pFunction)(void);
            pFunction   Jump_To_Application;
            uint32_t    JumpAddress;
                                                 
 NVIC_SetVectorTable(NVIC_VectTab_FLASH, USER_PROG_OFFSET);
 if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000) //Проверяем, есть ли что-нибудь по адресу (там должно лежать значение SP для приложения, его кладет линкер)
    
      JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);          //Адрес перехода из вектора Reset
      Jump_To_Application = (pFunction) JumpAddress;                    //Указатель на функцию перехода
      __set_MSP(*(__IO uint32_t*) ApplicationAddress);                  //Устанавливаем SP приложения
      Jump_To_Application();                                            //Запускаем приложение
    }
}
  
/*====================================================================================================*/
int main    (void)
{
    InitBootCLK();
    InitTimer(TIM2, 100000);//4сек
    NVICTmrInit(TIM2,TIM2_IRQn,1);
    InitUSARTPeriph(USART_SPEED,USART_Pins,BOOT_USART,USART_Interrupt);
    TmrOn(TIM2);
    TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
          
    while (!BootLoaderStack.TIMEOUT_FLAG){} //ждем 4 секунды после запуска
      
    switch  (BootLoaderStack.TIMEOUT_FLAG)
            {
                case    TIMER_SRC:  {
                                        AppAddr=((ReadFromFlash(PRG_ADDR_CELL)<<16)|ReadFromFlash(PRG_ADDR_CELL+2));//+USER_PROG_OFFSET;
      
                                        if (((AppAddr>=FLASH_START_ADDR)&&(AppAddr<=FLASH_END_ADDR))||((AppAddr>=SRAM_START_ADDR)&&(AppAddr<=SRAM_END_ADDR))) 
                                            {
                                            RCC->APB1RSTR=0;
                                                RCC->APB2RSTR=0;
                                            RCC->APB1ENR=0;
                                            RCC->APB2ENR=0;
                                            TmrOff(TIM2);
                                            TIM_ITConfig(TIM2,TIM_IT_Update,DISABLE);
                                            USART_Cmd(USART2,DISABLE);
                                            USART_DeInit(USART2);
                                            USART_ITConfig(USART2,USART_IT_TC,DISABLE);
                                            USART_ITConfig(USART2,USART_IT_RXNE,DISABLE);  */
                                            __disable_irq ();
                                            JumpToApplication(AppAddr);
                                            }
                                            else
                                                {
                                                 while (1)
                                                        {
                                                            BootLoaderProcessing();
                                                            if (BootLoaderStack.APPLICATION_READY_FLAG)
                                                                NVIC_SystemReset(); 
                                                        }   
                                                }
                                        break;
                case    BOOT_SRC:   
                                    {   
                                     while (1)
                                                        {
                                                            BootLoaderProcessing();
                                                            if (BootLoaderStack.APPLICATION_READY_FLAG)
                                                                NVIC_SystemReset(); 
                                                        
                                    }   break;
                default:                break;
            } }
 

Outcomes