summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcpldcpu <cpldcpu@gmail.com>2014-02-21 09:09:03 +0100
committercpldcpu <cpldcpu@gmail.com>2014-02-21 09:09:03 +0100
commit2297c1546d74a3cdeed5e3a3c064ca75f122ee4a (patch)
tree53dd1e5f27d23303ed58ca3af8c1bf9f1ab8a83d
parenteef6c9736b07669aee8965533dba963a363b8494 (diff)
downloadmicronucleus-2297c1546d74a3cdeed5e3a3c064ca75f122ee4a.tar.gz
micronucleus-2297c1546d74a3cdeed5e3a3c064ca75f122ee4a.tar.bz2
micronucleus-2297c1546d74a3cdeed5e3a3c064ca75f122ee4a.zip
firmware: clean up configuration file
-rw-r--r--firmware/bootloaderconfig.h228
-rw-r--r--firmware/main.c13
2 files changed, 95 insertions, 146 deletions
diff --git a/firmware/bootloaderconfig.h b/firmware/bootloaderconfig.h
index ff4805f..d52fa8c 100644
--- a/firmware/bootloaderconfig.h
+++ b/firmware/bootloaderconfig.h
@@ -1,87 +1,28 @@
/* Name: bootloaderconfig.h
- * Project: USBaspLoader
- * Author: Christian Starkjohann
- * Creation Date: 2007-12-08
- * Tabsize: 4
- * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
- * Portions Copyright: (c) 2012 Louis Beaudoin
- * License: GNU GPL v2 (see License.txt)
- * This Revision: $Id: bootloaderconfig.h 729 2009-03-20 09:03:58Z cs $
+ * Micronucleus configuration file.
+ * This file (together with some settings in Makefile) configures the boot loader
+ * according to the hardware.
+ *
+ * Controller type: ATtiny 85
+ * Configuration: Digispark default configuration.
+ * Last Change: Feb 21,2014
+ *
+ * License: GNU GPL v2 (see License.txt
*/
#ifndef __bootloaderconfig_h_included__
#define __bootloaderconfig_h_included__
-/*
- * Bootloader defines
- */
-
-#ifndef __ASSEMBLER__
- typedef union {
- uint16_t w;
- uint8_t b[2];
- } uint16_union_t;
-#endif
-/*
-General Description:
-This file (together with some settings in Makefile) configures the boot loader
-according to the hardware.
-
-This file contains (besides the hardware configuration normally found in
-usbconfig.h) two functions or macros: bootLoaderInit() and
-bootLoaderCondition(). Whether you implement them as macros or as static
-inline functions is up to you, decide based on code size and convenience.
-
-bootLoaderInit() is called as one of the first actions after reset. It should
-be a minimum initialization of the hardware so that the boot loader condition
-can be read. This will usually consist of activating a pull-up resistor for an
-external jumper which selects boot loader mode.
-
-bootLoaderCondition() is called immediately after initialization and in each
-main loop iteration. If it returns TRUE, the boot loader will be active. If it
-returns FALSE, the boot loader jumps to address 0 (the loaded application)
-immediately.
-
-For compatibility with Thomas Fischl's avrusbboot, we also support the macro
-names BOOTLOADER_INIT and BOOTLOADER_CONDITION for this functionality. If
-these macros are defined, the boot loader uses them.
-*/
-
-#define TINY85_HARDWARE_CONFIG_1 1
-#define TINY85_HARDWARE_CONFIG_2 2
-
-/* ---------------------------- Hardware Config ---------------------------- */
-#define HARDWARE_CONFIG TINY85_HARDWARE_CONFIG_2
+/* ------------------------------------------------------------------------- */
+/* Hardware configuration. */
+/* Change this according to your CPU and USB configuration */
+/* ------------------------------------------------------------------------- */
#define USB_CFG_IOPORTNAME B
/* This is the port where the USB bus is connected. When you configure it to
* "B", the registers PORTB, PINB and DDRB will be used.
*/
-#ifndef __AVR_ATtiny85__
- # define USB_CFG_DMINUS_BIT 0
- /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
- * This may be any bit in the port.
- */
- #define USB_CFG_DPLUS_BIT 2
- /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
- * This may be any bit in the port. Please note that D+ must also be connected
- * to interrupt pin INT0!
- */
-#endif
-
-#if (defined __AVR_ATtiny85__) && (HARDWARE_CONFIG == TINY85_HARDWARE_CONFIG_1)
- #define USB_CFG_DMINUS_BIT 0
- /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
- * This may be any bit in the port.
- */
- #define USB_CFG_DPLUS_BIT 2
- /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
- * This may be any bit in the port, but must be configured as a pin change interrupt.
- */
-#endif
-
-#if (defined __AVR_ATtiny85__) && (HARDWARE_CONFIG == TINY85_HARDWARE_CONFIG_2)
#define USB_CFG_DMINUS_BIT 3
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
* This may be any bit in the port.
@@ -90,43 +31,22 @@ these macros are defined, the boot loader uses them.
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
* This may be any bit in the port, but must be configured as a pin change interrupt.
*/
-#endif
#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
-/* Clock rate of the AVR in kHz. Legal values are 12000, 16000 or 16500.
- * The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
- * deviation from the nominal frequency. All other rates require a precision
- * of 2000 ppm and thus a crystal!
- * Default if not specified: 12 MHz
+/* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000,
+ * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code
+ * require no crystal, they tolerate +/- 1% deviation from the nominal
+ * frequency. All other rates require a precision of 2000 ppm and thus a
+ * crystal!
+ * Since F_CPU should be defined to your actual clock rate anyway, you should
+ * not need to modify this setting.
*/
-/* ----------------------- Optional Hardware Config ------------------------ */
+/* ------------- Set up interrupt configuration (CPU specific) -------------- */
+/* The register names change quite a bit in the ATtiny family. Pay attention */
+/* to the manual. Note that the interrupt flag system is still used even though */
+/* interrupts are disabled. So this has to be configured correctly. */
-/* #define USB_CFG_PULLUP_IOPORTNAME D */
-/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
- * V+, you can connect and disconnect the device from firmware by calling
- * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
- * This constant defines the port on which the pullup resistor is connected.
- */
-/* #define USB_CFG_PULLUP_BIT 4 */
-/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
- * above) where the 1.5k pullup resistor is connected. See description
- * above for details.
- */
-
-/* ------------------------------------------------------------------------- */
-/* ---------------------- feature / code size options ---------------------- */
-/* ------------------------------------------------------------------------- */
-
-/* ----------------------- Optional MCU Description ------------------------ */
-
-/* tiny85 Architecture Specifics */
-#ifndef __AVR_ATtiny85__
-# error "uBoot is only designed for attiny85"
-#endif
-#define TINY85MODE
-
-/* ------------- Set up interrupt configuration (CPU specific) -------------- */
// setup interrupt for Pin Change for D+
#define USB_INTR_CFG PCMSK
@@ -138,18 +58,9 @@ these macros are defined, the boot loader uses them.
#define USB_INTR_PENDING_BIT PCIF
#define USB_INTR_VECTOR PCINT0_vect
-// Microcontroller vectortable entries in the flash
-#define RESET_VECTOR_OFFSET 0
-
-// number of bytes before the boot loader vectors to store the tiny application vector table
-#define TINYVECTOR_RESET_OFFSET 4
-#define TINYVECTOR_OSCCAL_OFFSET 6
-
-/* ------------------------------------------------------------------------ */
-// postscript are the few bytes at the end of programmable memory which store tinyVectors
-#define POSTSCRIPT_SIZE 6
-#define PROGMEM_SIZE (BOOTLOADER_ADDRESS - POSTSCRIPT_SIZE) /* max size of user program */
-
+/* ------------------------------------------------------------------------- */
+/* ---------------------- feature / code size options ---------------------- */
+/* Configure the behavior of the bootloader here */
/* ------------------------------------------------------------------------- */
/*
@@ -183,13 +94,17 @@ these macros are defined, the boot loader uses them.
*
*/
-#define ENTRYMODE ENTRY_EXT_RESET
+#define ENTRYMODE ENTRY_ALWAYS
#define JUMPER_PIN PB0
#define JUMPER_PORT PORTB
#define JUMPER_DDR DDRB
#define JUMPER_INP PINB
+/*
+ Internal implementation, don't change this unless you want to add an entrymode.
+*/
+
#define ENTRY_ALWAYS 1
#define ENTRY_WATCHDOG 2
#define ENTRY_EXT_RESET 3
@@ -237,7 +152,7 @@ these macros are defined, the boot loader uses them.
#define AUTO_EXIT_MS 5000
/*
- * Defines the setting of the RC-oscillator calibration after quitting the bootloader. (OSCCAL)
+ * Defines the setting of the RC-oscillator calibration after quitting the bootloader. (OSCCAL)
*
* OSCCAL_RESTORE Set this to '1' to revert to factory calibration, which is 16.0 MHZ +/-10%
* Adds ~14 bytes.
@@ -245,7 +160,8 @@ these macros are defined, the boot loader uses them.
* OSCCAL_16.5MHz Set this to '1' to use the same calibration as during program upload.
* This value is 16.5Mhz +/-1% as calibrated from the USB timing. Please note
* that only true if the ambient temperature does not change.
- * This is the default behaviour of the Digispark.
+ * This is the default behaviour of the original Digispark and is not recommended
+ * for use on devices other than the ATtiny85.
* Adds ~38 bytes.
*
* OSCCAL_HAVE_XTAL Set this to '1' if you have an external crystal oscillator. In this case no attempt
@@ -254,46 +170,76 @@ these macros are defined, the boot loader uses them.
*
* If both options are selected, OSCCAL_RESTORE takes precedence.
*
- * If no option is selected, OSCCAL will be left untouched and stay at either 16.0Mhz or 16.5Mhz depending
+ * If no option is selected, OSCCAL will be left untouched and stays at either 16.0 Mhz or 16.5 Mhz depending
* on whether the bootloader was activated. This will take the least memory. You can use this if your program
* comes with its own OSCCAL calibration or an external clock source is used.
*/
-#define OSCCAL_RESTORE 1
-#define OSCCAL_16_5MHz 0
+#define OSCCAL_RESTORE 0
+#define OSCCAL_16_5MHz 1
#define OSCCAL_HAVE_XTAL 0
/*
* Defines handling of an indicator LED while the bootloader is active.
*
- * LED_PRESENT Set this this to '1' to active all LED related code. If this is 0, all other
- * defines are ignored.
- * Adds 18 bytes depending on implementation.
+ * LED_MODE Define behavior of attached LED or suppress LED code.
+ *
+ * NONE Do not generate LED code (gains 18 bytes).
+ * ACTIVE_HIGH LED is on when output pin is high. This will toggle bettwen 1 and 0.
+ * ACTIVE_LOW LED is on when output pin is low. This will toggle between Z and 0.
*
* LED_DDR,LED_PORT,LED_PIN Where is your LED connected?
*
+ */
+
+#define LED_MODE ACTIVE_HIGH
+
+#define LED_DDR DDRB
+#define LED_PORT PORTB
+#define LED_PIN PB1
+
+/*
+ * This is the implementation of the LED code. Change the configuration above unless you want to
+ * change the led behavior
+ *
* LED_INIT Called once after bootloader entry
* LED_EXIT Called once during bootloader exit
* LED_MACRO Called in the main loop with the idle counter as parameter.
* Use to define pattern.
- */
+*/
-#define LED_PRESENT 1
+#define NONE 0
+#define ACTIVE_HIGH 1
+#define ACTIVE_LOW 2
+
+#if LED_MODE==ACTIVE_HIGH
+ #define LED_INIT(x) LED_DDR = _BV(LED_PIN);
+ #define LED_EXIT(x) {LED_DDR &=~_BV(LED_PIN);LED_PORT &=~_BV(LED_PIN);}
+ #define LED_MACRO(x) if ( x & 0x4c ) {LED_PORT&=~_BV(LED_PIN);} else {LED_PORT|=_BV(LED_PIN);}
+#elif LED_MODE==ACTIVE_LOW
+ #define LED_INIT(x) LED_PORT &=~_BV(LED_PIN);
+ #define LED_EXIT(x) LED_DDR &=~_BV(LED_PIN);
+ #define LED_MACRO(x) if ( x & 0x4c ) {LED_DDR&=~_BV(LED_PIN);} else {LED_DDR|=_BV(LED_PIN);}
+#elif LED_MODE==NONE
+ #define LED_INIT(x)
+ #define LED_EXIT(x)
+ #define LED_MACRO(x)
+#endif
-#define LED_DDR DDRB
-#define LED_PORT PORTB
-#define LED_PIN PB1
+/* --------------------------------------------------------------------------- */
+/* Micronucleus internal configuration. Do not change anything below this line */
+/* --------------------------------------------------------------------------- */
-#if LED_PRESENT
-// #define LED_INIT(x) LED_PORT &=~_BV(LED_PIN); // Use this with low active LED
- #define LED_INIT(x) LED_PORT = _BV(LED_PIN); // Use this with high active LED
- #define LED_EXIT(x) LED_DDR &=~_BV(LED_PIN);
- #define LED_MACRO(x) if ( x & 0x58 ) {LED_DDR&=~_BV(LED_PIN);} else {LED_DDR|=_BV(LED_PIN);}
-#else
- #define LED_INIT(x)
- #define LED_EXIT(x)
- #define LED_MACRO(x)
-#endif
-/* ------------------------------------------------------------------------- */
+// Microcontroller vectortable entries in the flash
+#define RESET_VECTOR_OFFSET 0
+
+// number of bytes before the boot loader vectors to store the tiny application vector table
+#define TINYVECTOR_RESET_OFFSET 4
+#define TINYVECTOR_OSCCAL_OFFSET 6
+
+/* ------------------------------------------------------------------------ */
+// postscript are the few bytes at the end of programmable memory which store tinyVectors
+#define POSTSCRIPT_SIZE 6
+#define PROGMEM_SIZE (BOOTLOADER_ADDRESS - POSTSCRIPT_SIZE) /* max size of user program */
#endif /* __bootloader_h_included__ */
diff --git a/firmware/main.c b/firmware/main.c
index cf61d3e..d60798a 100644
--- a/firmware/main.c
+++ b/firmware/main.c
@@ -50,6 +50,11 @@ PROGMEM const uint8_t configurationReply[4] = {
MICRONUCLEUS_WRITE_SLEEP
};
+ typedef union {
+ uint16_t w;
+ uint8_t b[2];
+ } uint16_union_t;
+
#if OSCCAL_RESTORE
register uint8_t osccal_default asm("r2");
#endif
@@ -59,7 +64,7 @@ register uint16_union_t idlePolls asm("r6"); // r6/r7 idlecounter
// command system schedules functions to run in the main loop
enum {
- cmd_local_nop=0, // also: get device info
+ cmd_local_nop=0,
cmd_device_info=0,
cmd_transfer_page=1,
cmd_erase_application=2,
@@ -216,8 +221,7 @@ static inline void leaveBootloader(void) {
bootLoaderExit();
- // _delay_ms(10); // Bus needs to see a few more SOFs before it can be disconnected
- usbDeviceDisconnect(); /* Disconnect micronucleus */
+ usbDeviceDisconnect(); /* Disconnect micronucleus */
USB_INTR_ENABLE = 0;
USB_INTR_CFG = 0; /* also reset config bits */
@@ -287,8 +291,7 @@ int main(void) {
eraseApplication();
// Attention: eraseApplication will set command=cmd_write_page!
if (command==cmd_write_page)
- writeFlashPage();
-
+ writeFlashPage();
if (command==cmd_exit) {
if (!fastctr) break; // Only exit after 5 ms timeout
} else {