Archive-name: avrusb500-changes-2013-is
Submitted-by:
onei...@gmail.com
Last-modified: 2013-04-26 +00:00
Copyright-Notice: Released under the CC0 Public Domain Dedication;
(but may be too trivial to be copyrightable per se.)
[Followup-To: set to news:alt.sources.d, as per the charter, and
news:comp.arch.embedded.]
Synopsis
$ cd avrusb500/
$ mkdir +build-1
$ cd +build-1/
$ make F_CPU=7372800 BAUD=115200 MCU=atmega8a srcdir=.. -f ../Makefile all
...
$ cd ../ && mkdir +build-2 && cd +build-2/
$ make F_CPU=1000000 BAUD=9600 MCU=atmega8 srcdir=.. -f ../Makefile all
...
Summary
The changes suggested simplify the building of the AVRUSB500 [1]
programmer's firmware [2] somewhat, when either a current
AVR Libc version is used, or multiple builds (with different
MCUs, MCU clock frequencies, or baud rates) are desired.
[1]
http://tuxgraphics.org/electronics/200510/article05101.shtml
[2]
http://tuxgraphics.org/common/src2/article05101/avrusb500-1.7.tar.gz
Please note that a major portion of Makefile was, to put it
simply, "simplified out" in the process. It's left up to the
user to integrate the few lines specific to the new Makefile
(check F_CPU, BAUD, and CPPFLAGS) back into the old one, should
it become necessary to re-enable the now-missing features.
The ChangeLog entry is as follows.
2013-04-26 Ivan Shmakov <
onei...@gmail.com>
Makefile: Rewritten.
spi.c (F_CPU): Removed preprocessor definition.
timeout.c (F_CPU): Likewise.
uart.c (BAUD): Define, unless already defined.
(util/setbaud.h): Include it.
(uart_init): Use UBRRH_VALUE, UBRRL_VALUE, and USE_2X (as
calculated within util/setbaud.h.)
uart.h (uart_sendstr_p): Redefined to use PGM_P (was:
const prog_char *.)
uart.c (uart_sendstr_p): Likewise.
The patch
### Makefile -*- Makefile -*-
MCU = atmega8
## for 3.6864 MHz external crystal oscillator
F_CPU = 3686400
BAUD = 115200
## for 1 MHz internal RC oscillator
# F_CPU = 1000000
# BAUD = 9600
CC = avr-gcc
OBJCOPY = avr-objcopy
# optimize for size:
CFLAGS = -g -mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -mcall-prologues
CPPFLAGS = -I$(srcdir) -DF_CPU=$(F_CPU)UL -DBAUD=$(BAUD)
VPATH = $(srcdir)
all: avrusb500 avrusb500.hex
avrusb500.hex : avrusb500
$(OBJCOPY) -R .eeprom -O ihex $< $@
avr-size $@
@echo " "
@echo "Expl.: data=initialized data, bss=uninitialized data, text=code"
@echo " "
avrusb500 : main.o uart.o spi.o timeout.o
$(CC) $(CFLAGS) -o $@ -Wl,-Map,$@.map $^
%.o : %.c
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
main.o : main.c led.h avr_compat.h command.h spi.h uart.h timeout.h
timeout.o : timeout.c timeout.h avr_compat.h
spi.o : spi.c spi.h avr_compat.h timeout.h
uart.o : uart.c uart.h avr_compat.h timeout.h
### Makefile ends here
--- spi.c.~1~ 2007-04-08 20:17:52.000000000 +0000
+++ spi.c 2013-03-21 08:26:33.000000000 +0000
@@ -7,8 +7,6 @@
#include <avr/io.h>
#include "avr_compat.h"
#include "timeout.h"
-// timing for software spi:
-#define F_CPU 3686400UL // 3.6864 MHz
#include <util/delay.h>
static unsigned char sck_dur=1;
static unsigned char spi_in_sw=0;
--- timeout.c.~1~ 2006-11-06 00:11:37.000000000 +0000
+++ timeout.c 2013-03-21 08:26:37.000000000 +0000
@@ -10,7 +10,6 @@
#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/wdt.h>
-#define F_CPU 3686400UL // 3.6864 MHz
#include <util/delay.h>
#include "avr_compat.h"
--- uart.c.~1~ 2007-09-17 12:58:24.000000000 +0000
+++ uart.c 2013-04-26 12:36:41.000000000 +0000
@@ -12,12 +12,21 @@
#include "avr_compat.h"
#include "timeout.h"
+#ifndef BAUD
+#define BAUD 9600
+#endif
+#include <util/setbaud.h>
+
void uart_init(void)
{
- // baud=1=115.2K only with an external 3.6864MHz crystal:
- unsigned int baud=1;
- UBRRH=(unsigned char) (baud >>8);
- UBRRL=(unsigned char) (baud & 0xFF);
+ UBRRH = UBRRH_VALUE;
+ UBRRL = UBRRL_VALUE;
+#if USE_2X
+ UCSRA |= (1 << U2X);
+#else
+ UCSRA &= ~(1 << U2X);
+#endif
+
/* enable tx/rx and no interrupt on tx/rx */
UCSRB = (1<<RXEN) | (1<<TXEN);
/* format: asynchronous, 8data, no parity, 1stop bit */
@@ -40,7 +49,8 @@
}
}
-void uart_sendstr_p(const prog_char *progmem_s)
+void
+uart_sendstr_p (PGM_P progmem_s)
/* print string from program memory on rs232 */
{
char c;
--- uart.h.~1~ 2006-05-02 14:00:34.000000000 +0000
+++ uart.h 2013-03-21 08:41:12.000000000 +0000
@@ -11,7 +11,7 @@
extern void uart_init(void);
extern void uart_sendchar(char c);
extern void uart_sendstr(char *s);
-extern void uart_sendstr_p(const prog_char *progmem_s);
+extern void uart_sendstr_p (PGM_P progmem_s);
extern unsigned char uart_getchar(unsigned char kickwd);
extern void uart_flushRXbuf(void);
--
FSF associate member #7257