diff --git a/README.md b/README.md index a5d43bb..11039bf 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - 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 +## m00ex00 avrdude output without flashing : diff --git a/module01/ex00/Makefile b/module01/ex00/Makefile new file mode 100644 index 0000000..56b54a5 --- /dev/null +++ b/module01/ex00/Makefile @@ -0,0 +1,43 @@ +# frequency of the CPU (in Hz) +F_CPU = 16000000UL +TARGET = main +CC = avr-gcc + +AVRGCC_MCU_TYPE = atmega328p +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 -Os -o $(TARGET).bin + + +# https://linux.die.net/man/1/avr-objcopy +$(TARGET).hex: $(TARGET).bin + avr-objcopy -O ihex $(TARGET).bin $(TARGET).hex + + +# AVR Downloader/UploaDEr https://avrdudes.github.io/avrdude (v6.3 https://download-mirror.savannah.gnu.org/releases/avrdude/avrdude-doc-6.3.pdf) +flash: + avrdude -p $(AVRDUDE_MCU_TYPE) -c $(PROGRAMMER_ID) -b $(BAUD_RATE) -P $(SERIAL_PORT) -U flash:w:$(TARGET).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 restore \ No newline at end of file diff --git a/module01/ex00/main.c b/module01/ex00/main.c new file mode 100644 index 0000000..81e0195 --- /dev/null +++ b/module01/ex00/main.c @@ -0,0 +1,26 @@ +#include +#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 + +#define TEST_PIN(PORT, BIT) PIN ## PORT & 1 << BIT +#define TOGGLE_PIN(PORT, BIT) PIN ## PORT |= 1 << BIT +#define MODE_INPUT(PORT, BIT) CLEAR(DDR ## PORT, BIT) +#define MODE_OUTPUT(PORT, BIT) SET(DDR ## PORT, BIT) +#define IS_PIN_SET(PORT, BIT) (TEST_PIN(PORT, BIT)) == 0 +#define IS_PIN_CLEAR(PORT, BIT) (TEST_PIN(PORT, BIT)) == 1 + +#define D1 0 +#define D2 1 +#define D3 2 +#define D4 4 +#define SW1 2 +#define SW2 4 + +int main() { + MODE_OUTPUT(B, D1); + SET(PORTB, D1); +} \ No newline at end of file diff --git a/ressources/fr.subject_42chips.pdf b/ressources/fr.subject_42chips_module00.pdf similarity index 100% rename from ressources/fr.subject_42chips.pdf rename to ressources/fr.subject_42chips_module00.pdf diff --git a/ressources/fr.subject_42chips_module01.pdf b/ressources/fr.subject_42chips_module01.pdf new file mode 100644 index 0000000..6f9064a Binary files /dev/null and b/ressources/fr.subject_42chips_module01.pdf differ