cancel
Showing results for 
Search instead for 
Did you mean: 

Jumping to Application

Lori B.
Associate III
Posted on May 13, 2014 at 16:53

Hi, I'm quite new with the ARM and STM32 world.

I'm developing an application wich has to load a bootloader and, at a certain point, jump to the main application. I'm using the STM32F4-Disco.

The bootload is quite complex, using FreeRTOS and STemWin, comunicating to an external device with USART periph.

Using a USB OTG drive which han an image.bin file on it (which is the main app code), I load it to a flash memory sector that for me is

APPLICATION_ADDRESS (uint32_t)0x08080000

 and then press a button on the touch-LCD for jumping to the loaded code.

The jumping function is:

cmd_Jump_To_Application(APPLICATION_ADDRESS)

void cmd_Jump_To_Application(uint32_t start_Address)

        {

                    USART_DeInit(USART2);

                    USART_DeInit(USART1);

                    RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);

                    RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);

                    RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);

                    RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);

                    RCC_DeInit();

                    __disable_irq();       

        uint32_t addressToJump = *(__IO uint32_t*) (start_Address + 4);

        pFunction Jump_To_Application = (pFunction) addressToJump;

    

         /* Initialize application's Stack Pointer */

         __set_MSP(*(__IO uint32_t*) start_Address);   

         /* Call Reset Handler */

         Jump_To_Application();

        }

Assuming that the downloading part to flash memory is right (I ported from the FW_Upgrade example, and debugging I can see what I expect in the application sector), there is something wrong. When I press the jump button I get a white screen and everything freezing and I can't start the main application.

I'm missing something for sure, maybe about stack or some other vector adress\init, but I can't understand what. Some suggestions? Thanks!
25 REPLIES 25
Lori B.
Associate III
Posted on May 22, 2014 at 11:26

Any help\suggestion? Thank you..

chen
Associate II
Posted on May 22, 2014 at 11:42

I could have swan I replied to this already! Must be the damn forum not accepting my replies again.

''After my main app launches, I get stucked in the USBH_OTG_ISR_Handler

I think that this is because I don' DeInit the USB properly before the jump!

I wrote a function

USBH_Stop(&USB_OTG_Core,&USB_Host)''

I think the problem is the USB stop that you are doing.

Instead try a USB soft Disconnect :

void USB_SoftDisconnect( void )

{

    // set bit SDIS in OTG_FS_DCTL reg

    USB_OTG_dev.regs.DREGS->DCTL |= 0x02;

}

Lori B.
Associate III
Posted on May 22, 2014 at 12:25

Ahah, no problem! You are too kind!

Did you mean something like this?

void USB_SoftDisconnect( USB_OTG_CORE_HANDLE *pdev )

{

    // set bit SDIS in OTG_FS_DCTL reg

    pdev->regs.DREGS->DCTL |= 0x02;

}

USB_SoftDisconnect( &USB_OTG_Core);

I tried! Doing so, I get an hard falut starting my app, instead of going into the otg_handler.

Not sure if better or worse! (I think worse)

chen
Associate II
Posted on May 22, 2014 at 13:27

''I tried! Doing so, I get an hard falut starting my app, instead of going into the otg_handler.

Not sure if better or worse! (I think worse)''

It is better I think. Before, your bootloader was stuck due to USB IRQ.

Now, your bootloader has started the application but you get a HardFault in Application.

Debug your application. Find out why you get hard fault.

(See if SysTick IRQ happens before it is set up - this happened to me).

Lori B.
Associate III
Posted on May 22, 2014 at 17:32

Actually it was stuck in the USB Handler, but already in the app, not in the bootloader!

Anyway I finally made it!

The problem was related to the interrupts. __disable_irq(); suspend all interrups but does not act on the registers, so as soon as something in the App sets an interrupt, everything start acting random!

I solved it writing this function and calling it just before the jump!

void USB_Interface_DeInit(void){

    RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_OTG_HS, ENABLE);

    RCC_AHB1PeriphResetCmd( RCC_AHB1Periph_OTG_HS, DISABLE);

    RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_OTG_HS, DISABLE);

        nvicStructure.NVIC_IRQChannel = OTG_HS_IRQn;

    nvicStructure.NVIC_IRQChannelPreemptionPriority = 15;

    nvicStructure.NVIC_IRQChannelSubPriority = 0;

    nvicStructure.NVIC_IRQChannelCmd = DISABLE;

    NVIC_Init(&nvicStructure);

}

Thank you again!!
Posted on May 22, 2014 at 18:25

I'm going to cross link this thread, as it picked up the SVC topic, and had similar issue with disabling interrupts vs servicing them in the application.

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

 

EDIT: Fixed DEAD LINK, Original from 22-May-2014

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..