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.

usb_stick_update on EK TM4C123GXL problem Host mode

Other Parts Discussed in Thread: EK-TM4C123GXL, TM4C123AE6PM, TM4C1294KCPDT

Hello everyone, 

I have a question regarding usb_stick_update example for TM4C1294 launchpad, I got that example to work on that board and now I want to adopt it to fit TM4C123gxl board. I have changed clock to run on 80Mhz, here is the change in .cmd file

#define APP_BASE 0x00000000
#define RAM_BASE 0x20000000
MEMORY
{
    /* Application stored in and executes from internal flash */
    FLASH (RX) : origin = APP_BASE, length = 0x00040000
    /* Application uses internal RAM for data */
    SRAM (RWX) : origin = 0x20000000, length = 0x00008000
}

SECTIONS
{
    .intvecs:   > APP_BASE
    .text   :   > FLASH
    .const  :   > FLASH
    .cinit  :   > FLASH
    .pinit  :   > FLASH
    .init_array : > FLASH
    .vtable :   > RAM_BASE
    .data   :   > SRAM
    .bss    :   > SRAM
    .sysmem :   > SRAM
    .stack  :   > SRAM
}
__STACK_TOP = __stack + 1024;

And I also changed function that configures USB interface to 

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5);
ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

I wanted to configure one of the USB0EPEN pins for Host mode from datasheet but none of them made the difference, and then I noticed according to the layout they are not connected to USB_VBUS line at all but pin PB1 is. And still board does nothing when USB connected to the USB port. Changes I made in test app that should be loaded out of USB is 

#define APP_BASE 0x00004800

Is there something more that I needed to change? How to set Host mode for this board?

Thank you for your time!

Kind regards

  • Hello Djedjica

    You would be needing an external VBUS driver for host mode when using EK-TM4C123GXL.

    I would suggest using DK-TM4C123 where this is already done and the examples are available.

    D:\ti\TivaWare_C_Series-2.1.2.111\examples\boards\dk-tm4c123g\usb_stick_demo
    D:\ti\TivaWare_C_Series-2.1.2.111\examples\boards\dk-tm4c123g\usb_stick_update

    Regards
    Amit
  • Yes I already checked that examples, thing is that for testing purposes here we have TM4C123gxl and TM4C1294xl and I'm trying this bootloader on this TM4C123 board because that controller or similar controllers (TM4C123AE6PM) we use here in our system boards, and I want this bootloader to work on our custom boards, so I want to check all the changes which needs to be made in usb_stick_update example (TM4C1294) to make it fit these processors(TM4C123). I assume that then I can refer to this "\dk-tm4c123g\usb_stick_demo" to develop bootloader software for TM4C123AE6PM?
  • Hello Djedjica

    Yes, that is correct. However the pin out of USB and some other functions may be different. So except for the pin out there should not be much difference. However note that EK-TM4C123GXL does not have the additional circuit for Host Mode.

    Regards
    Amit
  • Hello Mr.Ashara,
    yes, yes I have in mind different pins for peripheral functions when working with different MCUs. I suppose external VBUS driver is problem of our electronics I was only interested to make sure for this SW part.
    Thank you for your response.
    Kind regards,
    Djedjica
  • Hello Djedjica

    On the LaunchPad, the USBID can be got by populating the 0 Ohm resistor. The USBVBUS is still going to be an issue

    You may want to use the DK-TM4C123G as the reference platform

    Regards
    Amit
  • Hi Amit,

    I am using the the same example of usb_stick_updater for tm4c1294kcpdt controller. The controller is able to detect the usb stick and the binary file in it. And I think the flash is also being programmed properly from the location 0x20000000 with that binary file. But when i try to set the vector table address as 0x20000000 in the code, the app doesn`t run. Can u please tell me what may be the issue?

    I have used SysCtlPeripheralEnable() commands instead of ROM_SysCtlPeripheralEnable()(ROM_ commands)and i hope that doesn`t make any difference.
    I have one more doubt, in my application i have used main function and startup file of its own. I hope i have done nothing wrong in this.

    To shift the vector table i used the following commands from the usb_stick_updater only:

    #if defined(codered) || defined(gcc) || defined(sourcerygxx)
    void __attribute__((naked))
    CallApplication(uint_fast32_t ui32StartAddr)
    {
    //
    // Set the vector table to the beginning of the app in flash.
    //
    HWREG(NVIC_VTABLE) = ui32StartAddr;

    //
    // Load the stack pointer from the application's vector table.
    //
    __asm(" ldr r1, [r0]\n"
    " mov sp, r1");

    //
    // Load the initial PC from the application's vector table and branch to
    // the application's entry point.
    //
    __asm(" ldr r0, [r0, #4]\n"
    " bx r0\n");
    }
    #elif defined(ewarm)
    void
    CallApplication(uint_fast32_t ui32StartAddr)
    {
    //
    // Set the vector table to the beginning of the app in flash.
    //
    HWREG(NVIC_VTABLE) = ui32StartAddr;

    //
    // Load the stack pointer from the application's vector table.
    //
    __asm(" ldr r1, [r0]\n"
    " mov sp, r1");

    //
    // Load the initial PC from the application's vector table and branch to
    // the application's entry point.
    //
    __asm(" ldr r0, [r0, #4]\n"
    " bx r0\n");
    }
    #elif defined(rvmdk) || defined(__ARMCC_VERSION)
    __asm void
    CallApplication(uint_fast32_t ui32StartAddr)
    {
    //
    // Set the vector table address to the beginning of the application.
    //
    ldr r1, =0xe000ed08
    str r0, [r1]

    //
    // Load the stack pointer from the application's vector table.
    //
    ldr r1, [r0]
    mov sp, r1

    //
    // Load the initial PC from the application's vector table and branch to
    // the application's entry point.
    //
    ldr r0, [r0, #4]
    bx r0
    }
    #elif defined(ccs)
    void
    CallApplication(uint_fast32_t ui32StartAddr)
    {
    //
    // Set the vector table to the beginning of the app in flash.
    //
    HWREG(NVIC_VTABLE) = ui32StartAddr;

    //
    // Load the stack pointer from the application's vector table.
    //
    __asm(" ldr r1, [r0]\n"
    " mov sp, r1\n");

    //
    // Load the initial PC from the application's vector table and branch to
    // the application's entry point.
    //
    __asm(" ldr r0, [r0, #4]\n"
    " bx r0\n");
    }
    #else
    #error Undefined compiler!
    #endif

    But that doesn`t work, I am also confused with the compiler i am using(in KEIL) which has to be described in the #if defined()condition above. Please help. Thanks in advance.
  • Hello Naman

    Did you make sure that things like the SysTick and other peripherals that were enabled and capable of generating interrupts are disabled?
  • Thanks for the reply Amit.

    I disabled all the interrupts by using the command IntMasterDisable() before calling the application in the bootloader program. When I am calling the application from boot loader code, it should jump to the new vector address(of the application). But instead of jumping to the application, it jumps again to the bootloader and executes main() of the bootloader. I am not debuging through keil, I am using Lcd Display to debug.

    After that I tried using pre-definition "ewarm" in project properties so that CallApplication() calls the below code:
    void
    CallApplication(uint_fast32_t ui32StartAddr)
    {
    //
    // Set the vector table to the beginning of the app in flash.
    //
    HWREG(NVIC_VTABLE) = ui32StartAddr;

    //
    // Load the stack pointer from the application's vector table.
    //
    __asm(" ldr r1, [r0]\n"
    " mov sp, r1");

    //
    // Load the initial PC from the application's vector table and branch to
    // the application's entry point.
    //
    __asm(" ldr r0, [r0, #4]\n"
    " bx r0\n");
    }

    But it then shows errors like sp is undefined, r0 cannot be used before being set, and the type of expression is undefined(for "bx r0\n").
    So i think there is some issue with asm commands. Or may be i am not able to run these commands in priviledged mode. Please advise.
  • I need to make a correction for my first post, i am using 0x8000/0x10000/0x20000 as the new application address(I tried all these but result is same).
  • This is NOT my subject area of expertise (few are) yet I note your earlier mention of "Keil" and today's (01 May, 09:40) post states,
    "tried using pre-definition "ewarm""

    Ewarm is a "file folder name" - very common w/in IAR. (usually contains the .exe file.) I'm unsure if "ewarm" occurs w/in Keil too!

    Believed it wise to "Flag ewarm/IAR" - for this thread's attention - "just in case."

  • I am not using ewarm. I found it in the code only. What i am trying to do is simple, just using the code of usb_stick_updater to update the code at a certain flash memory region and then trying to run that application.

    I am using the below commands to jump to application vector table,

    HWREG(NVIC_VTABLE) = APP_START_ADDRESS;

    __asm(" ldr r1, [r0]\n"
    " mov sp, r1");

    __asm(" ldr r0, [r0, #4]\n"
    " bx r0\n");

    But it is showing error now. Errors like sp(stack pointer) is undefined, r0 cannot be used before being set, and the type of expression is undefined(for "bx r0\n").
    Can you please help me with this. How can I use asm inline commands without these errors. Is there any file i need to include?
  • Presented here is variant code to that which you supplied. Yours was for IAR - below is for Keil. (rvmdk signals such)

    Now - this code runs nicely w/in the IAR IDE - should those same (or other) errors occur (especially tied to the ASM listings) you must read/review the Keil IDE manual - to see how to make it "ASM aware."

    #elif defined(rvmdk) || defined(__ARMCC_VERSION)
    __asm void
    CallApplication(unsigned long ulStartAddr)
    {
    //
    // Set the vector table address to the beginning of the application.
    //
    ldr r1, =0xe000ed08
    str r0, [r1]

    // Load the stack pointer from the application's vector table.
    //
    ldr r1, [r0]
    mov sp, r1

    // Load the initial PC from the application's vector table and branch to
    // the application's entry point.
    //
    ldr r0, [r0, #4]
    bx r0
    }

    Should those (same ASM errors persist) I suggest that you search through your Keil folders - and the Keil Operating Manual - for the smallest/simplest ASM code example you can find - and note carefully which files are included.     By selectively removing those files - you should be able to determine which files your program requires...      Good luck.

  • Hello Amit,

    The above code seems to be working now. Now when i am calling the application from boot loader code using the bx instruction. Instead of calling the main() of the new application, it is calling the main of the boot loader code. Is there anything that needs to be changed in the startup file of the new application. As both the boot loader code and the application have almost same startup files. both the files are having the below code:

    IMPORT __main
    B __main

    The difference is that USB handler is there is bootloader but there is no external handler in application code. Please advise.
  • And please let me know if there is anything to be done with linker scripts as I have not taken them into consideration and they would be the default ones.
  • Hello Amit,

    It is working now. Thanks for your support.

    The issue was with the linker file of the application on which i was trying to jump. The Start Address Of the Flash in the linker file must be set to the application address in the flash where we are programming it. I was not using LM Flash programmer to program. I was using usb stick instead so this problem did not happen before while programming the application.