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
#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: Arduino Playground - 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
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
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:
cd change_splash (this is the directory containing change_splash.cpp and CMakeLists.txt)
mkdir build
cd build
cmake ..
Output:
-- 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
make VERBOSE=1
Output ( I cut part of it, but there are no error messages)