Permalink
Browse files

added support for new xmega page sizes

The makefile has been changed to handle different page sizes for the app
and boot sections of the flash. Newer Xmegas have defines that aren't
compatible with the way the bootloader previously worked. This commit
should provide support for both.
  • Loading branch information...
bandtank committed Nov 3, 2013
1 parent 9f1d81f commit 38df3621b805d57a683768faa3f6a57eaea74e9e
Showing with 92 additions and 103 deletions.
  1. +54 −46 README
  2. +3 −3 Xmega_Bootloader.c
  3. +0 −1 config_macros.h
  4. +0 −31 file2
  5. +27 −14 makefile
  6. +8 −8 sp_driver.s
View
100 README
@@ -16,51 +16,59 @@ Bootloader Instructions (configure each setting in the makefile):
How to configure:
In the makefile, you will see the following block of text at the top of the file. You should not need to edit anything other than this block of code unless you are adding support for additional baud rates or devices.
###############################################################################
# User modification section
###############################################################################
# Choose one of the following MCUs:
# If you have a different MCU, you will have to define the
# BOOT_SECTION_START_IN_BYTES and FLASH_PAGE_SIZE_IN_BYTES for
# -section-start and the number of bytes to program at a time respectively.
# This information can be found in the iox....h file as BOOT_SECTION_START
# and PROGMEM_PAGE_SIZE.
# MCU = atxmega128a1
# MCU = atxmega64a3
# MCU = atxmega32a4
# MCU = atxmega16a4
MCU = atxmega16d4
# Choose a baud rate for the UART.
# If you need a baud rate that is not listed in this makefile, you must add
# new configuration statements in config.macros.h. Remember, Xmegas start-up
# with a 2MHz clock.
# BAUD_RATE = 9600
# BAUD_RATE = 38400
# BAUD_RATE = 57600
BAUD_RATE = 115200
# Specify a pin to check for entry into the bootloader. The notation is
# PORT,PIN. For example, if you wanted to use PIN 3 on PORTC, you would set
# the option as C,3. Then specifiy the logic value required to enable the
# bootloader code (1 = enable the bootloader if the pin is VCC, 0 = enable
# the bootloader if the pin is GND).
BOOTLOADER_PIN = B,2
BOOTLOADER_PIN_ON = 1
# Specify a pin to control an LED. The notation is PORT,PIN. For example, if
# you wanted to use PIN 6 on PORTA, you would set the option as A,6. Then
# specifiy the logic value required to enable the LED (1 = output VCC to turn
# on the LED, 0 = output GND to turn on the LED).
LED_PIN = D,2
LED_ON = 0
# Specify which UART to use with PORT,NUM notation. For example, UART1 on
# PORTD would be D,1.
UART = C,0
###############################################################################
# End user modification section
###############################################################################
###############################################################################
# User modification section
###############################################################################
# Choose one of the following MCUs:
# If you have a different MCU, you will have to define these values:
# Name in makefile Name in ioxxxx.h
# --------------------------- -----------------------------
# BOOT_SECTION_START_IN_BYTES BOOT_SECTION_START
# BOOT_PAGE_SIZE BOOT_SECTION_PAGE_SIZE
# APP_PAGE_SIZE APP_SECTION_PAGE_SIZE
#
# You can find these files in the include path for your compiler. Examples:
# 1) Winavr: C:\WinAVR-20100110\avr\include\avr\ioxxxx.h
# 2) Atmel 3.4.2: C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\
# Native\3.4.2.1002\avr8-gnu-toolchain\avr\include\avr\ioxxxx.h
# MCU = atxmega128a1
# MCU = atxmega64a3
MCU = atxmega64a3u
# MCU = atxmega32a4
# MCU = atxmega16a4
# MCU = atxmega16d4
# Choose a baud rate for the UART.
# If you need a baud rate that is not listed in this makefile, you must add
# new configuration statements in config.macros.h. Remember, Xmegas start-up
# with a 2MHz clock.
# BAUD_RATE = 9600
# BAUD_RATE = 38400
# BAUD_RATE = 57600
BAUD_RATE = 115200
# Specify a pin to check for entry into the bootloader. The notation is
# PORT,PIN. For example, if you wanted to use PIN 3 on PORTC, you would set
# the option as C,3. Then specifiy the logic value required to enable the
# bootloader code (1 = enable the bootloader if the pin is VCC, 0 = enable
# the bootloader if the pin is GND).
BOOTLOADER_PIN = B,2
BOOTLOADER_PIN_ON = 0
# Specify a pin to control an LED. The notation is PORT,PIN. For example, if
# you wanted to use PIN 6 on PORTA, you would set the option as A,6. Then
# specifiy the logic value required to enable the LED (1 = output VCC to turn
# on the LED, 0 = output GND to turn on the LED).
LED_PIN = D,2
LED_ON = 0
# Specify which UART to use with PORT,NUM notation. For example, UART1 on
# PORTD would be D,1.
UART = C,0
###############################################################################
# End user modification section
###############################################################################
Please email me (anthonyandriano@gmail.com) if you have any questions or comments about the code. I will respond very quickly.
View
@@ -44,8 +44,8 @@
unsigned char BlockLoad(unsigned int size, unsigned char mem, ADDR_T *address);
void BlockRead(unsigned int size, unsigned char mem, ADDR_T *address);
/* BLOCKSIZE should be chosen so that the following holds: BLOCKSIZE*n = PAGESIZE, where n=1,2,3... */
#define BLOCKSIZE PAGESIZE
/* BLOCKSIZE should be chosen so that the following holds: BLOCKSIZE*n = APP_PAGE_SIZE, where n=1,2,3... */
#define BLOCKSIZE APP_PAGE_SIZE
#endif /* REMOVE_BLOCK_SUPPORT */
@@ -119,7 +119,7 @@ int main(void)
// Chip erase.
else if(val=='e')
{
for(address = 0; address < APP_END; address += PAGESIZE)
for(address = 0; address < APP_END; address += APP_PAGE_SIZE)
{ // NOTE: Here we use address as a byte-address, not word-address, for convenience.
SP_WaitForSPM();
#ifdef __ICCAVR__
View
@@ -59,7 +59,6 @@
// It gets values from iox.....h
// SPM control
#define PAGESIZE PROGMEM_PAGE_SIZE
#define APP_END (APP_SECTION_START + APP_SECTION_SIZE)
#if(APP_SECTION_SIZE >= 0x10000)
View
31 file2

This file was deleted.

Oops, something went wrong.
View
@@ -9,14 +9,21 @@ PROJECT = Xmega_Bootloader
# User modification section
###############################################################################
# Choose one of the following MCUs:
# If you have a different MCU, you will have to define the
# BOOT_SECTION_START_IN_BYTES and FLASH_PAGE_SIZE_IN_BYTES for
# -section-start and the number of bytes to program at a time respectively.
# This information can be found in the iox....h file as BOOT_SECTION_START
# and PROGMEM_PAGE_SIZE.
# If you have a different MCU, you will have to define these values:
# Name in makefile Name in ioxxxx.h
# --------------------------- -----------------------------
# BOOT_SECTION_START_IN_BYTES BOOT_SECTION_START
# BOOT_PAGE_SIZE BOOT_SECTION_PAGE_SIZE
# APP_PAGE_SIZE APP_SECTION_PAGE_SIZE
#
# You can find these files in the include path for your compiler. Examples:
# 1) Winavr: C:\WinAVR-20100110\avr\include\avr\ioxxxx.h
# 2) Atmel 3.4.2: C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\
# Native\3.4.2.1002\avr8-gnu-toolchain\avr\include\avr\ioxxxx.h
# MCU = atxmega128a1
MCU = atxmega64a3
# MCU = atxmega64a3u
# MCU = atxmega64a3
MCU = atxmega64a3u
# MCU = atxmega32a4
# MCU = atxmega16a4
# MCU = atxmega16d4
@@ -56,32 +63,38 @@ MCU = atxmega64a3
## Set configuration options based on MCU model
ifeq ($(MCU), atxmega128a1)
BOOT_SECTION_START_IN_BYTES = 0x20000
FLASH_PAGE_SIZE = 512
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega64a3)
BOOT_SECTION_START_IN_BYTES = 0x10000
FLASH_PAGE_SIZE = 256
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega64a3u)
BOOT_SECTION_START_IN_BYTES = 0x10000
FLASH_PAGE_SIZE = 256
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega32a4)
BOOT_SECTION_START_IN_BYTES = 0x8000
FLASH_PAGE_SIZE = 256
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega16a4)
BOOT_SECTION_START_IN_BYTES = 0x4000
FLASH_PAGE_SIZE = 256
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega16d4)
BOOT_SECTION_START_IN_BYTES = 0x4000
FLASH_PAGE_SIZE = 256
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
TARGET = $(PROJECT).elf
@@ -91,7 +104,7 @@ CC = avr-gcc
CPP = avr-g++
## Compile options common for all C compilation units.
CFLAGS += -mmcu=$(MCU) -Wall -gdwarf-2 -std=gnu99 -DF_CPU=2000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -DFLASH_PAGE_SIZE=$(FLASH_PAGE_SIZE) -DMCU=$(MCU) -DBAUD_RATE=$(BAUD_RATE) -DMY_UART=$(UART) -DENTER_BOOTLOADER_PIN=$(BOOTLOADER_PIN) -DLED_PIN=$(LED_PIN) -DLED_ON=$(LED_ON) -DBOOTLOADER_PIN_EN=$(BOOTLOADER_PIN_ON) -DBOOTUP_DELAY=$(BOOTUP_DELAY)
CFLAGS += -mmcu=$(MCU) -Wall -gdwarf-2 -std=gnu99 -DF_CPU=2000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -DBOOT_PAGE_SIZE=$(BOOT_PAGE_SIZE) -DAPP_PAGE_SIZE=$(APP_PAGE_SIZE) -DMCU=$(MCU) -DBAUD_RATE=$(BAUD_RATE) -DMY_UART=$(UART) -DENTER_BOOTLOADER_PIN=$(BOOTLOADER_PIN) -DLED_PIN=$(LED_PIN) -DLED_ON=$(LED_ON) -DBOOTLOADER_PIN_EN=$(BOOTLOADER_PIN_ON) -DBOOTUP_DELAY=$(BOOTUP_DELAY)
CFLAGS += -MD -MP -MT $(*F).o
## Assembly specific flags
View
@@ -385,11 +385,11 @@ SP_LoadFlashPage:
ldi r20, NVM_CMD_LOAD_FLASH_BUFFER_gc ; Prepare NVM command code in R20.
sts NVM_CMD, r20 ; Load it into NVM command register.
#if FLASH_PAGE_SIZE > 512
ldi r22, ((FLASH_PAGE_SIZE/2) >> 8)
#if APP_PAGE_SIZE > 512
ldi r22, ((APP_PAGE_SIZE/2) >> 8)
#endif
ldi r21, ((FLASH_PAGE_SIZE/2)&0xFF) ; Load R21 with page word count.
ldi r21, ((APP_PAGE_SIZE/2)&0xFF) ; Load R21 with page word count.
ldi r18, CCP_SPM_gc ; Prepare Protect SPM signature in R16.
SP_LoadFlashPage_1:
@@ -399,7 +399,7 @@ SP_LoadFlashPage_1:
spm ; Self-program.
adiw ZL, 2 ; Move Z to next Flash word.
#if FLASH_PAGE_SIZE > 512
#if APP_PAGE_SIZE > 512
subi r21, 1 ; Decrement word count.
sbci r22, 0
#else
@@ -441,19 +441,19 @@ SP_ReadFlashPage:
ldi r20, NVM_CMD_NO_OPERATION_gc ; Prepare NVM command code in R20.
sts NVM_CMD, r20 ; Set NVM command to No Operation so that LPM reads Flash.
#if FLASH_PAGE_SIZE > 512
ldi r22, ((FLASH_PAGE_SIZE/2) >> 8) ; Load R22 with byte cont high if flash page is large.
#if APP_PAGE_SIZE > 512
ldi r22, ((APP_PAGE_SIZE/2) >> 8) ; Load R22 with byte cont high if flash page is large.
#endif
ldi r21, ((FLASH_PAGE_SIZE)&0xFF) ; Load R21 with byte count.
ldi r21, ((APP_PAGE_SIZE)&0xFF) ; Load R21 with byte count.
SP_ReadFlashPage_1:
elpm r24, Z+ ; Load Flash bytes into R18:r19
elpm r25, Z+
st X+, r24 ; Write bytes to buffer.
st X+, r25
#if FLASH_PAGE_SIZE > 512
#if APP_PAGE_SIZE > 512
subi r21, 1 ; Decrement word count.
sbci r22, 0
#else

0 comments on commit 38df362

Please sign in to comment.