cancel
Showing results for 
Search instead for 
Did you mean: 

Disabling USB

jdcowpland
Associate II
Posted on April 14, 2014 at 13:08

Does anyone know the easiest way to disable USB? I have a bootloader which makes use of the usbh to download a program from a usb flash drive to flash and then runs the program. The program also makes use of usb though so I need to disable it before loading my program. I've called the USBH_DeInit command but that doesn't seem to have done the trick. Is there anything else I've missed?

6 REPLIES 6
chen
Associate II
Posted on April 14, 2014 at 13:22

Hi

'' The program also makes use of usb though so I need to disable it before loading my program.''

''Is there anything else I've missed?''

Yes, if you are transfering from one program to another and want to have USB in the new program - you have to force a 'soft disconnect' on the USB.

Try :

    // set bit SDIS in OTG_FS_DCTL reg

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

jdcowpland
Associate II
Posted on April 14, 2014 at 15:30

My program code seems to be running into issues when it calls the BSP_Delay() function. Is there something I'm maybe missing that I should be disabling to make sure that that works after the bootloader? I did the soft disconnect you suggested but it doesn't seem to have helped

chen
Associate II
Posted on April 14, 2014 at 16:42

Hi

''My program code seems to be running into issues when it calls the BSP_Delay() function.''

No idea what that is.

''I'm maybe missing that I should be disabling to make sure that that works after the bootloader? I did the soft disconnect you suggested but it doesn't seem to have helped''

Sorry, should have made it clearer.

Disable interrupts and then do the USB soft-disconnect (or the IRQ will start the USB enumeration again in the bootloader just as you are switching to the application).

In summary :

In bootloader, just before switching to application

disable interrupts

do USB soft disconnect

switch to application.

jdcowpland
Associate II
Posted on April 14, 2014 at 17:32

Ok, I'm disabling interrupts with 

__asm(''CPSID I'');

and then re-enabling them in my application with 

__asm(''CPSIE I '');

Am I doing that bit right?

chen
Associate II
Posted on April 14, 2014 at 18:08

Hi

''Ok, I'm disabling interrupts with ''

''Am I doing that bit right?''

I do not know, those asm commands do not look familiar to me.

I do not do that much ARM assembler now a dars.

I just call the USB disable IRQ and it works OK on my project.

FreeRTOS disables IRQs like this :

__attribute__(( naked )) unsigned long ulPortSetInterruptMask( void )

{

    __asm volatile                                                        \

    (                                                                    \

        ''    mrs r0, basepri                                            \n'' \

        ''    mov r1, %0                                                \n''    \

        ''    msr basepri, r1                                            \n'' \

        ''    bx lr                                                    \n'' \

        :: ''i'' ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : ''r0'', ''r1''    \

    );

    /* This return will not be reached but is necessary to prevent compiler

    warnings. */

    return 0;

}

I am not using FreeRTOS in my bootloader (just the application).

My bootloader code is this :

        // need to disable and soft disconnect USB before starting app

        if( ( rebootDelayCnt > APP_START_USB_DISC - 1 ) && ( rebootDelayCnt < APP_START_USB_DISC + 1 ) )

        {

            USB_DisableInterrupt( true );

            USB_SoftDisconnect();

        }

        // end of time delay for starting app

        if( rebootDelayCnt == 0 )

        {

            loopRound = false;

        }

    }    // while( loopRound )

//    USB_DisableInterrupt();

    /* Jump to user application */

    JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);

    Jump_To_Application = (pFunction) JumpAddress;

    /* Initialize user application's Stack Pointer */

    __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);

    Jump_To_Application();

}

jdcowpland
Associate II
Posted on April 14, 2014 at 18:24

Found the issue! Turns out the BSP_Delay function from the stm discovery library moved the vector table back to 0x0800000 in the application code... Took that out and all worked 🙂