EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Executing function in external SDRAM

Started by Kuba Dorzak September 12, 2012
Hi All,

I have LPC1788 (Cortex-M3) with external SDRAM. I'd like to execute a
function in the SDRAM. CPU correctly jumps to the function (I have
-mlong-calls) which is at 0xA000 0000, but when it enters the function
prologue the program crashes:

toggleLed:
a0000000: push {r7, lr} // <- crash happens when storing context
a0000002: add r7, sp, #0
a0000004: movw r3, #6469 ; 0x1945
a0000008: movt r3, #0
a000000c: blx r3
a000000e: pop {r7, pc}
a0000010: beq.w 0xa003ce50
a0000014: beq.w 0xa003ce54
a0000018: beq.w 0xa003ce58

I have stacks aligned to 8 bytes, placed in internal RAM. The function is
working correctly in the on-chip flash. Any ideas?

Regards,
Kuba


An Engineer's Guide to the LPC2100 Series

It depends on how you load it.

The boot code normally copies the functions from flash to RAM if you execute
from RAM

That works because the RAM always works, but SDRAM will not work until the
memory controller is set up and the SDRAM properly initialized.

If you want to execute from SDRAM you either have to manually copy the image
after setting up the SDRAM, or call the EMC init code from the startup file
before executing any of the standard startup code.

If you did this then it should work, but if you didn't then the image in
SDRAM will not be valid.

Regards

Phil.

From: l... [mailto:l...] On Behalf Of
Kuba Dorzak
Sent: 12 September 2012 10:51
To: l...
Subject: [lpc2000] Executing function in external SDRAM

Hi All,

I have LPC1788 (Cortex-M3) with external SDRAM. I'd like to execute a
function in the SDRAM. CPU correctly jumps to the function (I have
-mlong-calls) which is at 0xA000 0000, but when it enters the function
prologue the program crashes:

toggleLed:
a0000000: push {r7, lr} // <- crash happens when storing context
a0000002: add r7, sp, #0
a0000004: movw r3, #6469 ; 0x1945
a0000008: movt r3, #0
a000000c: blx r3
a000000e: pop {r7, pc}
a0000010: beq.w 0xa003ce50
a0000014: beq.w 0xa003ce54
a0000018: beq.w 0xa003ce58

I have stacks aligned to 8 bytes, placed in internal RAM. The function is
working correctly in the on-chip flash. Any ideas?

Regards,
Kuba





To those who might be interested- an excerpt from UM (page 155, Chapter
10.2):

"MPU: Default memory space permissions for the Cortex-M3 do not allow
program
execution from the address range that includes the dynamic memory chip
selects.
These permissions can be changed by programming the MPU"

Regards,
Kuba
2012/9/12 Phil Young

> **
> It depends on how you load it.
>
> The boot code normally copies the functions from flash to RAM if you
> execute
> from RAM
>
> That works because the RAM always works, but SDRAM will not work until the
> memory controller is set up and the SDRAM properly initialized.
>
> If you want to execute from SDRAM you either have to manually copy the
> image
> after setting up the SDRAM, or call the EMC init code from the startup file
> before executing any of the standard startup code.
>
> If you did this then it should work, but if you didn't then the image in
> SDRAM will not be valid.
>
> Regards
>
> Phil.
>
> From: l... [mailto:l...] On Behalf
> Of
> Kuba Dorzak
> Sent: 12 September 2012 10:51
> To: l...
> Subject: [lpc2000] Executing function in external SDRAM
> Hi All,
>
> I have LPC1788 (Cortex-M3) with external SDRAM. I'd like to execute a
> function in the SDRAM. CPU correctly jumps to the function (I have
> -mlong-calls) which is at 0xA000 0000, but when it enters the function
> prologue the program crashes:
>
> toggleLed:
> a0000000: push {r7, lr} // <- crash happens when storing context
> a0000002: add r7, sp, #0
> a0000004: movw r3, #6469 ; 0x1945
> a0000008: movt r3, #0
> a000000c: blx r3
> a000000e: pop {r7, pc}
> a0000010: beq.w 0xa003ce50
> a0000014: beq.w 0xa003ce54
> a0000018: beq.w 0xa003ce58
>
> I have stacks aligned to 8 bytes, placed in internal RAM. The function is
> working correctly in the on-chip flash. Any ideas?
>
> Regards,
> Kuba
>
>
>
>
>
>
>


On 12/09/2012 12:25, Kuba Dorzak wrote:
> To those who might be interested- an excerpt from UM (page 155, Chapter
> 10.2):
>
> "MPU: Default memory space permissions for the Cortex-M3 do not allow
> program
> execution from the address range that includes the dynamic memory chip
> selects.
> These permissions can be changed by programming the MPU"
...but the MPU is not on by default, so that should not cause a problem.

Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for microcontrollers. More than 7000 downloads per month.

+ http://www.FreeRTOS.org/trace
15 interconnected trace views. An indispensable productivity tool.

>
> Regards,
> Kuba
> 2012/9/12 Phil Young > **
>> It depends on how you load it.
>>
>> The boot code normally copies the functions from flash to RAM if you
>> execute
>> from RAM
>>
>> That works because the RAM always works, but SDRAM will not work until the
>> memory controller is set up and the SDRAM properly initialized.
>>
>> If you want to execute from SDRAM you either have to manually copy the
>> image
>> after setting up the SDRAM, or call the EMC init code from the startup file
>> before executing any of the standard startup code.
>>
>> If you did this then it should work, but if you didn't then the image in
>> SDRAM will not be valid.
>>
>> Regards
>>
>> Phil.
>>
>> From: l... [mailto:l...] On Behalf
>> Of
>> Kuba Dorzak
>> Sent: 12 September 2012 10:51
>> To: l...
>> Subject: [lpc2000] Executing function in external SDRAM
>> Hi All,
>>
>> I have LPC1788 (Cortex-M3) with external SDRAM. I'd like to execute a
>> function in the SDRAM. CPU correctly jumps to the function (I have
>> -mlong-calls) which is at 0xA000 0000, but when it enters the function
>> prologue the program crashes:
>>
>> toggleLed:
>> a0000000: push {r7, lr} // <- crash happens when storing context
>> a0000002: add r7, sp, #0
>> a0000004: movw r3, #6469 ; 0x1945
>> a0000008: movt r3, #0
>> a000000c: blx r3
>> a000000e: pop {r7, pc}
>> a0000010: beq.w 0xa003ce50
>> a0000014: beq.w 0xa003ce54
>> a0000018: beq.w 0xa003ce58
>>
>> I have stacks aligned to 8 bytes, placed in internal RAM. The function is
>> working correctly in the on-chip flash. Any ideas?
>>
>> Regards,
>> Kuba
>>
>>
>>
>>
>>
>>
>>
>
>
>
Hi,

I am reading the UM and in the MPU chapter (39.4.5.2, page 980) there is a
remark:

"When the ENABLE bit is set to 0, the system uses the default memory map.
This has the same memory attributes as if the MPU is not implemented, see
Table 775".

And the table says that the address range beetwen 0xA0000000-0xDFFFFFFF has
XN attribute (eXecute Never). Has anyone executed code successfully from
that space without using MPU for LPC1788?

Regards,
Kuba
2012/9/12 FreeRTOS Info

> **
> On 12/09/2012 12:25, Kuba Dorzak wrote:
> > To those who might be interested- an excerpt from UM (page 155, Chapter
> > 10.2):
> >
> > "MPU: Default memory space permissions for the Cortex-M3 do not allow
> > program
> > execution from the address range that includes the dynamic memory chip
> > selects.
> > These permissions can be changed by programming the MPU"
>
> ...but the MPU is not on by default, so that should not cause a problem.
>
> Regards,
> Richard.
>
> + http://www.FreeRTOS.org
> Designed for microcontrollers. More than 7000 downloads per month.
>
> + http://www.FreeRTOS.org/trace
> 15 interconnected trace views. An indispensable productivity tool.
> >
> > Regards,
> > Kuba
> >
> >
> > 2012/9/12 Phil Young
> >
> >> **
>
> >>
> >>
> >> It depends on how you load it.
> >>
> >> The boot code normally copies the functions from flash to RAM if you
> >> execute
> >> from RAM
> >>
> >> That works because the RAM always works, but SDRAM will not work until
> the
> >> memory controller is set up and the SDRAM properly initialized.
> >>
> >> If you want to execute from SDRAM you either have to manually copy the
> >> image
> >> after setting up the SDRAM, or call the EMC init code from the startup
> file
> >> before executing any of the standard startup code.
> >>
> >> If you did this then it should work, but if you didn't then the image in
> >> SDRAM will not be valid.
> >>
> >> Regards
> >>
> >> Phil.
> >>
> >> From: l... [mailto:l...] On
> Behalf
> >> Of
> >> Kuba Dorzak
> >> Sent: 12 September 2012 10:51
> >> To: l...
> >> Subject: [lpc2000] Executing function in external SDRAM
> >>
> >>
> >> Hi All,
> >>
> >> I have LPC1788 (Cortex-M3) with external SDRAM. I'd like to execute a
> >> function in the SDRAM. CPU correctly jumps to the function (I have
> >> -mlong-calls) which is at 0xA000 0000, but when it enters the function
> >> prologue the program crashes:
> >>
> >> toggleLed:
> >> a0000000: push {r7, lr} // <- crash happens when storing context
> >> a0000002: add r7, sp, #0
> >> a0000004: movw r3, #6469 ; 0x1945
> >> a0000008: movt r3, #0
> >> a000000c: blx r3
> >> a000000e: pop {r7, pc}
> >> a0000010: beq.w 0xa003ce50
> >> a0000014: beq.w 0xa003ce54
> >> a0000018: beq.w 0xa003ce58
> >>
> >> I have stacks aligned to 8 bytes, placed in internal RAM. The function
> is
> >> working correctly in the on-chip flash. Any ideas?
> >>
> >> Regards,
> >> Kuba
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
> >
> >
> >
> >
> >
> >
Hi,

if someone will need to execute code from external SDRAM using LPC1788- I
can confirm that to run program from the SDRAM the MPU needs to be
configured. I did it according to the description:

http://www.lpcware.com/content/forum/using-dynamic-ram-uclinux-lpc1788.

Regards,
Kuba

2012/9/13 Kuba Dorzak

> Hi,
>
> I am reading the UM and in the MPU chapter (39.4.5.2, page 980) there is a
> remark:
>
> "When the ENABLE bit is set to 0, the system uses the default memory map.
> This has the same memory attributes as if the MPU is not implemented, see
> Table 775".
>
> And the table says that the address range beetwen 0xA0000000-0xDFFFFFFF
> has XN attribute (eXecute Never). Has anyone executed code successfully
> from that space without using MPU for LPC1788?
>
> Regards,
> Kuba
>
> 2012/9/12 FreeRTOS Info > **
>> On 12/09/2012 12:25, Kuba Dorzak wrote:
>> > To those who might be interested- an excerpt from UM (page 155, Chapter
>> > 10.2):
>> >
>> > "MPU: Default memory space permissions for the Cortex-M3 do not allow
>> > program
>> > execution from the address range that includes the dynamic memory chip
>> > selects.
>> > These permissions can be changed by programming the MPU"
>>
>> ...but the MPU is not on by default, so that should not cause a problem.
>>
>> Regards,
>> Richard.
>>
>> + http://www.FreeRTOS.org
>> Designed for microcontrollers. More than 7000 downloads per month.
>>
>> + http://www.FreeRTOS.org/trace
>> 15 interconnected trace views. An indispensable productivity tool.
>> >
>> > Regards,
>> > Kuba
>> >
>> >
>> > 2012/9/12 Phil Young
>> >
>> >> **
>>
>> >>
>> >>
>> >> It depends on how you load it.
>> >>
>> >> The boot code normally copies the functions from flash to RAM if you
>> >> execute
>> >> from RAM
>> >>
>> >> That works because the RAM always works, but SDRAM will not work until
>> the
>> >> memory controller is set up and the SDRAM properly initialized.
>> >>
>> >> If you want to execute from SDRAM you either have to manually copy the
>> >> image
>> >> after setting up the SDRAM, or call the EMC init code from the startup
>> file
>> >> before executing any of the standard startup code.
>> >>
>> >> If you did this then it should work, but if you didn't then the image
>> in
>> >> SDRAM will not be valid.
>> >>
>> >> Regards
>> >>
>> >> Phil.
>> >>
>> >> From: l... [mailto:l...] On
>> Behalf
>> >> Of
>> >> Kuba Dorzak
>> >> Sent: 12 September 2012 10:51
>> >> To: l...
>> >> Subject: [lpc2000] Executing function in external SDRAM
>> >>
>> >>
>> >> Hi All,
>> >>
>> >> I have LPC1788 (Cortex-M3) with external SDRAM. I'd like to execute a
>> >> function in the SDRAM. CPU correctly jumps to the function (I have
>> >> -mlong-calls) which is at 0xA000 0000, but when it enters the function
>> >> prologue the program crashes:
>> >>
>> >> toggleLed:
>> >> a0000000: push {r7, lr} // <- crash happens when storing context
>> >> a0000002: add r7, sp, #0
>> >> a0000004: movw r3, #6469 ; 0x1945
>> >> a0000008: movt r3, #0
>> >> a000000c: blx r3
>> >> a000000e: pop {r7, pc}
>> >> a0000010: beq.w 0xa003ce50
>> >> a0000014: beq.w 0xa003ce54
>> >> a0000018: beq.w 0xa003ce58
>> >>
>> >> I have stacks aligned to 8 bytes, placed in internal RAM. The function
>> is
>> >> working correctly in the on-chip flash. Any ideas?
>> >>
>> >> Regards,
>> >> Kuba
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >

Memfault Beyond the Launch