modify stack start in linker file of an LPC2148 project

OP #1585178
Rate this post
• ▲ useful
▼ not useful
Hi,

I have made a project using an LPC2148 evaluation board from sparkfun 
(logomatic V2).

I think that I have a memory overflow problem because some global data 
are overwrited during my program execution without any write.

Example:
Bebug output in the beginning of my program execution
1
    weekday N0 alarm: morning_en:0 afternoon_en:0
2
    weekday N1 alarm: morning_en:1 afternoon_en:1
3
                  08h:30m
4
                  12h:00m
5
                  14h:00m
6
                  17h:30m
7
    weekday N2 alarm: morning_en:1 afternoon_en:1
8
                  08h:30m
9
                  12h:00m
10
                  14h:00m
11
                  17h:30m
12
    weekday N3 alarm: morning_en:1 afternoon_en:1
13
                  08h:30m
14
                  12h:00m
15
                  14h:00m
16
                  17h:30m
17
    weekday N4 alarm: morning_en:1 afternoon_en:1
18
                  08h:30m
19
                  12h:00m
20
                  14h:00m
21
                  17h:30m
22
    weekday N5 alarm: morning_en:1 afternoon_en:1
23
                  08h:30m
24
                  12h:00m
25
                  14h:00m
26
                  17h:30m
27
    weekday N6 alarm: morning_en:1 afternoon_en:0
28
                  09h:00m
29
                  12h:00m

and when I read the same data later I could see that some data are 
overwrited by some strange values:
1
    weekday N0 alarm: morning_en:0 afternoon_en:0
2
    weekday N1 alarm: morning_en:1 afternoon_en:1
3
                  08h:30m
4
                  12h:00m
5
                  14h:00m
6
                  17h:30m
7
    weekday N2 alarm: morning_en:1 afternoon_en:1
8
                  08h:30m
9
                  12h:00m
10
                  14h:00m
11
                  17h:30m
12
    weekday N3 alarm: morning_en:1 afternoon_en:1
13
                  08h:30m
14
                  12h:00m
15
                  14h:00m
16
                  17h:30m
17
    weekday N4 alarm: morning_en:53 afternoon_en:208
18
                  00h:02m
19
                  00h:17m
20
                  00h:04m
21
                  00h:17m
22
    weekday N5 alarm: morning_en:54 afternoon_en:44
23
                  00h:100m
24
                  00h:128m
25
                  53h:11m
26
                  157h:60m
27
    weekday N6 alarm: morning_en:28 afternoon_en:50
28
                  53h:248m
29
                  00h:04m
30
                  54h:220m
31
                  00h:100m

I think that the .bss section (my global data) is overwrited by the 
.stack

Here is some detail:
Section    Size    Address
.text     75100  0001 0000
.data      2576  4000 0000
.bss       9564  4000 0A10
.stack     3072  4000 3000

in startup.s file
1
.set UND_Stack_Size, 0x00000080
2
.set SVC_Stack_Size, 0x00000080
3
.set ABT_Stack_Size, 0x00000080
4
.set FIQ_Stack_Size, 0x00000080
5
.set IRQ_Stack_Size, 0x00000200
6
.set USR_Stack_Size, 0x00000800

So the size of the stack (3000) is correct but I don't understand why it 
start so close to the .bss section. Shouldn't be at the address 4000 
8000 ?

The .bss section end at 4000 0A10 + 255C = 4000 2F6C
If the .stack data start at 4000 3000 it may collide with the .bss 
section (4000 3000 - 0C00 = 4000 2400) !!

Could you help me to solve this problem?
Attached files:
OP #1585246
Rate this post
• ▲ useful
▼ not useful
I have increased the stack size from 0x800 to 0x1000 and my error seems 
to be solved.

I hope the problem is totally solved.

Here is the modification:

main_memory_block.ld
1
ENTRY(_boot)
2
STACK_SIZE = 0x1000; -> see startup-file and .stack-section

startup.S
1
.set USR_Stack_Size, 0x00001000

Do you agree with me?
Moderator #1585536
Rate this post
• ▲ useful
▼ not useful
Noel Le moult wrote:
> I have increased the stack size from 0x800 to 0x1000 and my error seems
> to be solved.
>
> I hope the problem is totally solved.
>
> Here is the modification:
>
> main_memory_block.ld
>
1
> ENTRY(_boot)
2
> STACK_SIZE = 0x1000; -> see startup-file and .stack-section
3
>

The mentioned lines are commented out in the file attached to the first 
post (seem a unmodified version from one of may examples).

While the STACK_SIZE definition is not used since the stacks are defined 
in the startup-code it is a good idea to place an ENTRY line into the 
linker-script (outside a comment). Here ENTRY(Reset_Handler) should do.

> startup.S
>
1
> .set USR_Stack_Size, 0x00001000
2
>
>
> Do you agree with me?

Yes. This defines the size of the user-mode stack which is later used to 
define a memory-area for this stack (using .space) and during the 
startup-code to initialise the core's stack-pointer for the user-mode

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.