Embedded Programming
Back to Mónica Pedro ←main page ←Assigments
individual assignment:
read a microcontroller data sheet
program your board to do something,
with as many different programming languages
and programming environments as possible
group assignment:
compare the performance and development workflows
for other architectures
Microcontroller data sheet
About the Microcontroller Attiny44 and MyBoard
Significant facts:
- Button is connect to PA3
- LED is connect to PA7
FTDI
I'll use the SparkFun FTDI Basic Breakout - 5V
- It uses a SMD 6-pin header on the bottom
- is a basic breakout board for the FTDI FT232RL USB to serial IC
- the pinout of this board matches the FTDI cable to work with official Arduino and cloned 5V Arduino boards.
- major difference is: brings out the DTR pin as opposed to the RTS pin of the FTDI cable... will auto reset any Arduino board that has the reset pin brought out to a 6-pin connector.
- the pins labeled BLK and GRN correspond to the colored wires on the FTDI cable.
- The black wire on the FTDI cable is GND, green is CTS.
- This board has TX and RX LEDs that make it a bit better to use over the FTDI cable. You can actually see serial traffic on the LEDs to verify if the board is working.
- One of the nice features of this board is a jumper on the back of the board that allows the board to be configured to either 3.3V or 5V (both power output and IO level). This board ship default to 5V, but you can cut the default trace and add a solder jumper if you need to switch to 3.3V.
other important learnings:
- MACPorts project is a open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the MAC OS. MacPorts
Programming my board to do something
The microcontrollers that we'd been using are AVR, namely Attiny44 and Attiny45, so I need to understand how to program them
Sources of knowledge:
AVR Lib user manual.pdf
Microchip AVR Libc Reference Manual
Programming Environments
Inspired by professor Neil Gershenfel I wanted to use low level programming, namely through Mac OS Terminal, so I strugled to install it... wuite a lot....
AVR ToolChain:
- FSF: Free Software Foundation promotes the development of and use of free software, particularly the GNU operating system, used widely in its GNU/Linux variant.
- GCC - One of the main projects of GNU systems is the GNU Compiler Collection, or GCC, and its sister project, the Binutils. The two open source projects provide a foundation for a software development toolchain. (originzally to run on Linux-like systems).
- GCC is a highly flexible compiler systems, in which
- host system is the system (processor/OS) that the compiler runs on.
- build system, is the system that the compiler is built (from source code) on.
- is the compiler has the same system for host and target its known as native compiler
- is the compiler has the different system for host and target its known as cross-compiler
- Bunutils: stands for "Binary Utilities". It contains the GNU assembler (gas), and the GNU linker (ld), but also contains many other utilities that work with binary files that are created as part of the software development toolchain.
- avr-lib: The open source AVR toolchain has its own Standard C Library project. This because GCC and Binutils provides a lot of the tools to develop software, but there is one critical component that they do not provide: a Standard C Library. There are different open source projects that provide a Standard C Library depending upon your system time, whether for a native compiler (GNU Libc), for some other embedded system (newlib), or for some versions of Linux (uCLibc).
- MAKE File: contains dependency rules, showing which output files are dependent upon which input files, and instructions on how to build output files from input files.
- GNU Make is a program that makes things, and mainly software. Make interprets and executes a Makefile that is written for a project.
- AVRDUDE is a program that can interface with various hardware devices to program its processor.
- is used to update or read the flash and EEPROM memories of Atmel AVR microcontrollers on FreeBSD Unix.
- uses the PC's parallel port
- can upload either a raw binary file or an Intel Hex format file.
- can be used in an interactive mode to individually update EEPROM cells, fuse bits, and/or lock bits.
- onse installed, avrdude can program processors using the contents of .hex file specified on the command line.
Installing GNU ToolChain
- in Mac OS terminal: echo $PATH to see the Shell Path
- update the Shell Path to include AVR folder fallowing this elegant documentation: Modify the Shell Path in macOS Sierra
- Install GNU Binutils on AVR folder
- Install GNU in AVR folder
- brew tap homebrew/versions... and it showed the message: "Updating Homebrew..." which ended with the message: "Error: homebrew/versions was deprecated. This tap is now empty as all its formulae were migrated."
- brew install which ended without erros...
- Install AVR LibC - will try using homebrew since it had been a GCC clean installation. found this directions: Homebrew AVR Toolchain
- brew tap osx-cross/avr, which resulted in
- brew install avr-gcc - which resulted in
, almost 20 minuts...
- Install avrdude - HomeBrew worked just fine above, so I used it again: brew install avrdude which resulted ...
- HomeBrew Instructions
Using the GNU toolchain
Readings for leaning
GCC and Make
- Check the Tool Chain:
- $ gcc -v Display information about GCC version
- $ gcc --help Display GCC command options
- $ man gcc GCC command manual
- $ nano hello.c to create a C file
- $ ls to see if there's something new... and it was a.out file
- $ chmod a+x a.out to create a C file
- About the chmod command see Linux chmod command
- its used to change the permissions of files and directories
- so this line was to change the permissions: ALL users access + READ of the file
- $ ./a.out to realy execute the program, which RESULTED...
- but... what if we want to compile the code and store it in a file instead of showing in terminal????
- $ gcc -o hello hello.c will compile "hello.c" and store it in a new file "hello" in current directory
- $ chmod a+x hello to change the permissions of new executable file "hello"
- $ ./hello just to call the executable program which results in....
- but very FUNY is to see what it had done with the verbose option: $ gcc -v -o hello hello.c which gives the amassing message:
about .h .lib .a .dll .so
- Library is a collection of pre-compiled object files that can be linked into our programs via the linker.
- static library has the file extension of ".a" (archive file) in Unix/MAC.
- ___ When our program is linked to a static library, the machine code of external functions used in our program is copied into the executable
- shared library has the file extenson of ".so" (shared objects) in Unix/Mac.
- ___ When our program is linked against a shared library, only a small table is created in the executable.
- ___ Before the executable starts running, the operating system loads the machine code needed for the external functions - a process known as dynamic linking.
- ____ dynamic linking makes executable files smaller and saves disk space, because one copy of a library can be used and shared between multiple programs.
- ___ most operating systems aloows one copy os shared library in memory to be used by all running programs, thus, saving memory.
about -I -L -l
- the compiller needs header files to compile the source codes;
- the linker needs the librries to resolve external references from other object files or libraries.
- we need to set the the appropriate options for compiller and linker in order them to find the headers and libraries.
- for each of the headers (#include), the compiler searcher the so-called include-paths for these headers.
- ___ the library-path is specified via -Ldir option (or environment variable LIBRARY_PATH)
- ___ In addition we also need to specify the library name.
- ___ in Unixes, the library libxxx.a is specified via -lxxx option (lowercase letter 'l', without the prefix 'lib' and '.a' extension)
- ___ the linker need to know both the directories as well the library names.
GCC Environement variables
- PATH for searching the executables and run-time shared libraries (.so)
- CPATH for searching the includ-paths for headers.
- ____ It is searched after paths specified in "-Ixxxxx" options.
- LIBRARY_PATH for searching library-paths for link libraries.
- ____ it is searched after paths specified in "-Lxxxx" options.
GNU Make
- the make utility automates the mundane aspects of building executable from source coce.
- ___ uses a so-called makefile, which contains rules on how to build the executables.
- ______ $ make --help to list command-line options
- ______ $ nam make to display the man pages.... q to finish !!!!
- ___ is made of comand lines such as in which we should always use TAB and never spaces...
- ____ we can use Phony targets: all, clean, install
- variables begins with $ and is enclosed within parentheses (...) or braces {...}
- single character variables does not need parentheses.
- make sets automatic variables after a rule is matched, namelly
- $@ the target filename
- $* the target filename without the file extension
- $< the first prerequisite filename
- $^ the filenames of all the prerequisites, separated by spaces, discard duplicates.
- $+ similar to above but includes duplicates.
- $? the names of all prerequisites that are newer than the target, separated by spaces.
- VPATH specifies the directory to search for dependencies and target files.
- vpath is more precise about the file type and search directory.
- & is a pattern matching symbol, and can be used as filename
Programming the board
Using FABIsp
Attention to the USB cable which needs to have a Female extention, as this one
Connecting the 6-pin header to FabIsp taking attention tho the board schematic
Hello World 6-pin head
Fab ISP 6-pin head
Connecting FabISP to Hello World Board
Then see if the FabISP is recognised by MAC OS Sierra I used a new command ioreg which shows the I/O Kit registry, as fallows:
$ ioreg -p IOUSB -w0 -l
which resulted in the fallowing..
now I would like to program the board using the Comand Line and the files provided in Academy
- hello.ftdi.44.echo.c
- hello.ftdi.44.echo.c.make
Programming with different languages
for that I fallowed the indication of Lining Yao
- traveled to disk folder where I'd saved the files with the comand $CD F2019, where "F2019" is the folder name
- introduced comand: $ make -f hello.ftdi.44.echo.c.make, which resulted in the fallowing
- introduced comand: $ make -f hello.ftdi.44.echo.c.make program-usbtiny , which resulted in the fallowing EROR 1
SOLUTION: Connect the FTDI cabe to the Board
And... it worked!!!
- next comand whas to run the Phyton Code: $ python hello.ftdi.44.py /dev/tty.usb* 115200, which resulted in..
so needed some different instructions and founded Schaad
- $ sudo easy_install pip
- $ pip install pyserial
- $ python term.py /dev/tty. and hit the key TAB to vew the Ports ADDS as in my case
- then finished the comand with $ python term.py /dev/tty.usbserial-A700eEf3 115200
- and got an ERROR: python: can't open file 'term.py': [Errno 2] No such file or directory
FTDI
←