Writing to RAM on LPC1114

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Writing to RAM on LPC1114

361 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mohsin on Thu Dec 16 03:20:39 MST 2010
Hi All,

           I am having some problem while writing to the ram in the LPC1114.

static uint8_t        *ram_ptr        = (uint8_t *)  (0x10000000)

value        = *ram_ptr; // Step1
*ram_ptr    = 0xaa;     // Step2
*ram_ptr    = value;    // Step3

The values before Step1 are
ram_ptr      0x10000000   
*ram_ptr    0   

The value I am getting after Step2 are
ram_ptr      0x10[COLOR=Red]aa[/COLOR]0000   
*ram_ptr    [COLOR=Red]0[/COLOR]   

I should be getting
ram_ptr      0x10[COLOR=Black]00[/COLOR]0000   
*ram_ptr    0xaa   

Any clues why this is happenning?

Thanks,
Mohsin
0 Kudos
5 Replies

348 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Thu Dec 16 08:58:51 MST 2010
My guess: your pointer is somewhere close to 0x10000000. By writing to some location close to 0x10000000 you effectively write to one of bytes occupied by the pointer, so you change the pointer value. Your code correctly updated the pointer to a new value, containing the pattern 0xAA. So the pointer doesn't point to itself any more, and the location it points to does not contain 0xAA.

What's not clear is the fact that the pointer's byte updated is not its LSB.

Look at the section in .map file containing the addresses of data and check the address of your pointer.
0 Kudos

348 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mohsin on Thu Dec 16 06:56:12 MST 2010
As requested the following is the snapshot of the linker map file

.ARM.extab
*(.ARM.extab* .gnu.linkonce.armextab.*)
                0x00002d68                __exidx_start = .

.ARM.exidx
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
                0x00002d68                __exidx_end = .
                0x00002d68                _etext = .
[COLOR=Red].data           0x10000000        0x8 load address 0x00002d68[/COLOR]
                  0x10000000                _data = .
*(vtable)
*(.data*)
.data          0x10000000        0x4 ..\..\lib\mhm.a(mhm_mem.c.o)
.data          0x10000004        0x4

Thanks,
Mohsin
0 Kudos

348 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Thu Dec 16 05:52:01 MST 2010
Have you looked at the linker map file to see what the linker might be placing at 0x10000000??? I have a suspicion you may well be overwritting your own data!

For memory map information, take a look at the LPC11 user manual and datasheet - available from:

http://ics.nxp.com/products/lpc1000/lpc1100/lpc11xx/~LPC1114/#LPC1114

Or you can check by selecting your project in the LPCXpresso Project Explorer view and using [FONT=Courier New][SIZE=1]Project Properties - > C/C++ Build -> MCU Settings[/SIZE][/FONT].

But yes, RAM on LPC1114 is 0x2000 bytes, so runs to 0x1000 1fff.

Regards,
CodeRedSupport
0 Kudos

348 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mohsin on Thu Dec 16 05:41:44 MST 2010
Thanks for your reply. It works for me as well when the RAM address is 0x10000300. I am doing a background check of the RAM to check its working correctly. So basically I am just changing the value and restoring it back.

So it works from  0x10000004 - 0x10001fff.

Can anyone explain why it is not working for 0x10000000, 0x10000001, 0x10000002, 0x10000003.

Is the RAM from 0x10000000 to 0x10001fff for LPC1114 ?

Thanks,
Mohsin
0 Kudos

348 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Thu Dec 16 03:59:48 MST 2010
Seems to work OK here with LPCXpresso 3.6.0 - though I would recommend moving the RAM location that you are using, as normally you will actually have global data placed at the start of RAM (from the C library even if your own code has no globals).

Check the linker map file that LPCXPresso autogenerates for details of where the linker is placing globals (both data and bss).

I would suggest that you actually post buildable code, your build options, and the version of the tools that you are using. Better still attach a buildable project to the thread (use Quickstart -> Import and Export -> Export projects to archive).

For your reference, here is the main.c I used....

#include "LPC11xx.h"
int main(void) {
    
    static uint8_t *ram_ptr = (uint8_t *) (0x10000300);
    uint8_t value;
    value = *ram_ptr; // Step1
    *ram_ptr = 0xaa; // Step2
    *ram_ptr = value; // Step3

    // Enter an infinite loop, just incrementing a counter
    volatile static int i = 0 ;
    while(1) {
        i++ ;
    }
    return 0 ;
}
Regards,
CodeRedSupport
0 Kudos