PDA

View Full Version : Array Size on the 2138


RageKage
04-15-07, 03:02 AM
Back Again,

This time I am having trouble creating arrays on the 2138.
I am trying to create one relatively large 2d array and am having troubles.

As an Example:

char array[262][1024] = {0};

I have also tried:

char array[1024][262] = {0};


In both cases when I start getting to far into the indexing the ARM just freezes and a reset is required. I know the array itself should fit into the memory on the 2138, but its possible my stack isn't set correctly.

My start.s file:

@// code originally from phillips appnote 10254
@ ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ
@ Assembler Directives
@ ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ
.section asm_code,"ax" @ New Code section
@ CODE32 @ ARM code
.extern __main @ main not defined
@ in this section
.global _start @ global symbol
@ referenced in
@ ivt.s
@ ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ
_start:
@ Set SP for Supervisor mode. Depending upon
@ the stack the application needs this value
@ needs to be set.
@ stack is already set by bootloader
@ but if this point is entered by any
@ other means than reset, the stack pointer
@ needs to be set explicity

LDR SP,=0x40001000

@ Setting up SP for IRQ and FIQ mode.
@ Change mode before setting each one
@ move back again to Supervisor mode
@ Each interrupt has its own link
@ register, stack pointer and program
@ counter The stack pointers must be
@ initialized for interrupts to be
@ used later.

@ setup for fiq and irq interrupt stacks to run
@ below current stack by 1000.
mov r0, sp @ copy current stack pointer
sub r0, r0, #1000 @ make irq stack pointer
sub r1, r0, #1000 @ make fiq stack pointer
msr cpsr_c, #0x12 @ switch to irq mode
mov sp, r0 @ set irq stack pointer
msr cpsr_c, #0x11 @ fiq mode
mov sp, r1 @ set fiq stack pointer
msr cpsr_c, #0x13 @ supervisor mode F,I enabled

@ Jump to C code

LDR lr, =__main
MOV pc, lr




Any ideas on what I can do to get this array to work?

mckenney
04-15-07, 08:49 PM
char array[262][1024] = {0};
The LPC2138 only has 32KB of SRAM, so you won't be able to allocate a
262KB array in any case. (You could allocate a fairly large constant array in
flash (.text), but that doesn't appear to be what you want to do.)

As you observe, you can't really use all the 32KB either, since you need space
for the stack(s). To figure out the largest array you can get, you need to go
through the linker script and the startup code.

Check your .map file, but the typical linker script puts data at the beginning of
SRAM (0x40000000), which will quickly collide with the stacks, which are in
SRAM (apx.) 0x40000800-0x1000. (This is probably the failure you're seeing,
though with such an oversized array some failure was inevitable.)

The smallest change to get you going would be to change the initial SP to
"=0x40008000", which puts the system stack at the top of SRAM, and the
IRQ/FIQ stack tops 1000/2000 bytes below it. Assuming you aren't using any
FIQs, this gives you 32KB-2000 bytes (minus other variables) to put into an
array.

It's also probable you could shrink the IRQ stack a bit by reducing that
"#1000" in the second "SUB" instruction. (I'd recommend keeping the system
stack size -- the first "SUB" -- at #1000.)