diff --git a/avr/bootloader/Makefile b/avr/bootloader/Makefile index 49eda74..39e6279 100644 --- a/avr/bootloader/Makefile +++ b/avr/bootloader/Makefile @@ -4,15 +4,17 @@ TARGET = bootloader F_CPU = 20000000UL MCU = atmega644 -SRC = bootloader.c +SRC = bootloader.c ASRC = usbdrv/usbdrvasm.S interrupts.S OBJECTS += $(patsubst %.c,%.o,${SRC}) OBJECTS += $(patsubst %.S,%.o,${ASRC}) HEADERS += $(shell echo *.h) # CFLAGS += -Werror + LDFLAGS += -L/usr/local/avr/avr/lib CFLAGS += -Iusbdrv -I. CFLAGS += -DHARDWARE_REV=$(HARDWARE_REV) +CDEFS += -DF_CPU ASFLAGS += -x assembler-with-cpp ASFLAGS += -Iusbdrv -I. @@ -36,12 +38,12 @@ else ifeq ($(MCU),atmega88) # bootloader section starts at 0xc00 (word-address) == 0x1800 (byte-address) BOOT_SECTION_START = 0x1800 else ifeq ($(MCU),atmega644) - # atmega88 with 2048 words bootloader: + # atmega644 with 2048 words bootloader: # bootloader section starts at 0x7800 (word-address) == 0xF000 (byte-address) BOOT_SECTION_START = 0xf000 endif -LDFLAGS += -Wl,--section-start=.text=$(BOOT_SECTION_START) +LDFLAGS += -Wl,--section-start=.text=$(BOOT_SECTION_START) -Wl,-u,vfprintf CFLAGS += -DBOOT_SECTION_START=$(BOOT_SECTION_START) diff --git a/avr/bootloader/avr.mk b/avr/bootloader/avr.mk index e93c6ee..30f7814 100644 --- a/avr/bootloader/avr.mk +++ b/avr/bootloader/avr.mk @@ -15,7 +15,6 @@ AS = avr-as CP = cp RM = rm -f AVRDUDE = avrdude -AVRDUDE_BAUDRATE = 19200 SIZE = avr-size -include $(CURDIR)/config.mk diff --git a/avr/bootloader/bootloader.c b/avr/bootloader/bootloader.c index 7442d4c..a2ba389 100644 --- a/avr/bootloader/bootloader.c +++ b/avr/bootloader/bootloader.c @@ -95,16 +95,38 @@ static const uint8_t signature[4] = { # error "BOOT_SECTION_START undefined!" #endif +#if defined (__AVR_ATmega644__) + /* Due arvdude limitations we can't erase the whole progmem + without running into an usb timeount on cleint side. So we + we limit the erase section by 0x1000 + */ + #define ERASE_SECTION 0xe000 +#else + #define ERASE_SECTION BOOT_SECTION_START +#endif + #ifdef DEBUG_UART -static __attribute__ (( __noinline__ )) void putc(uint8_t data) { +static __attribute__ (( __noinline__ )) void uart_putc(uint8_t data) { while(!(UCSR0A & _BV(UDRE0))); UDR0 = data; } #else -#define putc(x) + #define uart_putc(x) #endif +#ifdef DEBUG_UART +static __attribute__ (( __noinline__ )) void uart_puts(uint8_t *data) { + while(*data){ + uart_putc(*data); + data++; + } +} +#else + #define uart_puts(x) +#endif + + /* supply custom usbDeviceConnect() and usbDeviceDisconnect() macros * which turn the interrupt on and off at the right times, * and prevent the execution of an interrupt while the pullup resistor @@ -150,6 +172,8 @@ uint8_t request_exit; uint8_t timeout; + + usbMsgLen_t usbFunctionSetup(uchar data[8]) { usbRequest_t *req = (void *)data; @@ -204,16 +228,20 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) /* catch a chip erase */ } else if (data[2] == ISP_CHIP_ERASE1 && data[3] == ISP_CHIP_ERASE2) { + uart_puts("\n\rErase Flash"); for (flash_address.word = 0; - flash_address.word < BOOT_SECTION_START; + flash_address.word < ERASE_SECTION; flash_address.word += SPM_PAGESIZE) { /* wait and erase page */ boot_spm_busy_wait(); + if (flash_address.word && flash_address.word%1024 == 0 ) + uart_putc('.'); cli(); boot_page_erase(flash_address.word); sei(); } + uart_puts("\n\r"); } /* in case no data has been filled in by the if's above, just return zeroes */ @@ -228,10 +256,6 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) #endif } else if (req->bRequest >= USBASP_FUNC_READFLASH) { /* && req->bRequest <= USBASP_FUNC_SETLONGADDRESS */ - - putc('R'); - putc(req->bRequest); - /* extract address and length */ flash_address.word = req->wValue.word; bytes_remaining = req->wLength.bytes[0]; @@ -248,11 +272,11 @@ uchar usbFunctionWrite(uchar *data, uchar len) if (len > bytes_remaining) len = bytes_remaining; bytes_remaining -= len; - if (request == USBASP_FUNC_WRITEEEPROM) { for (uint8_t i = 0; i < len; i++) eeprom_write_byte((uint8_t *)flash_address.word++, *data++); - } else { + } + else { /* data is handled wordwise, adjust len */ len /= 2; len -= 1; @@ -334,47 +358,42 @@ int __attribute__ ((noreturn,OS_main)) main(void) { /* start bootloader */ - #ifdef DEBUG_UART /* init uart (115200 baud, at 20mhz) */ UBRR0L = 10; UCSR0C = _BV(UCSZ00) | _BV(UCSZ01); UCSR0B = _BV(TXEN0); #endif - putc('0'); - - uint8_t reset = MCUSR; uint16_t delay =0; timeout = TIMEOUT; - + + uart_puts("Snesram Bootloader v0.1\n\r"); /* if power-on reset, quit bootloader via watchdog reset */ if (reset & _BV(PORF)){ - putc('P'); + uart_puts("Found power on reset\n\r"); MCUSR = 0; leave_bootloader(); } /* if watchdog reset, disable watchdog and jump to app */ else if(reset & _BV(WDRF)){ - - MCUSR = 0; + uart_puts("Found watchdog reset\n\r"); + MCUSR = 0; wdt_disable(); - putc('W'); - DLED_TGL; _delay_ms(500); DLED_TGL; _delay_ms(500); - - jump_to_app(); + uart_puts("Jump to main\n\r"); + jump_to_app(); } + uart_puts("Enter programming mode\n\r"); /* else: enter programming mode */ - /* clear external reset flags */ MCUSR = 0; @@ -394,16 +413,11 @@ int __attribute__ ((noreturn,OS_main)) main(void) /* disconnect for ~500ms, so that the host re-enumerates this device */ - putc('d'); usbDeviceDisconnect(); for (uint8_t i = 0; i < 50; i++) _delay_ms(10); /* 0 means 0x10000, 38*1/f*0x10000 =~ 498ms */ usbDeviceConnect(); - putc('c'); - - - - + uart_puts("Wait for firmware"); while(1) { usbPoll(); @@ -411,14 +425,14 @@ int __attribute__ ((noreturn,OS_main)) main(void) /* do some led blinking, so that it is visible that the bootloader is still running */ if (delay == 0) { - putc('p'); + uart_putc('.'); DLED_TGL; if (timeout < 255) timeout--; } if (request_exit || timeout == 0) { - putc('e'); + uart_puts("\n\rExit\n\r"); _delay_ms(10); leave_bootloader(); } diff --git a/avr/bootloader/config.h b/avr/bootloader/config.h index dc47f1d..fe10820 100644 --- a/avr/bootloader/config.h +++ b/avr/bootloader/config.h @@ -16,3 +16,7 @@ /* uncomment this for debug information via uart */ #define DEBUG_UART + + +#define DEBUG 1 +#define DEBUG_USB 2 diff --git a/avr/usbload/Makefile b/avr/usbload/Makefile index 25a11b5..6b75083 100644 --- a/avr/usbload/Makefile +++ b/avr/usbload/Makefile @@ -2,9 +2,9 @@ TTY = /dev/tty.PL2303-00002126 DEVICE = atmega644 F_CPU = 20000000 # in Hz - +TARGET = main AVRDUDE = avrdude -c usbasp -p $(DEVICE) - +SIZE = avr-size CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o dump.o timer.o watchdog.o @@ -31,6 +31,11 @@ help: all: hex hex: main.hex + @echo "===============================" + @echo "$(TARGET) compiled for: $(DEVICE)" + @echo -n "size is: " + @$(SIZE) -A $(TARGET).hex | grep "\.sec1" | tr -s " " | cut -d" " -f2 + @echo "===============================" program: flash fuse diff --git a/snes/monitor/makefile b/snes/monitor/makefile index f51c543..fd9c4f5 100644 --- a/snes/monitor/makefile +++ b/snes/monitor/makefile @@ -30,9 +30,13 @@ spc: $(SPCOFILES) $(SPCOFILES): $(SPCSFILES) $(SPCAC) $(AFLAGS) $(SPCSFILES) +header: + $(UCON) -smc $(ROMFILE) + flash: $(FL) $(FLFLAGS) $(ROMFILE) -upload: + +upload: header $(UCON) $(UCONFLAGS) $(ROMFILE) run: $(EMU) $(ROMFILE) diff --git a/snesram.tmproj b/snesram.tmproj index b1ae0af..a5a0e9d 100644 --- a/snesram.tmproj +++ b/snesram.tmproj @@ -2,8 +2,6 @@ - currentDocument - avr/usbload/main.c documents @@ -21,194 +19,6 @@ 271 metaData - avr/usbload/commandline/snesuploader.c - - caret - - column - 0 - line - 200 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 172 - selectFrom - - column - 0 - line - 195 - - selectTo - - column - 0 - line - 200 - - - avr/usbload/config.h - - caret - - column - 40 - line - 18 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/dump.c - - caret - - column - 1 - line - 50 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/dump.h - - caret - - column - 0 - line - 2 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 0 - selectFrom - - column - 0 - line - 0 - - selectTo - - column - 0 - line - 2 - - - avr/usbload/fifo.h - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/main.c - - caret - - column - 22 - line - 25 - - firstVisibleColumn - 0 - firstVisibleLine - 29 - - avr/usbload/requests.h - - caret - - column - 0 - line - 26 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 0 - selectFrom - - column - 34 - line - 33 - - selectTo - - column - 0 - line - 26 - - - avr/usbload/sram.c - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/watchdog.c - - caret - - column - 20 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/watchdog.h - - caret - - column - 0 - line - 19 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - poc/avr_sdcard/fat.h caret @@ -265,50 +75,7 @@ firstVisibleLine 211 - tools/ucon64/2.0/src/backup/snesram.c - - caret - - column - 53 - line - 204 - - firstVisibleColumn - 0 - firstVisibleLine - 164 - - tools/ucon64/2.0/src/backup/snesram.h - - caret - - column - 0 - line - 32 - - firstVisibleColumn - 0 - firstVisibleLine - 19 - - openDocuments - - avr/usbload/dump.c - avr/usbload/sram.c - avr/usbload/main.c - avr/usbload/watchdog.h - avr/usbload/dump.h - avr/usbload/watchdog.c - avr/usbload/config.h - avr/usbload/requests.h - tools/ucon64/2.0/src/backup/snesram.h - avr/usbload/commandline/snesuploader.c - tools/ucon64/2.0/src/backup/snesram.c - avr/usbload/fifo.h - showFileHierarchyDrawer showFileHierarchyPanel @@ -327,6 +94,21 @@ subItems + bootloader + + isExpanded + + subItems + + usbdrv + + isExpanded + + subItems + + + + usbload isExpanded @@ -349,46 +131,30 @@ isExpanded subItems - + + monitor + + isExpanded + + subItems + + routines + + isExpanded + + subItems + + + + + tools isExpanded subItems - - ucon64 - - isExpanded - - subItems - - 2.0 - - isExpanded - - subItems - - src - - isExpanded - - subItems - - backup - - isExpanded - - subItems - - - - - - - - - +