- 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 (turbo-app utility) or programmer (cemu utility) directly to MCU program memory or with 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 -mno-tablejump -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
indent:
for X in *.[ch]; do \
indent -npsl -sob -bad -bli0 -cli2 $$X; \
done
clean:
$(RM) *.o
$(RM) *.d
$(RM) *.i
$(RM) *.s
$(RM) *~
$(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
- -mno-tablejump - avoid tablejumps, which can cause problem with rellocation of long switch/case constructions
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 into the program memory.
For uploading of the file you have two options:
- over serial data cable connected to the phone with the help of turbo-cable-utils, turbo-app utility
- use programmer and turbo-prog-utils, cemu utility
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-app utility for uploading the file
Example:
In this case you insert Turbo (with SIM card) into the SIM connector on the programmer and with the help of cemu utility copy file into Turbo program memory.
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-2006 BLADOX
| Turbo version 1.2
|