lpcware

USB device code for LPC15xx on Keil MDK4

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by aykutkes on Mon Jul 21 02:42:49 MST 2014
Hello,

I can't find any sample project about using USB for LPC15xx on keil MDK4. I've been try to complie sample project written for lpcespresso ( usbd_rom_hid_generic) on my MDK4 but it does'nt work.

Anybody can help me?

There is a start code running after reset and there is some definitons coming from Linker. And i couldn't find equvilants on MDK4.

The definitions are;

extern unsigned int __data_section_table;
extern unsigned int __data_section_table_end;
extern unsigned int __bss_section_table;
extern unsigned int __bss_section_table_end;



The code is;


//*****************************************************************************
// Functions to carry out the initialization of RW and BSS data sections. These
// are written as separate functions rather than being inlined within the
// ResetISR() function in order to cope with MCUs with multiple banks of
// memory.
//*****************************************************************************
__attribute__ ((section(".after_vectors")))
void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
    unsigned int *pulDest = (unsigned int*) start;
    unsigned int *pulSrc = (unsigned int*) romstart;
    unsigned int loop;
    for (loop = 0; loop < len; loop = loop + 4)
        *pulDest++ = *pulSrc++;
}

__attribute__ ((section(".after_vectors")))
void bss_init(unsigned int start, unsigned int len) {
    unsigned int *pulDest = (unsigned int*) start;
    unsigned int loop;
    for (loop = 0; loop < len; loop = loop + 4)
        *pulDest++ = 0;
}

//*****************************************************************************
// The following symbols are constructs generated by the linker, indicating
// the location of various points in the "Global Section Table". This table is
// created by the linker via the Code Red managed linker script mechanism. It
// contains the load address, execution address and length of each RW data
// section and the execution and length of each BSS (zero initialized) section.
//*****************************************************************************
extern unsigned int __data_section_table;
extern unsigned int __data_section_table_end;
extern unsigned int __bss_section_table;
extern unsigned int __bss_section_table_end;


//*****************************************************************************
// Reset entry point for your code.
// Sets up a simple runtime environment and initializes the C/C++
// library.
//*****************************************************************************
__attribute__ ((section(".after_vectors")))
void
ResetISR(void) {

    //
    // Copy the data sections from flash to SRAM.
    //
    unsigned int LoadAddr, ExeAddr, SectionLen;
    unsigned int *SectionTableAddr;

    // Load base address of Global Section Table
    SectionTableAddr = &__data_section_table;

    // Copy the data sections from flash to SRAM.
    while (SectionTableAddr < &__data_section_table_end) {
        LoadAddr = *SectionTableAddr++;
        ExeAddr = *SectionTableAddr++;
        SectionLen = *SectionTableAddr++;
        data_init(LoadAddr, ExeAddr, SectionLen);
    }
    // At this point, SectionTableAddr = &__bss_section_table;
    // Zero fill the bss segment
    while (SectionTableAddr < &__bss_section_table_end) {
        ExeAddr = *SectionTableAddr++;
        SectionLen = *SectionTableAddr++;
        bss_init(ExeAddr, SectionLen);
    }
#if defined (__USE_CMSIS) || defined (__USE_LPCOPEN)
    SystemInit();
#endif

#if defined (__cplusplus)
    //
    // Call C++ library initialisation
    //
    __libc_init_array();
#endif

#if defined (__REDLIB__)
    // Call the Redlib library, which in turn calls main()
    __main() ;
#else
    main();
#endif

    //
    // main() shouldn't return, but if it does, we'll just enter an infinite loop
    //
    while (1) {
        ;
    }
}


I've found similiar code for MDK4 on internet. Looks like doing same job. But not work properly;


extern unsigned int Load$$RW_IRAM1$$Base;
extern unsigned int Image$$RW_IRAM1$$RW$$Base;
extern unsigned int Image$$RW_IRAM1$$RW$$Length;
extern unsigned int Image$$RW_IRAM1$$ZI$$Base;
extern unsigned int Image$$RW_IRAM1$$ZI$$Length;

void  Prepare_Zero( unsigned int  * dst, unsigned int  len )
{
    while(len)
    {
        *dst++ = 0;

        len -= 4;
    }
}

void Prepare_Copy( unsigned int  * src, unsigned int  * dst, unsigned int  len )
{
    if(dst != src)
    {
        while(len)
        {
            *dst++ = *src++;

            len -= 4;
        }
    }
}

Prepare_Copy((unsigned int *)&Load$$RW_IRAM1$$Base,(unsigned int *)&Image$$RW_IRAM1$$RW$$Base,(unsigned int)&Image$$RW_IRAM1$$RW$$Length);
Prepare_Zero((unsigned int *)&Image$$RW_IRAM1$$ZI$$Base,(unsigned int)&Image$$RW_IRAM1$$ZI$$Length);


Can I find an USB HID code running on LPC15xx for MDK4 or a way to transfer lpcexpresso project to MDK4 ??

Thanks to everybody...

Outcomes