Re: M32C/83: problem with pointers

Hi folks,

> > I'm debugging a board I designed. The features are: > > Micro: M32C/83 Renesas (512 kByte internal flash) > RAM: 512 kByte (external) > >I modified the startup file in order to have the compiler >allocate C variables into the external RAM. >I tested the external RAM and it works fine. > >The problem I got is the following: > > 1. I pass a function a pointer to linear buffer > containing some chars to be transimitted over > the UART1. > > 2. If I print out the content of the linear buffer > from within the function I just called I got > junk chars. > > 3. If I print out the content of the linear buffer > before calling the function I go no problems. > > >It seems like the pointer points to a wrong address. > >Am I missing something?

Sounds like you are messing with near / far declarations? How about turning on mixed mode in debugger and check what the compiler generates?

Markus

Reply to
Markus Zingg
Loading thread data ...

Enrico Migliore wrote in news: snipped-for-privacy@fatti.com:

This puts the variable into the .data segment (GCC terminology), that means it stores 1024 bytes of zero and then copies it to the location of my_array at startup. As this adds greatly to your executable size, you can see why initializing file-scoped variables to zero is a bad idea. If this is block scoped, then it's okay since it does a memset at program run-time each time it enters said block scope.

This puts the variable into the .bss segment (GCC terminology), that means it stores only the size of my_array and memsets it to zero at system start up.

It sounds like you need to look at the C run-time start up code, e.g. crt0.s or cstartup.asm.

--
- Mark ->
--
Reply to
Mark A. Odell

hi Markus,

the compiler is configured to generate far pointers and all vars are correctly allocated in the external/far RAM because, first, the mapviewer.exe tool confirms that, and second I tested the external RAM accesses with the scope and had no problems.

The strange thing is that if I initialize the buffer in this way, all works fine!:

unsigned char my_array[1024] = {0};

If I don't initialize the array, the bug appear:

unsigned char my_array[1024];

thanks for your answer Enrico

thanks M

--
***********************************************************
* Enrico Migliore - Co-founder and Senior Software Engineer
* FATTI srl - The Service Gateway Company
* Via Donatello 48 - 20020 - Solaro - Milano - Italy
* Phone: +3902 9679 9655
* Fax: +3902 9679 9373
* e-mail: enrico.migliore@fatti.com
* http://www.fatti.com***********************************************************
Reply to
Enrico Migliore
[...]

Combined with your earlier mention of having modified the startup file to get the compiler to generate variables in external ram, this almost certainly points the blame at those startup file modifications. They're apparently incomplete: you're not succeeding at initializing the segment of non-initialized data correctly.

--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Reply to
Hans-Bernhard Broeker

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.