Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
kewley
PostPosted: Jan 31, 2012 - 05:00 PM
Newbie


Joined: Jan 31, 2012
Posts: 2


I'm making a clock using 7-seg displays. I'm storing the port values in an array, but for some reason I'm having trouble with it. I've changed the code and put it in a basic form. It works if I use AVR Studio (version 5) on Windows, but the output is always 0xFF regardless using avr-gcc on Linux.

Code:
Code:
#include <avr/io.h>

int main( void )
{
    const uint8_t t[] = { 0x00, 0xFF };

    DDRD = 0xFF;
    PORTD = t[0];

    while( 1 );

    return 0;
}


Makefile for linux:
Code:
GNU nano 2.2.6              File: Makefile                                   

GCCFLAGS=-g -Wall -mmcu=atmega328p
LINKFLAGS=
AVRDUDEFLAGS=-B 250 -c avrisp2 -P usb -p m328p
NAME=test

all:    ${NAME}-upload

${NAME}.hex:    ${NAME}.c
    avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o ${NAME}.o ${NAME}.c ${LINKOBJECTS}
    avr-objcopy -j .text -O ihex ${NAME}.o ${NAME}.hex

${NAME}.ass:    ${NAME}.hex
    avr-objdump -S -d ${NAME}.o > ${NAME}.ass

${NAME}-upload: ${NAME}.hex
    avrdude ${AVRDUDEFLAGS} -U flash:w:${NAME}.hex:a


Build output from AVR Studio:

Code:
------ Build started: Project: test, Configuration: Debug AVR ------
Build started.
Project "test.avrgccproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\AVR Studio 5.0\Vs\AvrGCC.targets" from project "C:\Users\Craig\Documents\AVRStudio\test\test\test.avrgccproj" (target "Build" depends on it):
   Using "RunAvrGCC" task from assembly "C:\Program Files (x86)\Atmel\AVR Studio 5.0\Vs\AvrGCCLib.dll".
   Task "RunAvrGCC"
      C:\Program Files (x86)\Atmel\AVR Studio 5.0\AVR ToolChain\bin\make.exe all
test.c
      Invoking: AVR/GNU C Compiler
      "C:/Program Files (x86)/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe" -funsigned-char -funsigned-bitfields -O0 -fpack-struct -fshort-enums -g2 -Wall -c -std=gnu99  -mmcu=atmega328p   -MD -MP -MF"test.d" -MT"test.d" -o"test.o" ".././test.c"
      Finished building: .././test.c
      Building target: test.elf
      Invoking: AVR/GNU C/C++ Linker
      "C:/Program Files (x86)/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe"  -mmcu=atmega328p  -Wl,-Map=test.map -o test.elf  test.o 
      Finished building target: test.elf
      "C:/Program Files (x86)/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature  "test.elf" "test.hex"
      "C:/Program Files (x86)/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objdump.exe" -h -S "test.elf" > "test.lss"
      "C:/Program Files (x86)/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "test.elf" "test.eep" || exit 0
      AVR Memory Usage
      ----------------
      Device: atmega328p
      Program:     188 bytes (0.6% Full)
      (.text + .data + .bootloader)
      Data:          2 bytes (0.1% Full)
      (.data + .bss + .noinit)
   Done executing task "RunAvrGCC".
Done building target "CoreBuild" in project "test.avrgccproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "Build" in file "C:\Program Files (x86)\Atmel\AVR Studio 5.0\Vs\Avr.common.targets" from project "C:\Users\Craig\Documents\AVRStudio\test\test\test.avrgccproj" (entry point):
Done building target "Build" in project "test.avrgccproj".
Done building project "test.avrgccproj".

Build succeeded.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jan 31, 2012 - 05:04 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62218
Location: (using avr-gcc in) Finchingfield, Essex, England

Code:
    avr-objcopy -j .text -O ihex ${NAME}.o ${NAME}.hex

Code:
      "C:/Program Files (x86)/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature  "test.elf" "test.hex"

One of these things is not like the other one. Sure you can use -j's instead or -R's if you want (one adds, one subtracts) but if you are using -j you must add .data as well as .text as it's that .data that contains your initial values.

BTW this is really a question about GCC in particular so that's where this is headed..

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
kewley
PostPosted: Feb 01, 2012 - 01:41 PM
Newbie


Joined: Jan 31, 2012
Posts: 2


Thanks for the move and help, it works perfect now!
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits