Go Down

Topic: command line compilation and upload problem (Read 605 times) previous topic - next topic

c7s9

Hi,
I've tried to compile my project from command line under linux without succeeding  :(
For my test I used an old duemilanove with the atmega168 chip.

The code I used is the following
Code: [Select]

#include <Arduino.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(3,2); // pin 2 = TX, pin 3 = RX (unused)

void setup()
{
  mySerial.begin(9600); // set up serial port for 9600 baud
  delay(500); // wait for display to boot up
}

void loop()
{
  mySerial.write(254); // move cursor to beginning of first line
  mySerial.write(128);
  mySerial.write("  Hello World!  ");
  mySerial.write("  Hello World!  ");
  mySerial.write(124); // save to pic memory
  mySerial.write(10);
  while(1);
}

The purpose of the code (which works under the standard arduino IDE) changes the splash screen of an lcd display sold by sparkfun.
To compile the code I used  avr-gcc and  avr-g++ specifying "-mmcu=atmega168" and all the other options found at
this link: http://playground.arduino.cc/Code/CmakeBuild.

Together with my file (wich I named change_splash.cpp) I compiled all the necessary *.c and *.cpp files which I found
in the version 1.0.3 of the ide. After some tweaking I managed to link everything and got the executable I named "change_splash".

After this I run the following commands:
avr-objcopy -O ihex -R .eeprom change_splash output.hex
sudo avrdude -V -c arduino -p m168 -b 19200 -P /dev/ttyUSB0 -U flash:w:output.hex
The upload worked correctly.

After uploading the arduino board doesn't run the program correctly (the display remains blank instead of showing the new splash screen).
If I use the ide to load the program the boards starts working properly again.

Since I'm new cross-compilation I'm a bit lost at this point.
Is there someone who can help me?
Thanks
Carlo

westfw

Can you post a log of all the steps you did, with the associated output?

c7s9

I'm sorry for not posting all the info in the first post...
What I was trying to do is to compile and upload the code in the arduino board using cmake. I found some code on the net but it
is too complicated from my point of view, and so I wrote my own.
My intention is to clean the file after it works and make it available to other people.

This is my CMakeLists.txt
Code: [Select]

cmake_minimum_required(VERSION 2.8)
set(CMAKE_SYSTEM_NAME Generic)

set(CMAKE_C_COMPILER avr-gcc)
set(CMAKE_CXX_COMPILER avr-g++)

set(CSTANDARD "-std=gnu99")
set(CDEBUG "-gstabs")
set(CWARN "-Wall -Wstrict-prototypes")
set(CTUNING "-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums")
set(COPT "-Os")
set(CMCU "-mmcu=atmega168")
set(CDEFS "-DF_CPU=16000000")


set(CFLAGS "${CMCU} ${CDEBUG} ${CDEFS} ${COPT} ${CWARN} ${CSTANDARD} ${CEXTRA}")
set(CXXFLAGS "${CMCU} ${CDEFS} ${COPT}")

set(CMAKE_C_FLAGS ${CFLAGS})
set(CMAKE_CXX_FLAGS ${CXXFLAGS})

set(ARDUINO_SRC_DIR "${CMAKE_SOURCE_DIR}/../arduino-1.0.3") #this is the directory containing the arduino ide and the other files

include_directories(${ARDUINO_SRC_DIR}/hardware/arduino/cores/arduino)
include_directories(${ARDUINO_SRC_DIR}/hardware/arduino/variants/standard)
include_directories(${ARDUINO_SRC_DIR}/libraries/SoftwareSerial)

#creation of a library containing the core functionalities from the arduino project
#the library contains also the file main.cpp which declares the main function
file(GLOB ARDUINO_CORE_CPP "${ARDUINO_SRC_DIR}/hardware/arduino/cores/arduino/*.cpp")
file(GLOB ARDUINO_CORE_C "${ARDUINO_SRC_DIR}/hardware/arduino/cores/arduino/*.c")
add_library(arduinocore ${ARDUINO_CORE_C} ${ARDUINO_CORE_CPP})

#creation of the library with the SoftwareSerial code
add_library(SoftwareSerial ${ARDUINO_SRC_DIR}/libraries/SoftwareSerial/SoftwareSerial.cpp)

#creation of my executable
add_executable(change_splash  change_splash.cpp)
target_link_libraries(change_splash  SoftwareSerial arduinocore)

#code for the conversion elf -> hex
add_custom_target(hex
COMMAND avr-objcopy -O ihex -R .eeprom change_splash output.hex
       DEPENDS change_splash)

#code for the upload
add_custom_target(upload
       COMMAND avrdude -V -c arduino -p m168 -b 19200 -P /dev/ttyUSB0 -U flash:w:output.hex
       DEPENDS hex)


With this file and the one I put in my previous post (change_splash.cpp) I did the following:
1) cd change_splash      (this is the directory containing change_splash.cpp and CMakeLists.txt)
2) mkdir build
3) cd build
4) cmake ..
Output:
Code: [Select]

-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/csavorgn/arduino/change_splash/build

5) make VERBOSE=1
Output ( I cut part of it, but there are no error messages)
Code: [Select]

....
[100%] Building CXX object CMakeFiles/change_splash.dir/change_splash.cpp.o
avr-g++    -mmcu=atmega168 -DF_CPU=16000000 -Os -I/home/csavorgn/arduino/change_splash/../arduino-1.0.3/hardware/arduino/cores/arduino -I/home/csavorgn/arduino/change_splash/../arduino-1.0.3/hardware/arduino/variants/standard -I/home/csavorgn/arduino/change_splash/../arduino-1.0.3/libraries/SoftwareSerial    -o CMakeFiles/change_splash.dir/change_splash.cpp.o -c /home/csavorgn/arduino/change_splash/change_splash.cpp
Linking CXX executable change_splash
/usr/bin/cmake -E cmake_link_script CMakeFiles/change_splash.dir/link.txt --verbose=1
avr-g++   -mmcu=atmega168 -DF_CPU=16000000 -Os    CMakeFiles/change_splash.dir/change_splash.cpp.o  -o change_splash -rdynamic libSoftwareSerial.a libarduinocore.a
avr-g++: unrecognized option '-rdynamic'
make[2]: Leaving directory `/home/csavorgn/arduino/change_splash/build'
/usr/bin/cmake -E cmake_progress_report /home/csavorgn/arduino/change_splash/build/CMakeFiles  20
[100%] Built target change_splash
make[1]: Leaving directory `/home/csavorgn/arduino/change_splash/build'
/usr/bin/cmake -E cmake_progress_start /home/csavorgn/arduino/change_splash/build/CMakeFiles 0

6) make hex VERBOSE=1
Output (I cut the first part):
Code: [Select]

...
make[3]: Entering directory `/home/csavorgn/arduino/change_splash/build'
avr-objcopy -O ihex -R .eeprom change_splash output.hex
make[3]: Leaving directory `/home/csavorgn/arduino/change_splash/build'
/usr/bin/cmake -E cmake_progress_report /home/csavorgn/arduino/change_splash/build/CMakeFiles
[100%] Built target hex
make[2]: Leaving directory `/home/csavorgn/arduino/change_splash/build'
/usr/bin/cmake -E cmake_progress_start /home/csavorgn/arduino/change_splash/build/CMakeFiles 0
make[1]: Leaving directory `/home/csavorgn/arduino/change_splash/build'

7) make upload VERBOSE=1
Output (I cut the first part):
Code: [Select]

avrdude -V -c arduino -p m168 -b 19200 -P /dev/ttyUSB0 -U flash:w:output.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9406
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
        To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "output.hex"
avrdude: input file output.hex auto detected as Intel Hex
avrdude: writing flash (15328 bytes):

Writing | ################################################## | 100% 9.98s

avrdude: 15328 bytes of flash written

avrdude: safemode: Fuses OK

avrdude done.  Thank you.



After doing this I checked the board but it doesn't work...

Carlo

c7s9

Is there nobody who can help?
Am I missing some steps in my procedure?

Carlo

Go Up