Author Topic: How to use USBRAM for general purpose? + LPC1768  (Read 12998 times)

Offline Prakash

  • Newbie
  • *
  • Posts: 17
    • View Profile
How to use USBRAM for general purpose? + LPC1768
« on: August 07, 2010, 09:29:31 AM »

According to LPC17xx user manual the LPC1768 has a total of 64kB of SRAM. I understand that there is a 32kB bank of SRAM connected to the CPU's instruction and data busses, which is readily accessible.

There are two more 16kB banks of SRAM which are stated as typically being used for peripheral data but can supposedly still be used for general purpose instruction and data storage.

In my project I have to use 40kb to 45kb SRAM. Could you please anybody tell me how to use USBRAM? If any body can help on this, that will be very appreciated.


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3238
    • View Profile
    • uTasker
Re: How to use USBRAM for general purpose? + LPC1768
« Reply #1 on: August 07, 2010, 11:14:06 PM »
Hi Prakash

If you tell the linker that you have two separate RAM areas (2 sections rather than 1) it should automatically use the second area for variables once the first becomes full. This is a solution if you have a large amount of variables.

Alternatively it may be more practical to use the second block for heap (rather than the first) and the first for variables. In this case it depends on the malloc() implementation but it should also be possible to instruct the linker to put its heap area in a different RAM sector.

In the uTasker project development version there is a simple malloc() type routine which allocates space in USB RAM which doesn't need any linker script changes - so may be useful for first tests:

// Memory allocation in USB RAM block
extern void *uMallocUSB(unsigned short __size)
    static unsigned char *pucBottomOfHeap = (unsigned char *)(USB_RAM_START);
    static unsigned char *pucTopOfHeap = (unsigned char *)(USB_RAM_START + USB_RAM_SIZE);
    static unsigned short present_HeapSize = 0;
    unsigned char *ptr = (pucBottomOfHeap + present_HeapSize);
    if ((ptr + __size) >= pucTopOfHeap) {
        return 0;                                                        // no more room in USB ram space

    uMemset(ptr, 0, __size);                                             // ensure new memory chunk is always zeroed

    present_HeapSize = (ptr - pucBottomOfHeap) + __size;
    return ((void *)ptr);