This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TI-RTOS USB DFU mode problem

Other Parts Discussed in Thread: EK-TM4C123GXL

Hello

I'm using EK-TM4C123GXL LaunchPad

CCS 5.3

I'm trying to get into DFU Mode using TI-RTOS. for Some reason the following code doesn't work on TI-RTOS sample applications, but works with any other Tivaware sample application. I've tried putting this code in the main function of the hello example and it did work without any issues

	uint32_t ui32SysClock;
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
    SYSCTL_XTAL_16MHZ);
    ui32SysClock = ROM_SysCtlClockGet();
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5);
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();
    ROM_IntMasterDisable();
	ROM_SysTickIntDisable();
	ROM_SysTickDisable();
	HWREG(NVIC_DIS0) = 0xffffffff;
	HWREG(NVIC_DIS1) = 0xffffffff;
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
	ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_USB0);
	ROM_SysCtlUSBPLLEnable();
	ROM_SysCtlDelay(ui32SysClock*2 / 3);
	ROM_IntMasterEnable();
	ROM_UpdateUSB(0);
	while(1)
		{
		}

I can use  DFU mode without any problem using this code with Tivaware sample applications. but when I try using it with TI-RTOS, even putting it in the main function before anything else (even before bios start), it does not work and I get "Unknown USB Device"

I really don't understand what doing on

any help would be highly appreciated

Thanks

  • Any update on this?

    its really simple to reproduce the problem

    TI Explorer just import "hello" example from TivaWare and paste the above code and include required  headers 

    Compile and flash and it will work without any problems 

    do the same with any TI-RTOS example and paste the code above in the main function, and you will get "unknown usb device"

    again, any help would be highly appreciated

  • I've not used TI-RTOS but I suspect the problem here is that you are not disabling all possible interrupts in the NVIC prior to calling into the ROM boot loader. Try adding:


    HWREG(NVIC_DIS2) = 0xFFFFFFFF;
    HWREG(NVIC_DIS3) = 0xFFFFFFFF;
    HWREG(NVIC_DIS4) = 0xFFFFFFFF;

    after the two existing line for NVIC_DIS0 and NIVC_DIS1 and see if this helps.

  • Thanks for the suggestion

    but actually I've already tried that and still not working. here is the new modified code, which works with any Tivaware example but doesn't work with any TI-RTOS example

     ROM_IntMasterDisable();
    	 ROM_SysTickIntDisable();
    		ROM_SysTickDisable();
    		uint32_t ui32SysClock;
    	    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
    	    SYSCTL_XTAL_16MHZ);
    	    ui32SysClock = ROM_SysCtlClockGet();
    	    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    	    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5);
    	    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100);
    		HWREG(NVIC_DIS0) = 0xffffffff;
    		HWREG(NVIC_DIS1) = 0xffffffff;
    		HWREG(NVIC_DIS2) = 0xffffffff;
    		HWREG(NVIC_DIS3) = 0xffffffff;
    		HWREG(NVIC_DIS4) = 0xffffffff;
    		ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
    		ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_USB0);
    		ROM_SysCtlUSBPLLEnable();
    		ROM_SysCtlDelay(ui32SysClock*2 / 3);
    		ROM_IntMasterEnable();
    		ROM_UpdateUSB(0);
    		while(1)
    			{
    			}

    maybe, I'm not really sure, it has something to do with the reset vector. because even in Tivaware hello example, when I comment out resetINT function in the startup code, same problem happens and I get unknown usb device

    your help is highly appreciated

  • Khalefa Mohammed said:
    but actually I've already tried that and still not working. here is the new modified code, which works with any Tivaware example but doesn't work with any TI-RTOS example

    I can repeat the problem. That code worked when placed in a TivaWare example but failed when added to main in a TI-TROS example (I used the GPIO Interrupt example for the EK-TM4C123GXL lanchpad).

    USB View shows a connection status of "DeviceFailedEnumeration" and the Device Descriptor is all zeros.

    Will try and find what the TI-RTOS is doing to the device initialisation to cause the ROM_UpdateUSB to fail to enumerate correctly.

  • I'm pretty sure this must be related to the interrupt vector table address then. TI-RTOS changes the vector table pointer when it starts. The boot loader changes it back and, because you've disabled all interrupts, I can't see how this will affect things but you may like to try swapping the NVIC VTABLE pointer back to the original value (likely 0) prior to jumping back into the ROM boot loader.

    I initially thought that this would be the problem but, given that you've turned interrupts off, I can't see why this will affect things.

    One other thought - what context are you calling this code from? I suspect you need to make sure that it's done in non-interrupt, supervisor context so that you have access to all the low level features that you are touching here. I don't know if TI-RTOS does this but for other RTOSs I've used, user tasks are run in application mode and are prevented from accessing system peripherals such as SysTick and NVIC. Make sure that you are running in the correct privileged mode before calling this code.

  • Dave Wilson said:
    The boot loader changes it back and, because you've disabled all interrupts, I can't see how this will affect things but you may like to try swapping the NVIC VTABLE pointer back to the original value (likely 0) prior to jumping back into the ROM boot loader.

    By setting a hardware watchpoint on writes to NVIC VTABLE see that:

    1) The TI-RTOS startup sets NVIC VTABLE to 0x20000000 (i.e. start of RAM)

    2) ROM_UpdateUSB also sets NVIC VTABLE to 0x20000000

    Setting NVIC VTABLE to zero (flash) before calling ROM_UpdateUSB didn't fix the problem, but given that the ROM boot loader sets its own value that isn't surprising.

  • Dave Wilson said:
    I don't know if TI-RTOS does this but for other RTOSs I've used, user tasks are run in application mode and are prevented from accessing system peripherals such as SysTick and NVIC.

    Looking in the debugger can't see TI-RTOS change to use Unprivileged mode. Privileged mode is reported for:
    - main function
    - HWI interrupt content
    - task context

    The only thing I see changed is:
    - main function uses a Thread Mode Stack of MAIN
    - HWI interrupt context  uses a Thread Mode Stack of MAIN
    - task context uses a Thread Mose Stack of PROC

  • Maybe i am wrong, i am new to the whole TI-RTOS

    but according to the wiki of SYS/BIOS, all code being executed in provilged mode and there is no switching to User Mode

    appreciate all the help

  • The SYS/BIOS C-runtime init fiddles with the NVIC interrupt priority registers before getting to main(). Try adding this after your NVIC_DIS0-4 block:

    for(ui32Addr = NVIC_PRI0; ui32Addr <= NVIC_PRI49; ui32Addr+=4)
    {
    HWREG(ui32Addr) = 0;
    }
    HWREG(NVIC_SYS_PRI1) = 0;
    HWREG(NVIC_SYS_PRI2) = 0;
    HWREG(NVIC_SYS_PRI3) = 0;

    And let me know how it goes.  The lines above should restore them back to their POR defaults. 

    --Miles

  • Thanks Miles!!!

    At Last, its working great, this was really the issue. You know I gave up on this that I started using an alternative way which is somehow stupid but was working for me, deleting the first block of flash memory which will force DFU mode

    FlashErase(0x00000000);

    Anyway this is the actual code you provided modified a bit (there is no NVIC_PRI49, max 34) for people having the same issue

     ROM_IntMasterDisable();
    	 ROM_SysTickIntDisable();
    		ROM_SysTickDisable();
    		uint32_t ui32SysClock;
    	    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
    	    SYSCTL_XTAL_16MHZ);
    	    ui32SysClock = ROM_SysCtlClockGet();
    	    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    	    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5);
    	    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100);
    		HWREG(NVIC_DIS0) = 0xffffffff;
    		HWREG(NVIC_DIS1) = 0xffffffff;
    		HWREG(NVIC_DIS2) = 0xffffffff;
    		HWREG(NVIC_DIS3) = 0xffffffff;
    		HWREG(NVIC_DIS4) = 0xffffffff;
    		int ui32Addr;
    		for(ui32Addr = NVIC_PRI0; ui32Addr <= NVIC_PRI34; ui32Addr+=4)
    		{
    		   HWREG(ui32Addr) = 0;
    		}
    		HWREG(NVIC_SYS_PRI1) = 0;
    		HWREG(NVIC_SYS_PRI2) = 0;
    		HWREG(NVIC_SYS_PRI3) = 0;
    		ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
    		ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_USB0);
    		ROM_SysCtlUSBPLLEnable();
    		ROM_SysCtlDelay(ui32SysClock*2 / 3);
    		ROM_IntMasterEnable();
    		ROM_UpdateUSB(0);
    		while(1)
    			{
    			}

    
    

    Thanks again everyone

    Best

    --Khalefa