diff options
| author | Daniel Friesel <derf@finalrewind.org> | 2018-10-19 09:01:36 +0200 | 
|---|---|---|
| committer | Daniel Friesel <derf@finalrewind.org> | 2018-10-19 09:01:36 +0200 | 
| commit | 255085d06a75c424cd6b95aaac10056e5de65876 (patch) | |
| tree | 345a6bb1772089e4928e88f5035648f82b51531e /src/arch/arduino-nano | |
| parent | 458c89d71c3aa22eb5e83d4e34930a8978c0ef7e (diff) | |
arduino nano: support additional CPU frequencies
Diffstat (limited to 'src/arch/arduino-nano')
| -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 | 
3 files changed, 47 insertions, 4 deletions
| 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() | 
