mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-12-23 12:45:31 +02:00
atusb/fw/: flash a boot loader instead of the application (in progress)
- boot.c: basic boot loader that runs DFU for 2 s, then starts the payload - board.h (DFU_USB_VENDOR, DFU_USB_PRODUCT): added USB IDs for DFU - flash.c: stubs for board-specific Flash functions - Makefile: build boot.hex for the boot loader - Makefile (prog): load the boot loader at its rightful place - Makefile (prog): also set hfuse and the lock fuse
This commit is contained in:
parent
f91738c306
commit
e8bed1f3c1
@ -24,9 +24,11 @@ AVR_PREFIX = $(BIN_PATH) avr-
|
||||
CC = $(AVR_PREFIX)gcc
|
||||
OBJCOPY = $(AVR_PREFIX)objcopy
|
||||
#OBJDUMP = $(AVR_PREFIX)objdump
|
||||
SIZE = $(AVR_PREFIX)size
|
||||
|
||||
USB_OBJS = usb.o atu2.o
|
||||
OBJS = atusb.o board.o spi.o descr.o ep0.o $(USB_OBJS)
|
||||
BOOT_OBJS = boot.o board.o spi.o flash.o dfu.o $(USB_OBJS)
|
||||
|
||||
vpath %.c usb/
|
||||
|
||||
@ -54,22 +56,32 @@ endif
|
||||
|
||||
# ----- Rules -----------------------------------------------------------------
|
||||
|
||||
.PHONY: all clean upload prog version.c
|
||||
.PHONY: all clean upload prog version.c
|
||||
|
||||
all: $(NAME).bin
|
||||
all: $(NAME).bin boot.hex
|
||||
|
||||
$(NAME).elf: $(OBJS)
|
||||
$(MAKE) version.o
|
||||
$(CC) $(CFLAGS) -mmcu=$(CHIP) -o $@ $(OBJS) version.o
|
||||
|
||||
boot.elf: $(BOOT_OBJS)
|
||||
$(CC) $(CFLAGS) -mmcu=$(CHIP) -o $@ $(BOOT_OBJS) \
|
||||
-Wl,--section-start=.text=0x7000
|
||||
|
||||
%.bin: %.elf
|
||||
$(BUILD) $(OBJCOPY) -j .text -j .data -O binary $< $@
|
||||
@echo "build #`cat .version`, `ls -l $@`"
|
||||
|
||||
%.hex: %.elf
|
||||
$(BUILD) $(OBJCOPY) -j .text -j .data -O ihex $< $@
|
||||
$(SIZE) $@
|
||||
|
||||
# ----- Cleanup ---------------------------------------------------------------
|
||||
|
||||
clean:
|
||||
rm -f $(NAME).bin $(NAME).elf $(OBJS) $(OBJS:.o=.d)
|
||||
rm -f $(NAME).bin $(NAME).elf
|
||||
rm -f $(OBJS) $(OBJS:.o=.d)
|
||||
rm -f $(BOOT_OBJS) $(BOOT_OBJS:.o=.d)
|
||||
rm -f version.c version.d version.o
|
||||
|
||||
# ----- Build version ---------------------------------------------------------
|
||||
@ -102,13 +114,21 @@ version.c:
|
||||
|
||||
# ----- Programming and device control ----------------------------------------
|
||||
|
||||
upload: $(NAME).bin
|
||||
scp $(NAME).bin $(HOST):
|
||||
upload: $(NAME).bin boot.hex
|
||||
scp $(NAME).bin boot.hex $(HOST):
|
||||
|
||||
# lfuse: external clock, slow start-up
|
||||
# hfuse: 4 kB boot loader, reset into boot loader
|
||||
# lock: allow everything but SPM to the boot loader
|
||||
|
||||
prog:
|
||||
ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \
|
||||
-U flash:w:$(NAME).bin:r \
|
||||
-U lfuse:w:0x60:m # external clock, slow start-up
|
||||
-U flash:w:boot.hex:i \
|
||||
-U lfuse:w:0x60:m \
|
||||
-U hfuse:w:0xde:m \
|
||||
-U lock:w:0xef:m
|
||||
|
||||
# -U flash:w:$(NAME).bin:r \
|
||||
|
||||
on:
|
||||
ssh $(HOST) poke 0x10010318 4
|
||||
|
@ -58,11 +58,16 @@
|
||||
#define USB_VENDOR 0x20b7 /* Qi Hardware */
|
||||
#define USB_PRODUCT 0x1540 /* ben-wpan atusb */
|
||||
|
||||
#define DFU_USB_VENDOR USB_VENDOR
|
||||
#define DFU_USB_PRODUCT USB_PRODUCT
|
||||
|
||||
|
||||
void reset_rf(void);
|
||||
uint8_t read_irq(void);
|
||||
|
||||
void led(int on);
|
||||
void panic(void);
|
||||
|
||||
void board_init(void);
|
||||
|
||||
#endif /* !BOARD_H */
|
||||
|
63
atusb/fw/boot.c
Normal file
63
atusb/fw/boot.c
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* fw/boot.c - DFU boot loader for ATUSB
|
||||
*
|
||||
* Written 2008-2011 by Werner Almesberger
|
||||
* Copyright 2008-2011 Werner Almesberger
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
#define F_CPU 8000000UL
|
||||
#include <util/delay.h>
|
||||
|
||||
#include "usb.h"
|
||||
#include "dfu.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "spi.h"
|
||||
#include "atusb/ep0.h"
|
||||
|
||||
|
||||
#define MS_TO_LOOPS(ms) ((uint32_t) (ms)*81)
|
||||
|
||||
|
||||
static void (*run_payload)(void) = 0;
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint32_t loop = 0;
|
||||
|
||||
board_init();
|
||||
spi_init();
|
||||
reset_rf();
|
||||
|
||||
/* now we should be at 8 MHz */
|
||||
|
||||
usb_init();
|
||||
dfu_init();
|
||||
|
||||
led(1);
|
||||
|
||||
while (loop != MS_TO_LOOPS(2000)) {
|
||||
usb_poll();
|
||||
if (dfu.state == dfuIDLE)
|
||||
loop++;
|
||||
else
|
||||
loop = 0;
|
||||
}
|
||||
|
||||
led(0);
|
||||
|
||||
run_payload();
|
||||
|
||||
while (1); /* not reached */
|
||||
}
|
46
atusb/fw/flash.c
Normal file
46
atusb/fw/flash.c
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* fw/flash.c - Board-specific flash functions
|
||||
*
|
||||
* Written 2011 by Werner Almesberger
|
||||
* Copyright 2011 Werner Almesberger
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#define F_CPU 8000000UL
|
||||
#include <util/delay.h>
|
||||
|
||||
#include "dfu.h"
|
||||
#include "board.h"
|
||||
|
||||
|
||||
|
||||
void flash_start(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int flash_can_write(uint16_t size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void flash_write(const uint8_t *buf, uint16_t size)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
uint16_t flash_read(uint8_t *buf, uint16_t size)
|
||||
{
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user