1 /* Name: bootloaderconfig.h
2 * Project: USBaspLoader
3 * Author: Christian Starkjohann
4 * Author: Stephan Baerwolf
5 * Creation Date: 2007-12-08
6 * Modification Date: 2012-11-10
8 * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
9 * License: GNU GPL v2 (see License.txt)
10 * This Revision: $Id: bootloaderconfig.h 729 2009-03-20 09:03:58Z cs $
13 #ifndef __bootloaderconfig_h_included__
14 #define __bootloaderconfig_h_included__
18 This file (together with some settings in Makefile) configures the boot loader
19 according to the hardware.
21 This file contains (besides the hardware configuration normally found in
22 usbconfig.h) two functions or macros: bootLoaderInit() and
23 bootLoaderCondition(). Whether you implement them as macros or as static
24 inline functions is up to you, decide based on code size and convenience.
26 bootLoaderInit() is called as one of the first actions after reset. It should
27 be a minimum initialization of the hardware so that the boot loader condition
28 can be read. This will usually consist of activating a pull-up resistor for an
29 external jumper which selects boot loader mode.
31 bootLoaderCondition() is called immediately after initialization and in each
32 main loop iteration. If it returns TRUE, the boot loader will be active. If it
33 returns FALSE, the boot loader jumps to address 0 (the loaded application)
36 For compatibility with Thomas Fischl's avrusbboot, we also support the macro
37 names BOOTLOADER_INIT and BOOTLOADER_CONDITION for this functionality. If
38 these macros are defined, the boot loader usees them.
41 /* ---------------------------- Macro Magic ---------------------------- */
42 #define PIN_CONCAT(a,b) a ## b
43 #define PIN_CONCAT3(a,b,c) a ## b ## c
45 #define PIN_PORT(a) PIN_CONCAT(PORT, a)
46 #define PIN_PIN(a) PIN_CONCAT(PIN, a)
47 #define PIN_DDR(a) PIN_CONCAT(DDR, a)
49 #define PIN(a, b) PIN_CONCAT3(P, a, b)
51 /* ---------------------------- Hardware Config ---------------------------- */
53 #ifndef USB_CFG_IOPORTNAME
54 #define USB_CFG_IOPORTNAME D
56 /* This is the port where the USB bus is connected. When you configure it to
57 * "B", the registers PORTB, PINB and DDRB will be used.
59 #ifndef USB_CFG_DMINUS_BIT
60 #define USB_CFG_DMINUS_BIT 6 /* old value was 4 */
62 /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
63 * This may be any bit in the port.
65 #ifndef USB_CFG_DPLUS_BIT
66 #define USB_CFG_DPLUS_BIT 2
68 /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
69 * This may be any bit in the port. Please note that D+ must also be connected
70 * to interrupt pin INT0!
73 #define JUMPER_PORT USB_CFG_IOPORTNAME
76 * jumper is connected to this port
79 #define JUMPER_BIT 7 /* old value was 0 */
82 * jumper is connected to this bit in port "JUMPER_PORT", active low
85 #define USB_CFG_CLOCK_KHZ (F_CPU/1000)
86 /* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
87 * The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
88 * deviation from the nominal frequency. All other rates require a precision
89 * of 2000 ppm and thus a crystal!
90 * Default if not specified: 12 MHz
93 /* ----------------------- Optional Hardware Config ------------------------ */
95 /* #define USB_CFG_PULLUP_IOPORTNAME D */
96 /* If you connect the 1.5k pullup resistor from D- to a port pin instead of
97 * V+, you can connect and disconnect the device from firmware by calling
98 * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
99 * This constant defines the port on which the pullup resistor is connected.
101 /* #define USB_CFG_PULLUP_BIT 4 */
102 /* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
103 * above) where the 1.5k pullup resistor is connected. See description
107 /* ------------------------------------------------------------------------- */
108 /* ---------------------- feature / code size options ---------------------- */
109 /* ------------------------------------------------------------------------- */
111 #ifndef CONFIG_NO__HAVE_READ_LOCK_FUSE
112 #define HAVE_READ_LOCK_FUSE 1
114 #define HAVE_READ_LOCK_FUSE 0
117 * enable the loaders capability to load its lfuse, hfuse and lockbits
118 * ...However, programming of these is prohibited...
121 #ifndef CONFIG_NO__HAVE_BLB11_SOFTW_LOCKBIT
122 #define HAVE_BLB11_SOFTW_LOCKBIT 1
124 #define HAVE_BLB11_SOFTW_LOCKBIT 0
127 * The IC itself do not need to prgra BLB11, but the bootloader will avaoid
128 * to erase itself from the bootregion
131 #ifndef CONFIG_NO__HAVE_SPMINTEREFACE
132 #define HAVE_SPMINTEREFACE 1
134 #define HAVE_SPMINTEREFACE 0
137 * Since code within normal section of application memory (rww-section) is
138 * not able to call spm for programming flash-pages, this option (when
139 * enabled) will insert a small subroutine into the bootloader-section
140 * to enable applications to circumvent this limitation and make them
141 * able to program the flash in a similar way as the bootloader does, too.
142 * For further details see "spminterface.h", which implements this
146 #define HAVE_EEPROM_PAGED_ACCESS 1
147 /* If HAVE_EEPROM_PAGED_ACCESS is defined to 1, page mode access to EEPROM is
148 * compiled in. Whether page mode or byte mode access is used by AVRDUDE
149 * depends on the target device. Page mode is only used if the device supports
150 * it, e.g. for the ATMega88, 168 etc. You can save quite a bit of memory by
151 * disabling page mode EEPROM access. Costs ~ 138 bytes.
153 #define HAVE_EEPROM_BYTE_ACCESS 1
154 /* If HAVE_EEPROM_BYTE_ACCESS is defined to 1, byte mode access to EEPROM is
155 * compiled in. Byte mode is only used if the device (as identified by its
156 * signature) does not support page mode for EEPROM. It is required for
157 * accessing the EEPROM on the ATMega8. Costs ~54 bytes.
159 #ifndef CONFIG_NO__BOOTLOADER_CAN_EXIT
160 #define BOOTLOADER_CAN_EXIT 1
162 #define BOOTLOADER_CAN_EXIT 0
164 /* If this macro is defined to 1, the boot loader will exit shortly after the
165 * programmer closes the connection to the device. Costs extra bytes.
167 #define HAVE_CHIP_ERASE 0
168 /* If this macro is defined to 1, the boot loader implements the Chip Erase
169 * ISP command. Otherwise pages are erased on demand before they are written.
171 #ifndef CONFIG_NO__NEED_WATCHDOG
172 #define NEED_WATCHDOG 1
174 #define NEED_WATCHDOG 0
176 /* ATTANTION: This macro MUST BE 1, if the MCU has reset enabled watchdog (WDTON is 0).
177 * If this macro is defined to 1, the bootloader implements an additional "wdt_disable()"
178 * after its contional entry point.
179 * If the used MCU is fused not to enable watchdog after reset (WDTON is 1 - safty level 1)
180 * then "NEED_WATCHDOG" may be deactivated in order to save some memory.
182 //#define SIGNATURE_BYTES 0x1e, 0x93, 0x07, 0 /* ATMega8 */
183 /* This macro defines the signature bytes returned by the emulated USBasp to
184 * the programmer software. They should match the actual device at least in
185 * memory size and features. If you don't define this, values for ATMega8,
186 * ATMega88, ATMega168 and ATMega328 are guessed correctly.
190 /* ------------------------------------------------------------------------- */
192 /* Example configuration: Port D bit 3 is connected to a jumper which ties
193 * this pin to GND if the boot loader is requested. Initialization allows
194 * several clock cycles for the input voltage to stabilize before
195 * bootLoaderCondition() samples the value.
196 * We use a function for bootLoaderInit() for convenience and a macro for
197 * bootLoaderCondition() for efficiency.
200 #ifndef __ASSEMBLER__ /* assembler cannot parse function definitions */
202 #ifndef MCUCSR /* compatibility between ATMega8 and ATMega88 */
203 # define MCUCSR MCUSR
206 static inline void bootLoaderInit(void)
208 PIN_DDR(JUMPER_PORT
) = 0;
209 PIN_PORT(JUMPER_PORT
) = (1<< PIN(JUMPER_PORT
, JUMPER_BIT
)); /* activate pull-up */
211 // deactivated by Stephan - reset after each avrdude op is annoing!
212 // if(!(MCUCSR & (1 << EXTRF))) /* If this was not an external reset, ignore */
213 // leaveBootloader();
215 MCUCSR
= 0; /* clear all reset flags for next time */
218 #if BOOTLOADER_CAN_EXIT
219 static inline void bootLoaderExit(void)
221 PIN_PORT(JUMPER_PORT
) = 0; /* undo bootLoaderInit() changes */
225 #define bootLoaderCondition() ((PIN_PIN(JUMPER_PORT) & (1 << PIN(JUMPER_PORT, JUMPER_BIT))) == 0)
227 #endif /* __ASSEMBLER__ */
229 /* ------------------------------------------------------------------------- */
231 #endif /* __bootloader_h_included__ */