int main(void)
{
byte bCount,bID, bTxPacketLength,bRxPacketLength;
PortInitialize(); //Port In/Out Direction Definition
RS485_RXD; //Set RS485 Direction to Input State.
SerialInitialize(SERIAL_PORT0,1,RX_INTERRUPT);//RS485 Initializing(RxInterrupt)
SerialInitialize(SERIAL_PORT1,DEFAULT_BAUD_RATE,0); //RS232 Initializing(None Interrupt)
gbRxBufferReadPointer = gbRxBufferWritePointer = 0; //RS485 RxBuffer Clearing.
sei(); //Enable Interrupt -- Compiler Function
TxDString("\r\n Hello from the CM-5 !\r\n");
while(1);
}
GNU_AVR_PATH=/home/marmakoide/Bioloid/tools
CC=$(GNU_AVR_PATH)/bin/avr-gcc
OBJCOPY=$(GNU_AVR_PATH)/bin/avr-objcopy
CFLAGS=-O2 -mmcu=atmega128 -Wall
OBJECTS=\
./Example.o
TARGET=example
all: $(TARGET).hex $(TARGET).bin
$(TARGET).elf: $(OBJECTS)
$(CC) -o $@ $(OBJECTS)
%.hex:%.elf
$(OBJCOPY) --output-target ihex -R .eeprom $< $@
%.bin:%.elf
$(OBJCOPY) --output-target binary -R .eeprom $< $@
%.o:%.c
$(CC) $(CFLAGS) $(INCLUDES) -o $@ -c $<
clean:
rm -f $(OBJECTS)
cleaner: clean
rm -f $(TARGET).elf $(TARGET).hex $(TARGET).bin
#!/bin/bash
# ----------------------------------------------------------------------------
# build-toolchain.sh $1
#
# $1 Where to install the tools
#
# Build a toolchain for the AVR Atmel GCC C compiler
#
# Based on the following docs :
# http://lists.gnu.org/archive/html/avr-gcc-list/2006-08/msg00098.html
# ----------------------------------------------------------------------------
function download {
if [ ! -f $2 ]; then
wget $1/$2
if [ "$?" -ne "0" ]; then
echo "Fail to download" $2 "at" $1
return 1
fi
fi
}
# --- Init ---
BUILD_TMP=/tmp/
ORIGIN=`pwd`
if [ "$#" -lt 1 ]; then
echo "No installation path specified"
return 1
fi
INSTALL_PATH=$1
# --- Get the packages to install from the net ---
download ftp://sourceware.org/pub/binutils/releases binutils-2.17.tar.bz2
download ftp://ftp.gnu.org/gnu/gcc/gcc-4.1.1 gcc-core-4.1.1.tar.bz2
download http://download.savannah.gnu.org/releases/avr-libc avr-libc-1.4.5.tar.bz2
# --- Build the binutils ---
if [ ! -f ${INSTALL_PATH}/bin/avr-as ]; then
cd ${BUILD_TMP}
tar xjf ${ORIGIN}/binutils-2.17.tar.bz2
cd binutils-2.17
./configure --target=avr \
--prefix=${INSTALL_PATH} \
--disable-nls
make
make install
cd ${ORIGIN}
rm -rf ${BUILD_TMP}/binutils-2.17
fi
# --- Build gcc ---
export PATH=${INSTALL_PATH}/bin:$PATH
if [ ! -f ${INSTALL_PATH}/bin/avr-gcc-4.1.1 ]; then
cd ${BUILD_TMP}
tar xjf ${ORIGIN}/gcc-core-4.1.1.tar.bz2
cd gcc-4.1.1
./configure --target=avr \
--prefix=${INSTALL_PATH} \
--enable-languages="c" \
--disable-libssp \
--disable-nls \
--enable-clocale=gnu
#./configure --target=avr \
# --prefix=${INSTALL_PATH} \
# --enable-languages=c \
# --disable-libssp \
# --enable-__cxa_atexit \
# --enable-clocale=gnu \
# --disable-nls
make
make check
make install
cd ${ORIGIN}
rm -rf ${BUILD_TMP}/gcc-4.1.1
fi
# --- Build the libc ---
if [ ! -f ${INSTALL_PATH}/avr/include/stdio.h ]; then
cd ${BUILD_TMP}
tar xjf ${ORIGIN}/avr-libc-1.4.5.tar.bz2
cd avr-libc-1.4.5
./configure --host=avr --prefix=${INSTALL_PATH} CC="$INSTALL_PATH/bin/avr-gcc"
#./configure --build=`./config.guess` --host=avr --prefix=${INSTALL_PATH}
make
make install
cd ${ORIGIN}
rm -rf ${BUILD_TMP}/avr-libc-1.4.5
fi
TARGET=example
GNU_AVR_PATH = /home/xxx/Bioloid/tools
CC = $(GNU_AVR_PATH)/bin/avr-gcc
OBJCOPY = $(GNU_AVR_PATH)/bin/avr-objcopy
OPTIM_LEVEL = s
#
# Compiler flags
#
CFLAGS = -g
CFLAGS += -O$(OPTIM_LEVEL)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -std=gnu99
OBJECTS =\
./Example.o
LDFLAGS =
all: $(TARGET).hex $(TARGET).bin
$(TARGET).elf: $(OBJECTS)
$(CC) -mmcu=atmega128 $(LDFLAGS) -o $@ $(OBJECTS)
%.hex:%.elf
$(OBJCOPY) -O ihex -R .eeprom $< $@
%.bin:%.elf
$(OBJCOPY) -O binary -R .eeprom $< $@
%.o:%.c
$(CC) -mmcu=atmega128 $(CFLAGS) -o $@ -c $<
clean:
rm -f $(OBJECTS)
cleaner: clean
rm -f $(TARGET).elf \
$(TARGET).hex \
$(TARGET).bin
Marmakoide wrote:Problem solved, seems to be a compiler flag order issue
Here it is the script I made to build my Linux/GCC cross-compiler
- Code: Select all
#!/bin/bash
# ----------------------------------------------------------------------------
# build-toolchain.sh $1
#
# $1 Where to install the tools
#
# Build a toolchain for the AVR Atmel GCC C compiler
#
# Based on the following docs :
# http://lists.gnu.org/archive/html/avr-gcc-list/2006-08/msg00098.html
# ----------------------------------------------------------------------------
function download {
if [ ! -f $2 ]; then
wget $1/$2
if [ "$?" -ne "0" ]; then
echo "Fail to download" $2 "at" $1
return 1
fi
fi
}
# --- Init ---
BUILD_TMP=/tmp/
ORIGIN=`pwd`
if [ "$#" -lt 1 ]; then
echo "No installation path specified"
return 1
fi
INSTALL_PATH=$1
# --- Get the packages to install from the net ---
download ftp://sourceware.org/pub/binutils/releases binutils-2.17.tar.bz2
download ftp://ftp.gnu.org/gnu/gcc/gcc-4.1.1 gcc-core-4.1.1.tar.bz2
download http://download.savannah.gnu.org/releases/avr-libc avr-libc-1.4.5.tar.bz2
# --- Build the binutils ---
if [ ! -f ${INSTALL_PATH}/bin/avr-as ]; then
cd ${BUILD_TMP}
tar xjf ${ORIGIN}/binutils-2.17.tar.bz2
cd binutils-2.17
./configure --target=avr \
--prefix=${INSTALL_PATH} \
--disable-nls
make
make install
cd ${ORIGIN}
rm -rf ${BUILD_TMP}/binutils-2.17
fi
# --- Build gcc ---
export PATH=${INSTALL_PATH}/bin:$PATH
if [ ! -f ${INSTALL_PATH}/bin/avr-gcc-4.1.1 ]; then
cd ${BUILD_TMP}
tar xjf ${ORIGIN}/gcc-core-4.1.1.tar.bz2
cd gcc-4.1.1
./configure --target=avr \
--prefix=${INSTALL_PATH} \
--enable-languages="c" \
--disable-libssp \
--disable-nls \
--enable-clocale=gnu
#./configure --target=avr \
# --prefix=${INSTALL_PATH} \
# --enable-languages=c \
# --disable-libssp \
# --enable-__cxa_atexit \
# --enable-clocale=gnu \
# --disable-nls
make
make check
make install
cd ${ORIGIN}
rm -rf ${BUILD_TMP}/gcc-4.1.1
fi
# --- Build the libc ---
if [ ! -f ${INSTALL_PATH}/avr/include/stdio.h ]; then
cd ${BUILD_TMP}
tar xjf ${ORIGIN}/avr-libc-1.4.5.tar.bz2
cd avr-libc-1.4.5
./configure --host=avr --prefix=${INSTALL_PATH} CC="$INSTALL_PATH/bin/avr-gcc"
#./configure --build=`./config.guess` --host=avr --prefix=${INSTALL_PATH}
make
make install
cd ${ORIGIN}
rm -rf ${BUILD_TMP}/avr-libc-1.4.5
fi
Here it is the Makefile that works
- Code: Select all
TARGET=example
GNU_AVR_PATH = /home/xxx/Bioloid/tools
CC = $(GNU_AVR_PATH)/bin/avr-gcc
OBJCOPY = $(GNU_AVR_PATH)/bin/avr-objcopy
OPTIM_LEVEL = s
#
# Compiler flags
#
CFLAGS = -g
CFLAGS += -O$(OPTIM_LEVEL)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -std=gnu99
OBJECTS =\
./Example.o
LDFLAGS =
all: $(TARGET).hex $(TARGET).bin
$(TARGET).elf: $(OBJECTS)
$(CC) -mmcu=atmega128 $(LDFLAGS) -o $@ $(OBJECTS)
%.hex:%.elf
$(OBJCOPY) -O ihex -R .eeprom $< $@
%.bin:%.elf
$(OBJCOPY) -O binary -R .eeprom $< $@
%.o:%.c
$(CC) -mmcu=atmega128 $(CFLAGS) -o $@ -c $<
clean:
rm -f $(OBJECTS)
cleaner: clean
rm -f $(TARGET).elf \
$(TARGET).hex \
$(TARGET).bin
My procedure to upload a .bin executable to the CM-5 :
* lauching gtkterm (As minicom but with a more handy user interface)
* setting the connection to 57600 bauds, 1 stop bit, no parity bits, no stream control
* doing the #-and-red-button trick to enter in the bootloader (Matrix, here we come )
* typing load in the gtkterm shell
* sending my .bin file with the gtkterm ASCII file send functionality
* it's done, don't care about the CM-5 checksum complaints
Igga wrote:Thank you friend,
I understood my mistake.
Could you help with two more question:
1) Did you change the rs232 interface part in the example program.
I tried to compile it as you suggested, but it showed many errors
related to interface. Linux has different communication procedure with the interface, right?
Could you send the whole C code of your project?
2) Is there a linux driver for usb2dynamixel?
Thank you and best wishes for the New Year!!
Igga wrote:Hi,
USB2dynamixel is working perfectly under Linux.
The program BRLTTY didnt allow the driver to work properly.
It is explained here:
http://www.ladyada.net/learn/arduino/lesson0-lin.html
Igga wrote:However my example.hex program is not working if i program the CM-5 under linux.
Cheers!