[En-Nut-Discussion] simulate ethernut sample in avr studio

Andreas Heinzen heinzen at fh-koblenz.de
Wed Sep 20 18:06:06 CEST 2006


Yes, I had read the FAQ and all the documents in web I found, which
say it didn't work.

But I gave it a try and for simulate some hardware I used hapsim,
http://www.helmix.at/hapsim/

so my experiment starts with:
AVR Studio 4.12.490 (SP3)
HAPSIM V 2.07

I opened in AVR Studio a new project lcd without any auto generated files.
The project dir should be saved in the ethernut $top_appdir

The lcd.c:
#######################################
#include <compiler.h>
#include <stdio.h>
#include <dev/hd44780.h>
#include <dev/term.h>
/* Connect Definitions found in cfg/medianut.h
LCD DATA Port   = PORT D Bits 4..7
Reg. Select PIN = PORT E Bit 2
Enable PIN      = PORT E Bit 3
Read/Write PIN  = PORT E Bit 4
(see also hapsim file lcd.xml)
*/

void main(void)
{
        NutRegisterDevice(&devLcd, 0, 0);
        freopen("lcd", "w",stdout);
        printf("Hello world!\n");
}
#######################################

The external Makefile  used for compilation:
#######################################
PROJ = lcd

include ../Makedefs

CPFLAGS +=  -gdwarf-2


SRCS =  $(PROJ).c
OBJS =  $(SRCS:.c=.o)
LIBS =  $(LIBDIR)/nutinit.o -lnutos -lnutarch -lnutdev -lnutcrt $(ADDLIBS)


all: $(OBJS) $(TARG) $(DTARG) info

include ../Makerules

info:
#        avr-nm  -Sa $(DTARG)
        avr-objdump -h $(DTARG)
        avr-size -xA $(DTARG)


clean:
        -rm -f $(OBJS)
        -rm -f $(TARG)
        -rm -f $(DTARG)
        -rm -f $(PROJ).eep
        -rm -f $(PROJ).obj
        -rm -f $(PROJ).map
        -rm -f $(SRCS:.c=.lst)
        -rm -f $(SRCS:.c=.bak)
        -rm -f $(SRCS:.c=.i)
#######################################

My hapsim file shows 1 lcd-display and is conected  as discribed
in lcd.c open it in hapsim, in my simulation I also connected one
led to each Pin of PORTD and  PORTE,
to see that something happens, but the mail gets to long ;-)
.
lcd.xml:
#######################################
<?xml version="1.0"?>
<HAPSIM>
   <General>
      <Build>1793</Build>
      <Position>
         <top>326</top>
         <bottom>531</bottom>
         <left>441</left>
         <right>868</right>
      </Position>
      <StayOnTop>1</StayOnTop>
      <Target>ATmega128</Target>
   </General>
   <Views>
      <LCD>
         <Name>LCD1</Name>
         <Position>
            <top>14</top>
            <left>78</left>
         </Position>
         <DisplayConfig>
            <columns>16</columns>
            <rows>2</rows>
            <bkColor>0xc1fa9d</bkColor>
            <size>2</size>
         </DisplayConfig>
         <PortMapping>
            <DataPort>
               <Port>PORTD</Port>
               <HighNibble>bit 4..7</HighNibble>
               <LowNibble>N.C.</LowNibble>
            </DataPort>
            <EnablePin>
               <Port>PORTE</Port>
               <Bit>3</Bit>
            </EnablePin>
            <RW_Pin>
               <WriteOnly>1</WriteOnly>
               <Port>PORTE</Port>
               <Bit>3</Bit>
            </RW_Pin>
            <RS_Pin>
               <Port>PORTE</Port>
               <Bit>2</Bit>
            </RS_Pin>
         </PortMapping>
      </LCD>
   </Views>
</HAPSIM>
#######################################

What should I say, after compiling, starting the debugger, hook hapsim to
AVR Studio it works, ...
but with hundreds of warning messages about:

AVR Simulator: Uninitialized stack pointer used at ...
AVR Simulator: Stack Overflow at ...
...
AVR Simulator: Stack Underflow at ...
...

Because of these messages the simulation is unusable slow, I think it tooks
more than 10 minutes to get the "hello world!" on the hapsim display
(But it works!!!).

So I made some analyze of the resulting elf target.

And found out, by comparing with an another project, that there is an
section .debug_range missing.

Another mystery, when you look at the Makefile, you find the line 
#        avr-nm  -Sa $(DTARG)

by removing the comment the build fails with three errors and shows:
NutTimerStop
NutTimerStopAsync
nutTimerStopped
as the reason.

I also build the Nut/OS with -gdwarf-2 and it was very interesting
to debug through C-Code of the initialize process, to find out 
what is going wrong, but i didn't realy no what I'm searching for.

I hope someone here in the list with more knowledge about avr-gcc and 
what should happen to initialize correct, gets some hints through my
experiments and could fix the problem.

Sorry, about the long mail.

Andreas Henzen



More information about the En-Nut-Discussion mailing list