Compare commits
1 Commits
mac_devcon
...
mac_makefi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc45812dfb |
@@ -1,24 +0,0 @@
|
||||
# Use Ubuntu as the base image
|
||||
FROM ubuntu:latest
|
||||
|
||||
# Update and install necessary dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
build-essential \
|
||||
curl \
|
||||
git \
|
||||
vim \
|
||||
avr-libc gcc-avr binutils-avr \
|
||||
avrdude \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set the working directory to /workspace (VSCode will mount your local folder here)
|
||||
WORKDIR /workspace
|
||||
|
||||
# Set the default user as root for installing packages
|
||||
USER root
|
||||
|
||||
# Expose any necessary ports (if needed)
|
||||
# EXPOSE 3000
|
||||
|
||||
# Run bash as the default command when the container starts
|
||||
CMD ["/bin/bash"]
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"name": "Ubuntu DevContainer",
|
||||
"dockerFile": "Dockerfile", // Reference to your Dockerfile
|
||||
"context": ".", // The context is the root of your project
|
||||
"workspaceFolder": "/workspace", // Where VSCode will mount your current folder inside the container
|
||||
"mounts": [
|
||||
"source=${localWorkspaceFolder},target=/workspace,type=bind",
|
||||
"source=/dev/tty.usbserial-310,target=/dev/ttyUSB0,type=bind"
|
||||
],
|
||||
"postCreateCommand": "echo 'Devcontainer setup complete!'"
|
||||
}
|
||||
64
Makefile
Normal file
64
Makefile
Normal file
@@ -0,0 +1,64 @@
|
||||
# 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
|
||||
PROGRAMMER_ID = arduino
|
||||
|
||||
# original firmware dump
|
||||
DUMP_ORI = ../../ressources/dump_atmega328p_ori.hex
|
||||
|
||||
# Detect OS
|
||||
OS := $(shell uname -s)
|
||||
|
||||
# Set Serial Port based on OS
|
||||
ifeq ($(OS), Darwin) # macOS
|
||||
SERIAL_PORT := $(shell ls /dev/tty.usb* 2>/dev/null | head -n 1) # should be : /dev/tty.usbserial-310
|
||||
else ifeq ($(OS), Linux) # Ubuntu/Linux
|
||||
SERIAL_PORT = $(shell ls /dev/ttyUSB* 2>/dev/null | head -n 1) # should be : /dev/ttyUSB0
|
||||
endif
|
||||
|
||||
##
|
||||
## RULES
|
||||
##
|
||||
|
||||
all: hex flash
|
||||
|
||||
hex: $(TARGET).hex
|
||||
|
||||
# avr-gcc : compiler for AVR microcontrollers, https://gcc.gnu.org/wiki/avr-gcc#Using_avr-gcc, https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html
|
||||
# -mmcu : the target microcontrolle (ATmega328P)
|
||||
# -D : defines a preprocessor macro (#define F_CPU <value>)
|
||||
# -o : output filename
|
||||
$(TARGET).bin: $(TARGET).c
|
||||
$(CC) -mmcu=$(AVRGCC_MCU_TYPE) -D F_CPU=$(F_CPU) $(TARGET).c -Os -o $(TARGET).bin
|
||||
|
||||
# avr-objcopy : man avr-jobcopy, https://linux.die.net/man/1/avr-objcopy
|
||||
# -O : specifies output format, Intel HEX
|
||||
# some formats (list not found in any doc) :
|
||||
# -O ihex : Used for flashing AVR chips
|
||||
# -O binary : Raw binary file
|
||||
# -O elf32-avr : Used for debugging
|
||||
$(TARGET).hex: $(TARGET).bin
|
||||
avr-objcopy -O ihex $(TARGET).bin $(TARGET).hex
|
||||
|
||||
# avr-dude : AVR Downloader/UploaDEr, upload firmware, https://avrdudes.github.io/avrdude, v6.3 https://download-mirror.savannah.gnu.org/releases/avrdude/avrdude-doc-6.3.pdf
|
||||
# -p : specifies the microcontroller -> m328p
|
||||
# -c : programmer-id
|
||||
# -b : baud rate for serial communication
|
||||
# -P : the serial port, found with `ls /dev/tty*` -> /dev/ttyUSB0
|
||||
# -U : Uploads (w = write) the HEX firmware file to the flash memory
|
||||
# (-v : verbose info dump)
|
||||
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
|
||||
36
README.md
36
README.md
@@ -80,37 +80,7 @@ avrdude: safemode: Fuses OK (E:00, H:00, L:00)
|
||||
avrdude done. Thank you.
|
||||
```
|
||||
|
||||
## test macros
|
||||
## makefile on mac
|
||||
|
||||
#include <stdio.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
// // stringify
|
||||
#define STRINGIFY_HELPER(x) #x
|
||||
#define STRINGIFY(x) STRINGIFY_HELPER(x)
|
||||
|
||||
#define CONCAT_HELPER(x, y) x ## y
|
||||
#define CONCAT(x, y) CONCAT_HELPER(x, y)
|
||||
|
||||
// get argument at nth position
|
||||
#define ARG_1(v1, v2) v1
|
||||
#define ARG_2(v1, v2) v2
|
||||
#define GET_PORT(args) ARG_1 args
|
||||
#define GET_BIT(args) ARG_2 args
|
||||
|
||||
// actions on registers
|
||||
#define SET(register, bit) register |= 1 << bit
|
||||
|
||||
// actions on ports
|
||||
#define MODE_OUTPUT(elem) SET(CONCAT(DDR, GET_PORT(elem)), GET_BIT(elem))
|
||||
|
||||
// elements
|
||||
#define LED1 (B, 0)
|
||||
|
||||
int main()
|
||||
{
|
||||
MODE_OUTPUT(LED1);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
- `brew tap osx-cross/avr`
|
||||
- `brew install avr-gcc avrdude`
|
||||
|
||||
@@ -1,50 +1 @@
|
||||
# frequency of the CPU (in Hz)
|
||||
F_CPU = 16000000UL
|
||||
TARGET = main
|
||||
CC = avr-gcc
|
||||
|
||||
|
||||
all: hex flash
|
||||
|
||||
hex: $(TARGET).hex
|
||||
|
||||
# avr-gcc : compiler for AVR microcontrollers, https://gcc.gnu.org/wiki/avr-gcc#Using_avr-gcc, https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html
|
||||
# -mmcu : the target microcontrolle (ATmega328P)
|
||||
# -D : defines a preprocessor macro (#define F_CPU <value>)
|
||||
# -o : output filename
|
||||
$(TARGET).bin: $(TARGET).c
|
||||
$(CC) -mmcu=atmega328p -D F_CPU=$(F_CPU) $(TARGET).c -o $(TARGET).bin
|
||||
|
||||
|
||||
# avr-objcopy : man avr-jobcopy, https://linux.die.net/man/1/avr-objcopy
|
||||
# -O : specifies output format, Intel HEX
|
||||
# some formats (list not found in any doc) :
|
||||
# -O ihex : Used for flashing AVR chips
|
||||
# -O binary : Raw binary file
|
||||
# -O elf32-avr : Used for debugging
|
||||
$(TARGET).hex: $(TARGET).bin
|
||||
avr-objcopy -O ihex $(TARGET).bin $(TARGET).hex
|
||||
|
||||
|
||||
# avr-dude : AVR Downloader/UploaDEr, upload firmware, https://avrdudes.github.io/avrdude, v6.3 https://download-mirror.savannah.gnu.org/releases/avrdude/avrdude-doc-6.3.pdf
|
||||
# -p : specifies the microcontroller -> m328p
|
||||
# -c : programmer-id
|
||||
# -b : baud rate for serial communication
|
||||
# -P : the serial port, found with `ls /dev/tty*` -> /dev/ttyUSB0
|
||||
# -U : Uploads (w = write) the HEX firmware file to the flash memory
|
||||
# (-v : verbose info dump)
|
||||
flash:
|
||||
avrdude -p m328p -c arduino -b 115200 -P /dev/ttyUSB0 -U flash:w:$(TARGET).hex
|
||||
# avrdude -p m328p -c arduino -b 115200 -P /dev/ttyUSB0 -v
|
||||
# avrdude -p m328p -c arduino -b 115200 -P /dev/ttyUSB0 -U flash:w:../../ressources/dump_atmega328p_ori.hex
|
||||
|
||||
|
||||
dump:
|
||||
avrdude -p m328p -c arduino -b 115200 -P /dev/ttyUSB0 -U flash:r:dump_atmega328p.hex
|
||||
|
||||
|
||||
clean:
|
||||
rm -f main.hex main.bin
|
||||
|
||||
|
||||
.PHONY : all clean hex flash dump
|
||||
include ../../Makefile
|
||||
@@ -1,43 +1 @@
|
||||
# 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
|
||||
include ../../Makefile
|
||||
@@ -1,43 +1 @@
|
||||
# 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
|
||||
include ../../Makefile
|
||||
@@ -1,43 +1 @@
|
||||
# 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
|
||||
include ../../Makefile
|
||||
@@ -1,43 +1 @@
|
||||
# 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
|
||||
include ../../Makefile
|
||||
@@ -1,43 +1 @@
|
||||
# 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
|
||||
include ../../Makefile
|
||||
@@ -1,43 +1 @@
|
||||
# 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
|
||||
include ../../Makefile
|
||||
Reference in New Issue
Block a user