diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..a9ca4af --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,24 @@ +{ + "configurations": [ + { + "name": "linux-avr-gcc", + "includePath": ["${workspaceFolder}/**", "/usr/lib/avr/include/**"], + "defines": [], + "mergeConfigurations": false, + "compilerPath": "/usr/bin/avr-gcc", + "cStandard": "gnu11", + "cppStandard": "gnu++14", + "intelliSenseMode": "linux-gcc-x64", + "compilerArgs": ["-mmcu=atmega328p", "-DF_CPU=16000000UL", "-Os"] + }, + { + "name": "linux-gcc-x64", + "includePath": ["${workspaceFolder}/**"], + "compilerPath": "/usr/bin/gcc", + "intelliSenseMode": "linux-gcc-x64", + "compilerArgs": [""], + "mergeConfigurations": false + } + ], + "version": 4 +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e8c204d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "io.h": "c" + } +} diff --git a/README.md b/README.md index 35b5ee2..358ab09 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ -# RESSOURCES # +# RESSOURCES - https://github.com/m3y54m/start-avr/tree/master - avrdude 6.3 doc : https://download-mirror.savannah.gnu.org/releases/avrdude/avrdude-doc-6.3.pdf +- embedded systems : https://en.wikibooks.org/wiki/Embedded_Systems/Atmel_AVR -## ex00 ## +## ex00 avrdude output without flashing : + ``` avrdude -p m328p -c arduino -b 115200 -P /dev/ttyUSB0 -v @@ -73,4 +75,4 @@ avrdude: safemode: efuse reads as 0 avrdude: safemode: Fuses OK (E:00, H:00, L:00) avrdude done. Thank you. -``` \ No newline at end of file +``` diff --git a/module00/ex01/Makefile b/module00/ex01/Makefile index 2a483b1..40e9cb4 100644 --- a/module00/ex01/Makefile +++ b/module00/ex01/Makefile @@ -8,12 +8,15 @@ AVRDUDE_MCU_TYPE = m328p BAUD_RATE = 115200 SERIAL_PORT = /dev/ttyUSB0 PROGRAMMER_ID = arduino +DUMP_ORI = ../../ressources/dump_atmega328p_ori.hex all: hex flash + hex: $(TARGET).hex + # https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html $(TARGET).bin: $(TARGET).c $(CC) -mmcu=$(AVRGCC_MCU_TYPE) -D F_CPU=$(F_CPU) $(TARGET).c -o $(TARGET).bin @@ -29,12 +32,12 @@ flash: avrdude -p $(AVRDUDE_MCU_TYPE) -c $(PROGRAMMER_ID) -b $(BAUD_RATE) -P $(SERIAL_PORT) -U flash:w:$(TARGET).hex -dump: - avrdude -p m328p -c arduino -b 115200 -P /dev/ttyUSB0 -U flash:r:dump_atmega328p.hex +restore: + avrdude -p $(AVRDUDE_MCU_TYPE) -c $(PROGRAMMER_ID) -b $(BAUD_RATE) -P $(SERIAL_PORT) -U flash:w:$(DUMP_ORI) clean: rm -f main.hex main.bin -.PHONY : all clean hex flash dump \ No newline at end of file +.PHONY : all clean hex flash restore \ No newline at end of file diff --git a/module00/ex01/main.c b/module00/ex01/main.c index 0eefc1c..676b247 100644 --- a/module00/ex01/main.c +++ b/module00/ex01/main.c @@ -1,3 +1,37 @@ +#include + +#define SET(REGISTER, BIT) REGISTER |= 1 << BIT +#define CLEAR(REGISTER, BIT) REGISTER &= ~(1 << BIT) +#define TEST(REGISTER, BIT) REGISTER & 1 << BIT +#define TOGGLE(REGISTER, BIT) REGISTER ^= 1 << BIT + int main() { + // DDRx : select direction of the pin + // - 1 = output (pull-up off) + // - 0 = input + // PORTx : + // if DDRx = 1 (output mode) : + // - 1 = HIGH (5V) + // - 0 = LOW (0V) + // if DDRx = 0 (input mode) : + // - 1 = pull-up on + // - 0 = pull-up off + // PINx : + + + // turn on led 1 + SET(DDRB, 0); // make PB0 as OUTPUT + SET(PORTB, 0); // make PB0 as HIGH (LED turns ON) + + // CLEAR(DDRB, 1); // make PB0 as INPUT + // SET(PORTB, 1); // make PB0 pullup on + + // SET(DDRB, 2); // make PB0 as OUTPUT + // CLEAR(PORTB, 2); // make PB0 as LOW (LED turns OFF) + + // CLEAR(DDRB, 4); // make PB0 as INPUT + // CLEAR(PORTB, 4); // make PB0 as LOW (LED turns OFF) + + return 0; } \ No newline at end of file