Forum > Embedded - AVR

[SOLVED] Variable addresses in SRAM

(1/14) > >>

dseligo:
I have project working on a ATmega2561.
I only use one timer and digital I/O pins.

When I run it on a ATmega32U4 I have problem like random restarts or garbled text shown on LCD.
Lazarus says '...22080 bytes code, 1047 bytes data', so it should fit into ATmega32U4's 32KB flash.

What I suspect is that variables in SRAM are overwritten with stack.

So finally my question: how can I see last location used with variables?

I can see current SP value in debugger, so last variable location would help me estimate how much space I have to 'free'.

d.ioannidis:
Hi,

  if you suspect heap and stack collision, you can find some information here [AVR] Investigating stack and heap management.  Also in AVR Freaks you can find information ( c only ) for stack painting to determine if you have stack problem ( I think I have something like that written in Free Pascal. I'll take a look tomorrow when I return home .... )

  Do you use the heap manager and/or recursive function/procedures ?

EDIT: Fixed url ....

regards,

dseligo:

--- Quote from: Dimitrios Chr. Ioannidis on September 24, 2022, 11:40:40 am ---  if you suspect heap and stack collision, you can find some information here [AVR] Investigating stack and heap management.  Also in AVR Freaks you can find information ( c only ) for stack painting to determine if you have stack problem ( I think I have something like that written in Free Pascal. I'll take a look tomorrow when I return home .... )

--- End quote ---

Thank you for information.


--- Quote ---  Do you use the heap manager and/or recursive function/procedures ?

--- End quote ---

No recursive functions, only consts, vars, arrays, records.

MarkMLl:

--- Quote from: dseligo on September 24, 2022, 12:01:37 pm ---No recursive functions, only consts, vars, arrays, records.

--- End quote ---

Any strings (as distinct from shortstrings) or dynamic arrays?

MarkMLl

d.ioannidis:
Hi,


--- Quote from: dseligo on September 24, 2022, 11:22:20 am ---
< snip >

So finally my question: how can I see last location used with variables?

I can see current SP value in debugger, so last variable location would help me estimate how much space I have to 'free'.

--- End quote ---

can you share your AVR development setup ?

OS, FPC version ?

How do you debug your AVR project ?

AVRSim, hardware debugger ( snap, medbg, atmel ICE ), Microchip( Atmel ) Studio's ATBackend, gdb version ?


--- Quote from: dseligo on September 24, 2022, 12:01:37 pm ---No recursive functions, only consts, vars, arrays, records.

--- End quote ---

Also, if you use objects, IMHO, I recommend to switch to advancedrecords. I wasn't able to successfully debug objects when they're in different units ( I suspect bugs in dwarf  information ).

regards,

Navigation

[0] Message Index

[#] Next page

Go to full version