1
0
Fork 0
This commit is contained in:
Arti Zirk 2016-09-09 23:54:45 +03:00
commit dca26ac547
5 changed files with 154 additions and 0 deletions

3
.gitignore vendored
View File

@ -1,6 +1,9 @@
# Build artefacts
bin/*
# astyle formatter preserved files
*.orig
#
# Templates from https://github.com/github/gitignore
#

86
Makefile Normal file
View File

@ -0,0 +1,86 @@
###############################################################################
#
# Simple Makefile for Arduino MEGA 2560 C projects
#
###############################################################################
CC = avr-gcc
OBJCOPY = avr-objcopy
AVRDUDE = avrdude
CODE_FORMATTER = tooling/format-code.sh
BOARD = atmega2560
# Use shell command export to define it
# Example: export ARDUINO=/dev/ttyACM0
DEVICE = $(ARDUINO)
# Build artifacts
BINDIR = bin
TARGET = $(BINDIR)/$(BOARD)-user-code.ihx
ELF = $(BINDIR)/$(BOARD)-user-code.elf
# Source files. wildard "uses" all .c files in src directory
SRCDIR = src
SRC = $(wildcard $(SRCDIR)/*.c)
# Define object files from .c files defined above
OBJ=$(SRC:.c=.o)
# Compiler flags
# Note that those beginning with -D are acctually pre-processor macros
# -Wall ... -Wfatal-errors All possible warning options
# -Os Optimize code. The special option -Os is meant to turn on all -O2
# optimizations that are not expected to increase code size.
# -std=c11 use C11 standard
CFLAGS = -Wall \
-Wextra \
-Wpedantic \
-Wformat \
-pedantic-errors \
-Werror \
-Wfatal-errors \
-Os \
-mmcu=$(BOARD) \
-DF_CPU=16000000UL \
-DGIT_DESCR=\"$(shell git describe --abbrev=6 --dirty --always --tags --long)\" \
-std=c11
# Linker flags
LDFLAGS = -mmcu=$(BOARD)
OBJCOPYARGS = -O ihex \
-R .eeprom
# FIXME Find out why some Arduinos require -D to write code
AVRDUDEARGS = -p $(BOARD) \
-c wiring \
-F \
-P $(DEVICE) \
-b 115200 \
-V \
-D
all: $(ELF) $(TARGET)
%.o : %.c
$(CC) -c $(CFLAGS) -o $*.o $<
$(ELF): $(OBJ)
$(CC) $(LDFLAGS) $^ -o $@
$(TARGET):
$(OBJCOPY) $(OBJCOPYARGS) $(ELF) $(TARGET)
clean:
#Do not remove .placeholder in BINDIR
find $(BINDIR) -type f -not -name '.placeholder' -print0 | xargs -0 rm -f --
rm -f $(SRCDIR)/*.o
install:
$(AVRDUDE) $(AVRDUDEARGS) -U flash:w:$(TARGET)
format:
$(CODE_FORMATTER) $(SRC)
.PHONY: clean install format

View File

@ -0,0 +1,17 @@
# Arduino Mega USB UART converter wiring
## Introduction
This wiring schema uses only Tx from Arduino and is suitable to be used as standard error console.
## Wiring illustration
![Arduino Mega USB UART wiring.png](Arduino-Mega-USB-UART-wiring.png)
## Wiring table
| Signal | ATMega2560 port and pin | Arduino Mega 2560 pin | USB UART converter pin |
| --- | --- | --- | --- |
| Ground (GND) | - | GND | GND |
| Transmit data from Arduino (TxD) | PORTJ 1 (TXD3) | 14 (TX3) | TxD |

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

48
tooling/format-code.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
# Simple script for code formatting in 1tbs
# See http://astyle.sourceforge.net/astyle.html for syntax and defaults
MINPARAMS=1
ORIG_SUFFIX=orig
if [ $# -lt "$MINPARAMS" ]
then
echo "This script needs C source files passed as arguments"
echo "USAGE: format-code.sh src/main.c src/somecode.c ..."
exit 1
fi
#
for FILE in "$@"
do
RESULT="$(astyle --style=1tbs \
--indent-col1-comments \
--break-blocks \
--pad-oper \
--pad-header \
--delete-empty-lines \
--add-brackets \
--convert-tabs \
--max-code-length=80 \
--break-after-logical \
--mode=c \
--suffix=.$ORIG_SUFFIX \
--lineend=linux \
$FILE)"
# if file unchanged print unchanged result message
if [[ "$RESULT" = Unchanged* ]]
then
echo "$RESULT"
fi
# if file formatted print result and renamed file name
if [[ "$RESULT" = Formatted* ]]
then
echo "$RESULT"
echo "Original code was preserved in file $FILE.$ORIG_SUFFIX"
fi
done
exit 0