[En-Nut-Discussion] Question regarding nutinit.c

Malte Marwedel m.marwedel at onlinehome.de
Mon Sep 14 13:51:16 CEST 2009


Hello,
beside that my mp3 player finally plays a mp3 free of glitches :-D 
(using SPI with a MMC and a VS1002), I still have the problem, that 
Nut/OS always hangs somewhere on the first power-up. My current 
work-around is to to enable the watchdog in .init1 and after one 
watchdog bite, Nut/OS starts on the second try. As this is no permanent 
solution, I wanted to track down the problem and analyzed 
arch/avr/os/nutinit.c

The first mismatch I found is the following:
 > 0x1100-0x14FF  CLPD area  -> use 3 Waitstates for 0x1100-0x1FFF (no
 > Limit at 0x1500 available)
 >    0x1500-0xFFFF  Heap/Stack -> use 1 Waitstate  for 0x2000-0xFFFF
 >    */
 >    MCUCR  = _BV(SRE); /* enable xmem-Interface */
 >    XMCRA |= _BV(SRL0) | _BV(SRW01) | _BV(SRW00);
If 1 Waitstate  should be used, I think it should be
MCUCR  = _BV(SRE) | _BV(SRW10);
I dont know if either the code or the comment is wrong, as I dont know 
why a wait state is necessary and my board worked (well mostly) without it.

The second thing I found is, that some code looks to be called twice:
.init1:
   NutCustomInit
     sets MCUCR
   NutInitXRAM
     sets MCUCR
.init5:
   NutInitSP
   NutInitHeap
.init8:
   NutInit
     NutCustomInit
     NutInitHeap
     NutLoadConfig
     NutThreadCreate

So it looks like NutCustomInit and NutInitHeap gets called twice. While 
this is no problem for NutCustomInit, I wonder if this could cause 
conflicts, if the same memory region is added as heap twice.

Did I oversee something and the functions are not called twice, is it no 
problem to call NutHeapAdd twice for the same region, or is this may be 
a bug?

Greetings,
Malte Marwedel



More information about the En-Nut-Discussion mailing list