Showing posts with label AVR. Show all posts
Showing posts with label AVR. Show all posts

5 Sept 2019

Using Visual Studio Code for AVR (macOS)

Setup IntelliSense

1. Open a project's folder as Workspace in VS Code.
2. Install C/C++ Extension
3. Create a folder .vscode in the project's folder.
4. Place a file c_cpp_properties.json in the .vscode folder

Check documentation here or try the example project.

{
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/local/include",
"/usr/bin/gcc",
"/Users/usernamefolder/Library/avr-toolchain/avr/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "${default}",
"browse": {
"path": [
"/usr/local/include",
"/usr/bin/gcc",
"/Users/usernamefolder/Library/avr-toolchain/avr/include",
"${workspaceRoot}"
]
},
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}"
}
],
"version": 4
}

1 Sept 2019

Make Utility for AVR. (AVR build automation)

The Make Utility is a build tool that automatically determines which source files of a program need to be recompiled and/or linked. We can compile, link and flashing of AVR microcontroller using only one command in the terminal: make. Make remains widely used, especially in Unix-like operating systems.

How to use

1. Create a file inside of project's folder without extension and called Makefile.
2. Place commands in it.
3. Open a terminal and move into the project's folder with Makefile.
4. Type make command in terminal.
5. Use labels like: 
make all
make flash
make clean

Check here the example for ATTiny13

=====

MCU=attiny13
F_CPU=1200000
CC=avr-gcc
CS=avr-size
OBJCOPY=avr-objcopy
CFLAGS=-std=c99 -Wall -g -Os -mmcu=${MCU} -DF_CPU=${F_CPU} -I.
TARGET=main
SRCS=main.c

all:
@printf "\n"
@printf " ===> Compiling: \n"
${CC} ${CFLAGS} -o ${TARGET}.bin ${SRCS}
@printf "\n"
@printf " ===> Size: \n"
${CS} -C ${TARGET}.bin
@printf " ===> Generating .HEX: \n"
${OBJCOPY} -j .text -j .data -O ihex ${TARGET}.bin ${TARGET}.hex

flash:
@printf "\n"
@printf " ===> Flashing: \n"
avrdude -p ${MCU} -B 4 -c usbasp -U flash:w:${TARGET}.hex:i -F -P usb

clean:
@printf "\n"
@printf " ===> Cleaning: \n"
rm -f *.bin *.hex


31 Aug 2019

How to setup AVR programming environment on macOS. Step-by-step guide

This is a lightweight and easy to setup AVR dev programming instruction where we will use AVR 8-bit Toolchain 3.6.2 - Mac OS X 64-bit and will not use the old CrossPack. By the way, GNU Toolchain Documentation is here.


Let's start!
----------------->

AVR Toolchain Installation (Compiler, Assembler, Linker, Librarian, C Library, etc)


1. Download sh script from here
2. Run it. sudo sh <path>/install_toolchain.sh

1. Download sh script from here
2. Run it. sudo sh <path>/avr_toolchain_install.sh
3. Reboot your machine and test it using the terminal command avr-gcc -v 

You should get the answer: gcc version 5.4.0 (AVR_8_bit_GNU_Toolchain_3.6.2_503)

AVR Programmer Installation (Avrdude)


Before this we need to install libusb, you can get it here (I use libusb-1.0.23.tar.bz2)
Unzip, navigate, install:
1. sudo ./configure
2. sudo make
3. sudo make install

then move through these steps:

1. Download the current release of avrdude here (I use avrdude-6.3)
2. Unzip the downloaded file. In a Terminal window, navigate to the avrdude directory: cd <path>/avrdude-6.3
3. Configure avrdude. type: sudo ./configure
4. Compile avrdude. type: sudo make
5. Install avrdude. type: sudo make install
6. Test it by feeding the terminal with  avrdude -version

You should get the answer: avrdude version 6.3


Thanks to all of avr funs we have done with the software part!

Compiling an Example (for the cutiest ATTiny13 chip)


1. Get the example here
2. Navigate to the example directory cd <path>/example
3. Compile the code: avr-gcc -Wall -g -Os -mmcu=attiny13 -o main.bin main.c
4. Check program and data memory size: avr-size -C main.bin
5. Generate a HEX file for a programmer: avr-objcopy -j .text -j .data -O ihex main.bin main.hex



Time to flash the chip!

Flashing the chip


1. Connect USBasp programmer (You don't need a driver on macOS)
2. Move into the project's directory
3. Open terminal and type: avrdude -p attiny13 -c usbasp -U flash:w:main.hex:i

You should get the answer: avrdude: error: program enable: target doesn't answer. 1 
That means we are ready to connect real MCU and try again



How to setup AVR programming environment on macOS.

Troubleshooting

1. ----------------------------------------
avrdude: error: program enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.


Solution -> Use slow programming speed by adding flag B 1 - B 400 like this:
avrdude -p attiny13 -B 4 -c usbasp -U flash:w:main.hex:i


Files

Adafruit avrdude documentation is here.
All files are here

Popular Posts