Skip to main content
Dawid Kozub
Associate II
June 12, 2017
Question

No interrupts after jump to main program from custo bootloader (HAL libraires)

  • June 12, 2017
  • 8 replies
  • 1709 views
Posted on June 12, 2017 at 14:25

Hello Community,

I have problem with starting main program after jump from bootloader. I am using ECLIPSE with SW4STM32 and CubeMX.

Ok, what I did:

1. I writed bootloader which is prepared with settings: Linker file: ——————————————————————————– /* Specify the memory areas */ MEMORY { BOOTLOADER (rx): ORIGIN = 0x08000000, LENGTH = 24K FIRMWARE (rx) : ORIGIN = 0x08006000, LENGTH = 256K – 24K RAM (xrw) : ORIGIN = 0x200000C0, LENGTH = 32K – 192 /* 192 for vector table */ } /* Main app start address symbol */ _main_app_start_address = 0x08006000;

/* For main application, change BOOTLOADER by FIRMWARE */

REGION_ALIAS(“FLASH�?, BOOTLOADER ); ——————————————————————————– 2. Jump function:

// disable global interrupt
__disable_irq();
 // Disable all peripheral interrupts
 HAL_NVIC_DisableIRQ(SysTick_IRQn);
 HAL_NVIC_DisableIRQ(WWDG_IRQn);
 HAL_NVIC_DisableIRQ(RTC_IRQn);
 HAL_NVIC_DisableIRQ(FLASH_IRQn);
 HAL_NVIC_DisableIRQ(RCC_IRQn);
 HAL_NVIC_DisableIRQ(EXTI0_1_IRQn);
 HAL_NVIC_DisableIRQ(EXTI2_3_IRQn);
 HAL_NVIC_DisableIRQ(EXTI4_15_IRQn);
 HAL_NVIC_DisableIRQ(DMA1_Channel1_IRQn);
 HAL_NVIC_DisableIRQ(DMA1_Channel2_3_IRQn);
 HAL_NVIC_DisableIRQ(DMA1_Channel4_5_IRQn);
 HAL_NVIC_DisableIRQ(ADC1_IRQn);
 HAL_NVIC_DisableIRQ(TIM1_BRK_UP_TRG_COM_IRQn);
 HAL_NVIC_DisableIRQ(TIM1_CC_IRQn);
 HAL_NVIC_DisableIRQ(TIM3_IRQn);
 HAL_NVIC_DisableIRQ(TIM6_IRQn);
 HAL_NVIC_DisableIRQ(TIM7_IRQn);
 HAL_NVIC_DisableIRQ(TIM14_IRQn);
 HAL_NVIC_DisableIRQ(TIM15_IRQn);
 HAL_NVIC_DisableIRQ(TIM16_IRQn);
 HAL_NVIC_DisableIRQ(TIM17_IRQn);
 HAL_NVIC_DisableIRQ(I2C1_IRQn);
 HAL_NVIC_DisableIRQ(I2C2_IRQn);
 HAL_NVIC_DisableIRQ(SPI1_IRQn);
 HAL_NVIC_DisableIRQ(SPI2_IRQn);
 HAL_NVIC_DisableIRQ(USART1_IRQn);
 HAL_NVIC_DisableIRQ(USART2_IRQn);
 HAL_NVIC_DisableIRQ(USART3_6_IRQn);
 // main app start address defined in linker file
 extern uint32_t _main_app_start_address;
 uint32_t MemoryAddr = (uint32_t)&_main_app_start_address;
 uint32_t *pMem = (uint32_t *)MemoryAddr;
 // First address is the stack pointer initial value
 __set_MSP(*pMem); // Set stack pointer
 // Now get main app entry point address
 pMem++;
 void (*pMainApp)(void) = (void (*)(void))(*pMem);
 // Jump to main application (0x0800 6004)
 pMainApp();�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

3. I writedsimply FIRMWARE program which blinking one led using while loop and shoud blinking second led using IRQs –> void HAL_SYSTICK_Callback(void);

Blinking by IRQs not working. Blinking by while loop is working

4. Linker file from FIRMWARE:

——————————————————————————– /* Specify the memory areas */ MEMORY { BOOTLOADER (rx): ORIGIN = 0x08000000, LENGTH = 24K FIRMWARE (rx) : ORIGIN = 0x08006000, LENGTH = 256K – 24K RAM (xrw) : ORIGIN = 0x200000C0, LENGTH = 32K – 192 /* 192 for vector table */ } /* Main app start address symbol */ _main_app_start_address = 0x08006000;

/* For main application, change BOOTLOADER by FIRMWARE */

REGION_ALIAS(“FLASH�?, FIRMWARE ); ——————————————————————————–

5. In FIRMWARE program first function in main is Remap_Table();

void Remap_Table(void)
{
 // Copy interrupt vector table to the RAM.
 volatile uint32_t *VectorTable = (volatile uint32_t *)0x20000000;
 uint32_t ui32_VectorIndex = 0;
 for(ui32_VectorIndex = 0; ui32_VectorIndex < 48; ui32_VectorIndex++)
 {
 VectorTable[ui32_VectorIndex] = *(__IO uint32_t*)((uint32_t)FIRMWARE_START_ADDR + (ui32_VectorIndex << 2));
 }
 __HAL_RCC_AHB_FORCE_RESET();
// Enable SYSCFG peripheral clock
 __HAL_RCC_SYSCFG_CLK_ENABLE();
 __HAL_RCC_AHB_RELEASE_RESET();
// Remap RAM into 0x0000 0000
 __HAL_SYSCFG_REMAPMEMORY_SRAM();
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

I tried set __enable_irq(); after Remap_table(); and before main while loop and in other places from Remap_table() to main while loop and it does not work.

6. I did test with FIRMWARE and set in linker: ——————————————————————————– MEMORY { BOOTLOADER (rx): ORIGIN = 0x08000000, LENGTH = 24K FIRMWARE (rx) : ORIGIN = 0x08006000, LENGTH = 256K – 24K RAM (xrw) : ORIGIN = 0x200000C0, LENGTH = 32K – 192 /* 192 for vector table */ } /* Main app start address symbol */ _main_app_start_address = 0x08006000;

/* For main application, change BOOTLOADER by FIRMWARE */

REGION_ALIAS(“FLASH�?, BOOTLOADER); ——————————————————————————– then I deleted Remap function and __enable_irq();, compiled it and writed it to MCU by programmer –> blinking by while loop and IRQs worked good.

I heard about problem with starting FIRMWARE after custom bootloader witch is writed with HAL libraries. I think, I have this problem.Can someone give me some advice ?

MCU is STM32F030RCT6

Regards

Dawid

    This topic has been closed for replies.

    8 replies

    Tesla DeLorean
    Guru
    June 12, 2017
    Posted on June 12, 2017 at 15:11

    Is the boot loader calling from inside an interrupt?

    You would definitely need the __enable_irq() if you disable it previously, the processor isn't going to magically reenable them via the reset handler.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Dawid Kozub
    Associate II
    June 12, 2017
    Posted on June 12, 2017 at 16:04

    Yes, jump function is inside interrupt.

    __enable_irq(): is present  in my main app after remap of course
    Tesla DeLorean
    Guru
    June 12, 2017
    Posted on June 12, 2017 at 16:24

    >>Yes, jump function is inside interrupt.

    That is likely to be problematic, you should consider manipulating the stack frame so it returns to the application code rather than jumping from the interrupt state.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Dawid Kozub
    Associate II
    June 12, 2017
    Posted on June 12, 2017 at 16:36

    Yeeeeees !   It is working ! It was a problem.

    Thank You very much. I really appreciate that.

    For me topic is closed. Problem solved !

    Best regards

         Dawid Kozub

    Nesrine M_O
    Associate
    June 12, 2017
    Posted on June 12, 2017 at 17:13

    Hi

    dawid

    Dawid Kozub wrote:

    Yeeeeees ! It is working ! It was a problem.

    Thank You very much. I really appreciate that.

    For me topic is closed. Problem solved !

    Best regards

    Dawid Kozub

    https://community.st.com/0D50X00009bMM5DSAW