diff options
Diffstat (limited to 'src/arch')
-rw-r--r-- | src/arch/arduino-nano-168/Makefile.inc | 29 | ||||
-rw-r--r-- | src/arch/arduino-nano/Makefile.inc | 10 | ||||
-rw-r--r-- | src/arch/arduino-nano/arch.cc | 36 | ||||
-rw-r--r-- | src/arch/arduino-nano/driver/stdout.cc | 5 |
4 files changed, 74 insertions, 6 deletions
diff --git a/src/arch/arduino-nano-168/Makefile.inc b/src/arch/arduino-nano-168/Makefile.inc index 534ac27..a56e62a 100644 --- a/src/arch/arduino-nano-168/Makefile.inc +++ b/src/arch/arduino-nano-168/Makefile.inc @@ -7,7 +7,8 @@ BAUD = 19200 cpu_freq ?= 16000000 COMMON_FLAGS += -Werror=overflow -COMMON_FLAGS += -mmcu=${MCU} -DF_CPU=16000000UL -DMULTIPASS_ARCH_arduino_nano +COMMON_FLAGS += -mmcu=${MCU} -DMULTIPASS_ARCH_arduino_nano +COMMON_FLAGS += -DF_CPU=${cpu_freq}UL COMMON_FLAGS += -flto COMMON_FLAGS += -DMULTIPASS_ARCH_HAS_I2C @@ -39,6 +40,30 @@ ifneq ($(findstring timer,${arch_drivers}), ) TARGETS += src/arch/arduino-nano/driver/timer.cc endif +ifeq (${cpu_freq}, 16000000) + uart_baud = 57600 +else ifeq (${cpu_freq}, 8000000) + uart_baud = 38400 +else ifeq (${cpu_freq}, 4000000) + uart_baud = 38400 +else ifeq (${cpu_freq}, 2000000) + uart_baud = 19200 +else ifeq (${cpu_freq}, 1000000) + uart_baud = 9600 +else ifeq (${cpu_freq}, 500000) + uart_baud = 4800 +else ifeq (${cpu_freq}, 250000) + uart_baud = 2400 +else ifeq (${cpu_freq}, 125000) + uart_baud = 1200 +else ifeq (${cpu_freq}, 62500) + uart_baud = 300 +else + uart_baud = 9600 +endif + +COMMON_FLAGS += -DBAUD=${uart_baud}UL + OBJECTS = ${TARGETS:.cc=.o} .cc.o: @@ -58,7 +83,7 @@ arch_clean: ${QUIET}rm -f ${OBJECTS} build/system.hex monitor: - ${QUIET}screen ${PORT} 115200 + ${QUIET}screen ${PORT} ${uart_baud} arch_help: @echo "arduino-nano specific flags:" diff --git a/src/arch/arduino-nano/Makefile.inc b/src/arch/arduino-nano/Makefile.inc index bb51b6c..08dd6c1 100644 --- a/src/arch/arduino-nano/Makefile.inc +++ b/src/arch/arduino-nano/Makefile.inc @@ -7,7 +7,7 @@ BAUD = 57600 cpu_freq ?= 16000000 COMMON_FLAGS += -Werror=overflow -COMMON_FLAGS += -mmcu=${MCU} -DF_CPU=16000000UL -DMULTIPASS_ARCH_arduino_nano +COMMON_FLAGS += -mmcu=${MCU} -DMULTIPASS_ARCH_arduino_nano COMMON_FLAGS += -flto COMMON_FLAGS += -DMULTIPASS_ARCH_HAS_I2C @@ -39,6 +39,12 @@ ifneq ($(findstring timer,${arch_drivers}), ) TARGETS += src/arch/arduino-nano/driver/timer.cc endif +ifneq (${cpu_freq}, ) + COMMON_FLAGS += -DF_CPU=${cpu_freq}UL +else + COMMON_FLAGS += -DF_CPU=16000000UL +endif + OBJECTS = ${TARGETS:.cc=.o} .cc.o: @@ -58,7 +64,7 @@ arch_clean: ${QUIET}rm -f ${OBJECTS} build/system.hex monitor: - ${QUIET}screen ${PORT} 115200 + ${QUIET}screen ${PORT} 19200 arch_help: @echo "arduino-nano specific flags:" diff --git a/src/arch/arduino-nano/arch.cc b/src/arch/arduino-nano/arch.cc index b034348..2d957fc 100644 --- a/src/arch/arduino-nano/arch.cc +++ b/src/arch/arduino-nano/arch.cc @@ -5,6 +5,37 @@ void Arch::setup(void) { + +#if F_CPU == 16000000UL + /* default */ +#elif F_CPU == 8000000UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS0); +#elif F_CPU == 4000000UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS1); +#elif F_CPU == 2000000UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS1) | _BV(CLKPS0); +#elif F_CPU == 1000000UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS2); +#elif F_CPU == 500000UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS2) | _BV(CLKPS0); +#elif F_CPU == 250000UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS2) | _BV(CLKPS1); +#elif F_CPU == 125000UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS2) | _BV(CLKPS1) | _BV(CLKPS0); +#elif F_CPU == 62500UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS3); +#else +#error Unsupported F_CPU +#endif + #ifdef TIMER_CYCLES TCCR0A = 0; TCCR0B = _BV(CS00); @@ -13,11 +44,14 @@ void Arch::setup(void) #if defined(WITH_LOOP) || defined(TIMER_S) TCCR1A = 0; TCCR1B = _BV(WGM12) | _BV(CS12) | _BV(CS10); // /1024 - OCR1A = 15625; + OCR1A = F_CPU / 1024; TIMSK1 = _BV(OCIE1A); #endif #ifdef TIMER_US +#if F_CPU != 16000000UL +#error TIMER_US is only supported with F_CPU = 16MHz +#endif // 16MHz/8 -> 2MHz timer TCCR2A = 0; TCCR2B = _BV(CS21); diff --git a/src/arch/arduino-nano/driver/stdout.cc b/src/arch/arduino-nano/driver/stdout.cc index a3d905d..58ff440 100644 --- a/src/arch/arduino-nano/driver/stdout.cc +++ b/src/arch/arduino-nano/driver/stdout.cc @@ -2,7 +2,10 @@ #include <avr/io.h> #include <avr/interrupt.h> -#define BAUD 119200L +#ifndef BAUD +#define BAUD 9600UL +#endif + #include <util/setbaud.h> void StandardOutput::setup() |