- Note:
- We describe the development environment for linux and possibly other unices here. It is also possible to have the same environment for win32 but we have yet to try it.
The development consists of 3 main steps:
- write your code, compile and link
- convert resulting object yourapp.elf into yourapp.trb - Turbo application object format
- upload yourapp.trb either via cable directly to MCU program memory or via programmer to memory card (from where user simply selects yourapp.trb and installs it into program memory).
Devel and Install
For development and building of Turbo applications you need the following tools:
- gcc - GNU project C compiler configured for AVR architecture;
- binutils - GNU project set of utilities for linking and object code manipulation configured for AVR architecture; application specific format --turbo support patch by BLADOX;
- turbo-devel - package containing Turbo specific libc, headers and linker scripts.
As for gcc you can use the vanilla gcc from any GNU mirror, binutils have to be patched to provide turbo specific binary application format.
The binutils and turbo-devel packages can be found on http://www.bladox.com/.
Untar and ./configure --target=avr
make
make install
installs all the AVR binutils into /usr/local/.
Untar and ./configure --target=avr --enable-languages=c
make
make install
installs all the AVR gcc into /usr/local/.
Untar the package somewhere (and use this path in Makefiles).
- Example of Makefile
ifndef TURBO_DIR
TURBO_DIR = ../../turbo-devel
endif
TURBO_TAG = --turbo-manifest "YOUR_MANIFESTO" #--turbo-verbose
INCDIR = -I$(TURBO_DIR)/include -I.
LIBDIR = $(TURBO_DIR)/lib
CC = avr-gcc
LD = avr-ld
RM = rm -f
TRG = YOUR_TARGETNAME
SRC = YOUR_SOURCE1.c YOUR_SOURCE2.c ... YOUR_SOURCEn.c
LIB =
CFLAGS = -std=gnu99 -mmcu=atmega128 -Wimplicit-function-declaration -Os -fno-builtin
LDFLAGS = -L$(LIBDIR) -T turbo.lds -d -r --emit-relocs -R $(LIBDIR)/public_calls $(LIB) -lm -lc `avr-gcc -print-libgcc-file-name`
OBJ = $(SRC:.c=.o)
all: $(TRG).trb
include $(SRC:.c=.d)
%.o : %.c
$(CC) -c $(CFLAGS) $(INCDIR) $< -o $@
%.d: %.c
$(CC) -M $(CFLAGS) $(INCDIR) $< | sed 's/$*.o/& $@/g' >$@
$(TRG).elf: $(OBJ)
$(LD) -o $@ $(OBJ) $(LDFLAGS)
$(TRG).trb: $(TRG).elf
avr-objdump $(TURBO_TAG) --turbo $(TRG).elf
dis: $(TRG).elf
avr-objdump -D --architecture=avr:5 $(TRG).elf >$(TRG).dis
install: all
cp $(TRG).trb ../bin
clean:
$(RM) *.o
$(RM) *.d
$(RM) $(TRG).dis
$(RM) $(TRG).elf
$(RM) $(TRG).trb
Meaning of CFLAGS:
- -fno-builtin - to avoid usage of compiler internal strlen, etc.
- -std=gnu99 - to avoid some warnings
- -Wimplicit-function-declaration - it is really good to avoid implicit function declaration (code may be worse)
- -Os - optimize for size. For us size is more important than anything else.
- -mmcu=atmega128 - desired target
Meaning of LDFLAGS:
- -Tdata 0x800000 - starting address of the data section
- -T turbo.lds - use linker script turbo.lds
- -R /public_calls - read symbol names and their addresses from .../public_calls
- --emit-relocs - leave relocations sections in fully linked executable
- -d - assign space to commons symbols even if -r
- -r - generate relocatable output
trb and elf are created, dis when "make dis"
Assume that you have built your application and the result is helloworld.trb file. The next step is uploading this file to the memory card so it could be installed (flashed) to the AVR program memory.
For uploading of the file to the memory card you have two options:
- over serial data cable connected to the phone with the help of turbo-cable-utils
- use programmer and turbo-prog-utils
The advantage of this method is that you do not need to have the programmer. On the other hand you need to have phone which supports AT commands for SMS manipulation - notably AT+CMGR, AT+CMGW, AT+CMGD commands. Check your phone docs for the support of these commands.
The setup is following:
- install Turbo, have the phone running, connect data cable
- use turbo-cp utility for uploading the file
Example:
turbo-cp helloworld.trb /apps/helloworld.trb
In this case you insert the memory card into the MMC connector on the programmer and with the help of tcp utility copy files to the card. This scenario is more comfortable and faster then use of cable.
Debugging in the embedded world is not that easy as you may know from developing in "full-size" world. You cannot easily attach debugger to the running process, setup breakpoints and see variables. Also you do not have any direct screen where you could see the partial printouts.
For Turbo debugging you need to use the USB programmer we provide. When connected to the Turbo your application can send printouts to programmer and with programmer util called dbg you can see the results.
Example:
In your code (we suggest config.h) define (or comment out)
and use the macros dbsp(), dbc(), dbih(), dbch().
Example:
u16 i;
u8 c;
...
dbsp("We are here\n");
dbsp("Value of short in hex is ");dbih(i);dbc('\n');
dbsp("Value of char in hex is ");dbch(c);dbc('\n');
...
This complied with DEBUG defined will produce longer code and with dbg utility you will see the messages.
- Note:
- We suggest to use "dbg|tee my_log" to save the output to the file.
When the same code is compiled without the DEBUG defined the db*() macros will be empty and no extra debugging code will be included in your application.
Copyright © 2004 BLADOX
| Turbo version 1.0
|