├── keyboard_shortcuts.md ├── Linux_RPI ├── .vscode │ ├── c_cpp_properties.json │ └── tasks.json ├── blink_test.c ├── Makefile └── DOC.md └── README.md /keyboard_shortcuts.md: -------------------------------------------------------------------------------- 1 | ## Some use ful keyboard shortcuts in vs code 2 | 3 | * alt + shift + i - mylty line entry 4 | * ctrl + tab - To move alon instance 5 | * ctrl + ` - To open intragrated terminal 6 | -------------------------------------------------------------------------------- /Linux_RPI/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | "/usr/lib/avr/include" 8 | // here you need to include the path to all the liberaries that u used 9 | ], 10 | "defines": [], 11 | "compilerPath": "/usr/bin/avr-gcc", // here u need to add the path to avr-gcc 12 | "cStandard": "c11", 13 | "cppStandard": "c++17", 14 | "intelliSenseMode": "gcc-arm" 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /Linux_RPI/blink_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | # This part is to define the board that we are using 4 | # You can see all the board list that are availabele in the ave/io.h lib by 5 | # peacking to the header just select the avr/io.h in the #include part and press F12 6 | # press ctrl + f and search for the board that u are looking for 7 | # If your board is available then u can see the board name unde __AVR_your-board__ 8 | # Here am using Atmega328p SO __AVR_ATmega328P__ 9 | 10 | */ 11 | 12 | #ifndef __AVR_ATmega328P__ 13 | #define __AVR_ATmega328P__ 14 | #endif 15 | #define F_CPU 16000000UL 16 | 17 | #include 18 | #include 19 | 20 | int main(void) 21 | { 22 | DDRB = 0xff; 23 | while(1) 24 | { 25 | 26 | PORTB = 0xff; 27 | _delay_ms(1000); 28 | PORTB = (0<<5); 29 | _delay_ms(100); 30 | 31 | } 32 | return (0); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Linux_RPI/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "AVR Programmer APP", 8 | "type": "shell", 9 | "command": "make", 10 | "args": [], 11 | "group": "build", 12 | "presentation": { 13 | "reveal": "silent" 14 | }, 15 | "problemMatcher": [ 16 | "$gcc" 17 | ] 18 | }, 19 | { 20 | "type": "cppbuild", 21 | "label": "C/C++: gcc build active file", 22 | "command": "/usr/bin/gcc", 23 | "args": [ 24 | "-g", 25 | "${file}", 26 | "-o", 27 | "${fileDirname}/${fileBasenameNoExtension}" 28 | ], 29 | "options": { 30 | "cwd": "${workspaceFolder}" 31 | }, 32 | "problemMatcher": [ 33 | "$gcc" 34 | ], 35 | "group": "build", 36 | "detail": "compiler: /usr/bin/gcc" 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /Linux_RPI/Makefile: -------------------------------------------------------------------------------- 1 | #Main application file name 2 | MAIN_APP = blink_test 3 | #Main hex file path in windows format 4 | MAIN_HEX_PATH = /home/pi/Documents/intrrepts/$(MAIN_APP).hex 5 | 6 | # Compiler and other Section 7 | CC = avr-gcc 8 | # JCOPY = avr-objcopy 9 | # avr-objcopy -oihex -R .eeprom blink.elf blink.hex 10 | OBJCOPY = avr-objcopy 11 | AVRDUDE := avrdude 12 | 13 | #Options for avr-gcc 14 | CFLAGS = -g -Os -o 15 | 16 | #Linking options for avr-gcc 17 | 18 | LFLAGS = -Os -mmcu=atmega328p -o 19 | 20 | #Options for HEX file generation 21 | HFLAGS = -O ihex -R .eeprom 22 | #Options for avrdude to burn the hex file 23 | #MMCU model here according to avrdude options 24 | DUDEFLAGS = -c 25 | DUDEFLAGS += usbasp 26 | DUDEFLAGS += -p 27 | DUDEFLAGS += m328p 28 | DUDEFLAGS += -P 29 | DUDEFLAGS += /dev/ttyAMA0 # add port of the isp programmer here 30 | DUDEFLAGS += -b 31 | DUDEFLAGS += 19200 32 | DUDEFLAGS += -U flash:w:$(MAIN_HEX_PATH):i 33 | 34 | # Sources files needed for building the application 35 | SRC = $(MAIN_APP).c 36 | 37 | 38 | # The headers files needed for building the application 39 | INCLUDE = -I. 40 | 41 | # commands Section 42 | 43 | Burn : Build 44 | $(AVRDUDE) $(DUDEFLAGS) 45 | Build : $(MAIN_APP).elf 46 | $(OBJCOPY) $(HFLAGS) $< $(MAIN_APP).hex 47 | 48 | $(MAIN_APP).elf: $(MAIN_APP).o 49 | $(CC) $(SRC) $(INCLUDE) $(LFLAGS) $@ 50 | 51 | $(MAIN_APP).o:$(SRC) 52 | $(CC) $^ $(INCLUDE) $(CFLAGS) $@ 53 | 54 | -------------------------------------------------------------------------------- /Linux_RPI/DOC.md: -------------------------------------------------------------------------------- 1 | ## Hardware requirements 2 | 3 | ------------ 4 | 5 | - Any AVR microcontroller board 6 | - USB ASP programmer 7 | 8 | ## Software requirements 9 | 10 | ------------ 11 | 12 | - Visual Studio code 13 | - avr-gcc 14 | - avrdude 15 | - c/c++ extension 16 | 17 | ## Let's start Configuration 18 | 19 | ------------ 20 | 21 | - **Open VS code create a new work folder** 22 | 23 | - **create a c/c++ file (file with .C /.C++) write your embedded program in it and hit save** 24 | 25 | - **copy the [Make file](https://github.com/richu101/VScode-AVR-programmer/blob/main/Linux_RPI/Makefile) and paste it in your work folder** 26 | 27 | - **press ctrl + shift +p to open command palette** 28 | 29 | - **In command palette search for c/c++:Edit Configiratation(JSON) and select that** 30 | 31 | ## c/c++:Edit Configiratation(JSON) 32 | 33 | ~~~ This will create a folder named .vscode in your work folder and in that a json file named c_cpp_properties.json 34 | 35 | By default the c_cpp_properties.json contain the path to the gcc compiler but for avr micro controllers we need to compile using avr-gcc so that we need to add the path to the avr-gcc 36 | 37 | ~~~ 38 | 39 | 40 | **"compilerPath": "**~~/usr/bin/avr-gcc~~**"**, - // paste your avr-gcc path here 41 | 42 | ``` 43 | If you use any additional libraries you need to add the path to that library 44 | ``` 45 | 46 | ``` 47 | "includePath": [ 48 | "${workspaceFolder}/**", 49 | "/usr/lib/avr/include" 50 | // here you need to include the path to all the libraries that you used 51 | ], 52 | ``` 53 | After adding the path to the libraries dont forget to put **,** in the end eg: "/usr/lib/avr/include" , "/usr/lib/avr/serial" , "/usr/lib/avr/uart" 54 | 55 | Except includepath and compiler path rest content you can copy from my c_cpp_properties.json 56 | 57 | - **Copy the tasks.json file and paste it into your .vscode** 58 | 59 | - **Make some edit in the make file** 60 | 61 | ``` 62 | Make file is the file that compiles the c code and convert it into hex file. 63 | Then upload the hex file to the AVR Microcontroller using AVRDUDE 64 | ``` 65 | 66 | ## **Makefile edit** 67 | 68 | ----------- 69 | 70 | 71 | 72 | **MAIN_APP = ~~blink_test~~** 73 | 74 | here you need to add the name of your .c file 75 | 76 | **MAIN_HEX_PATH = /home/pi/Documents/intrrepts/$(MAIN_APP).hex** 77 | 78 | Here you need to add the the location where you need to create the hex file 79 | 80 | **LFLAGS = -Os -mmcu=~~atmega328p~~ -o** 81 | Here you need to give the name of the mcu (micro controller)that you are using 82 | 83 | **DUDEFLAGS += ~~/dev/ttyAMA0~~** 84 | Here you need to add port name in which you connect the usbasp programmer 85 | 86 | ### Build and Upload code 87 | 88 | * Press Ctrl + Shift + B 89 | 90 | To build the make file 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VScode-AVR-programme 2 | 3 | **How to program AVR microcontrollers using VS code** 4 | 5 | For Linux users you can check the Linux_RPI folder 6 | 7 | 8 | ------------ 9 | 10 | ## Hardware requirements 11 | 12 | ------------ 13 | 14 | - Any AVR microcontroller board 15 | - USB ASP programmer 16 | 17 | ## Software requirements 18 | 19 | ------------ 20 | 21 | - Visual Studio code 22 | - avr-gcc 23 | - avrdude 24 | - c/c++ extension 25 | 26 | ## Let's start programming 27 | 28 | ------------ 29 | 30 | - **Open VS code create a new work folder** 31 | 32 | - **create a c/c++ file write your embedded program in it and save** 33 | 34 | - **copy the Make file and paste it in your work folder** 35 | 36 | - **press ctrl + shift +p to open command palette** 37 | 38 | - **In command palette search for c/c++:Edit Configiratation(JSON) and select that** 39 | 40 | ## c/c++:Edit Configiratation(JSON) 41 | 42 | ~~~ This will create a folder named .vscode in your work folder and in that a json file named c_cpp_properties.json 43 | 44 | By default the c_cpp_properties.json contain the path to the gcc compiler but for avr micro controllers we need to compile using avr-gcc so that we need to add the path to the avr-gcc 45 | 46 | ~~~ 47 | 48 | 49 | **"compilerPath": "**~~/usr/bin/avr-gcc~~**"**, - // paste your avr-gcc path here 50 | 51 | ``` 52 | If you use any additional libraries you need to add the path to that library 53 | ``` 54 | 55 | ``` 56 | "includePath": [ 57 | "${workspaceFolder}/**", 58 | "/usr/lib/avr/include" 59 | // here you need to include the path to all the libraries that you used 60 | ], 61 | ``` 62 | After adding the path to the libraries dont forget to put **,** in the end eg: "/usr/lib/avr/include" , "/usr/lib/avr/serial" , "/usr/lib/avr/uart" 63 | 64 | Except includepath and compiler path rest content you can copy from my c_cpp_properties.json 65 | 66 | - **Copy the tasks.json file and paste it into your .vscode** 67 | 68 | - **Make some edit in the make file** 69 | 70 | ``` 71 | Make file compiles the c code and convert it into hex file. 72 | Then upload the hex file to the AVR Microcontroller using AVRDUDE 73 | 74 | ``` 75 | 76 | ## **Makefile edit** 77 | 78 | ----------- 79 | 80 | 81 | 82 | **MAIN_APP = ~~blink_test~~** 83 | 84 | here you need to add the name of your .c file 85 | 86 | **MAIN_HEX_PATH = /home/pi/Documents/intrrepts/$(MAIN_APP).hex** 87 | 88 | Here you need to add the the location where you need to create the hex file 89 | 90 | **LFLAGS = -Os -mmcu=~~atmega328p~~ -o** 91 | Here you need to give the name of the mcu (micro controller)that you are using 92 | 93 | **DUDEFLAGS += ~~/dev/ttyAMA0~~** 94 | Here you need to add port name in which you connect the usbasp programmer 95 | 96 | ### Buils 97 | 98 | * Press Ctrl + Shift + B 99 | 100 | To build the make file 101 | --------------------------------------------------------------------------------