{"id":16218951,"url":"https://github.com/arminjo/micronucleus-firmware","last_synced_at":"2025-04-06T11:09:53.170Z","repository":{"id":41472436,"uuid":"193170532","full_name":"ArminJo/micronucleus-firmware","owner":"ArminJo","description":"Fork for the firmware / digispark part of the micronucleus repository","archived":false,"fork":false,"pushed_at":"2024-11-07T08:46:58.000Z","size":28850,"stargazers_count":83,"open_issues_count":2,"forks_count":20,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-30T10:07:43.489Z","etag":null,"topics":["attiny85","bootloader","digispark","firmware","micronucleus"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArminJo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-21T23:25:46.000Z","updated_at":"2025-03-01T00:18:21.000Z","dependencies_parsed_at":"2024-12-24T11:15:55.602Z","dependency_job_id":"846a0f5a-b046-4778-a22e-ebe8800af726","html_url":"https://github.com/ArminJo/micronucleus-firmware","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArminJo%2Fmicronucleus-firmware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArminJo%2Fmicronucleus-firmware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArminJo%2Fmicronucleus-firmware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArminJo%2Fmicronucleus-firmware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArminJo","download_url":"https://codeload.github.com/ArminJo/micronucleus-firmware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247471521,"owners_count":20944158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["attiny85","bootloader","digispark","firmware","micronucleus"],"created_at":"2024-10-10T11:51:44.300Z","updated_at":"2025-04-06T11:09:53.154Z","avatar_url":"https://github.com/ArminJo.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align = center\u003e\n\n# Micronucleus USB Bootloader for ATtinies / Digisparks\nFork for the firmware / digispark part of the micronucleus repository.\n\n[![Badge License: GPLv3](https://img.shields.io/badge/License-GPLv2-brightgreen.svg)](https://www.gnu.org/licenses/gpl-2.0)\n \u0026nbsp; \u0026nbsp; \n[![Badge Version](https://img.shields.io/github/v/release/ArminJo/micronucleus-firmware?include_prereleases\u0026color=yellow\u0026logo=DocuSign\u0026logoColor=white)](https://github.com/ArminJo/micronucleus-firmware/releases/latest)\n \u0026nbsp; \u0026nbsp; \n[![Badge Commits since latest](https://img.shields.io/github/commits-since/ArminJo/micronucleus-firmware/latest?color=yellow)](https://github.com/ArminJo/micronucleus-firmware/commits/master)\n \u0026nbsp; \u0026nbsp; \n![Badge Hit Counter](https://visitor-badge.laobi.icu/badge?page_id=ArminJo_micronucleus-firmware)\n\u003cbr/\u003e\n\u003cbr/\u003e\n[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)\n\n\u003c/div\u003e\n\n#### If you find this library useful, please give it a star.\n\n\u0026#x1F30E; [Google Translate](https://translate.google.com/translate?sl=en\u0026u=https://github.com/ArminJo/micronucleus-firmware)\n\n\u003cbr/\u003e\n\nMicronucleus is a bootloader designed for AVR ATtiny microcontrollers with a minimal usb interface, cross platform libusb-based program upload tool, and a strong emphasis on bootloader compactness. To the authors knowledge this is, by far, the smallest USB bootloader for AVR ATtiny.\u003cbr/\u003e\n**The V2.0 release is a complete rewrite of the firmware and offers significant improvements over V1.x.**\u003cbr/\u003e\nDue to the many changes, also the upload tool had to be updated. The V2.0 upload tool is backwards compatible to the V1.X tool, though.\n\n![Digisparks](pictures/Digisparks.jpg)\n\n# Usage\nThe bootloader allows **uploading of new firmware via USB**. In its usual configuration it is invoked at device power or on reset and will identify to the host computer. If no communication is initiated by the host machine within a given time (default are 6 seconds), the bootloader will time out and enter the user program, if one is present.\u003cbr/\u003e\nFor proper timing, the command line tool should to be started on the host computer **before** the bootloader is invoked / the board attached.\u003cbr/\u003e\nThe bootloader resides in the same memory as the user program, since the ATtiny series does not support a protected bootloader section. Therefore, special care has to be taken not to overwrite the bootloader if the user program uses the self programming features. The bootloader will patch itself into the reset vector of the user program. **No other interrupt vectors are changed**.\u003cbr/\u003e\nPlease invoke the command line tool with \"micronucleus --help\" for a list of available options.\n\n\u003cbr/\u003e\n\n# Driver installation\nIf the Digispark board is not recognized by Microsoft Windows you must install the appropriate driver.\u003cbr/\u003e\nFor Windows you must install the **libusb driver** before you can program the board. Download it [here](https://github.com/digistump/DigistumpArduino/releases/download/1.6.7/Digistump.Drivers.zip), open it and run `InstallDrivers.exe`.\nClean Micronucleus devices without uploaded user program will not time out and allow sufficient time for proper driver installation. Linux and OS X do not require custom drivers.\n\n\u003cbr/\u003e\n\n# Updated configuration for Digispark boards\n**The new [ATTinyCore by Spence Konde](https://github.com/SpenceKonde/ATTinyCore) shrinks generated code size by 5 to 15 percent**. Just replace the old Digispark board manager URL **http://digistump.com/package_digistump_index.json** (e.g.in Arduino *File \u003e Preferences*) by the new  **http://drazzy.com/package_drazzy.com_index.json** and install the latest version.\n\u003cbr/\u003e\n\n\n# Update the bootloader to a new version\nTo **update** your old, flash consuming **bootloader**, you have 2 choices.\n1. Use the new Digistump board manager URL (see above), choose a bootloader with *Tools \u003e Micronucleus variant* and then burn it with *Tools \u003e Burn Bootloader*.\u003cbr/\u003e\n2. Run one of the Windows [scripts](https://github.com/ArminJo/micronucleus-firmware/tree/master/utils)\nlike e.g. the [1_Upgrade-t85_default.cmd](utils/1_Upgrade-t85_default.cmd). The internal mechanism is described [here](https://github.com/ArminJo/micronucleus-firmware/blob/master/firmware/upgrades/README.md).\n\n### If you want to burn the bootloader to an **ATtiny87** or **ATtiny167** with avrdude, you must use the [avrdude.config file](https://raw.githubusercontent.com/ArminJo/micronucleus-firmware/master/windows_exe/avrdude.conf) in [the windows_exe directory](https://github.com/ArminJo/micronucleus-firmware/tree/master/windows_exe) where [ATtiny87](https://github.com/ArminJo/micronucleus-firmware/blob/master/windows_exe/avrdude.conf#L15055) and [ATtiny167](https://github.com/ArminJo/micronucleus-firmware/blob/master/windows_exe/avrdude.conf#L15247) specifications are added.\n\n\u003cbr/\u003e\n\n# Fuse setting\nThe meaning of fuses can be seen with the [Engbedded Atmel AVR Fuse Calculator](https://www.engbedded.com/fusecalc/).\u003cbr/\u003e\nWindows helper scripts for setting fuses can be found [here](https://github.com/ArminJo/micronucleus-firmware/tree/master/utils).\n\nThe default fuses for a **Digispark** board are:\u003cbr/\u003e\n- ATtiny85 Lfuse: 0xE1 - (digispark default) 64 MHZ high speed PLL Clock + Startup 64 ms. CPU clock = 64 MHz / 4 = 16 MHz. CPU clock speed can later be reduced by core or user by using the `System Clock Prescaler` register.\n- ATtiny85 Hfuse: 0xDD - External Reset pin enabled (Pin5 not usable as I/O) + BOD 2.7 V + Enable Serial Program and Data Downloading.\n- ATtiny85 Efuse: 0xFE - self programming enabled.\n\nBOD enabled requires additional 20 \u0026micro;A in sleep state and therefore may be not desirable for low power battery applications. To disable BOD, use 0xDF as Hfuse.\n\nThe default fuses for a **Digispark Pro** board are:\u003cbr/\u003e\n- ATtiny167 Lfuse: 0xFF - External crystal osc. Frequency 8-16 MHz + Startup 65 ms. The Pro has a 16 MHz crystal.\n- ATtiny167 Hfuse: 0xDC - External Reset pin enabled + BOD 4.3Volt + Enable Serial Program and Data Downloading.\n- ATtiny167 Efuse: 0xFE - self programming enabled.\n\n# Flash the bootloader to a bricked device\nThis can only be done by means of a [High Voltage programmer](https://github.com/ArminJo/ATtiny-HighVoltageProgrammer_FuseEraser).\n\n# If nothing works...\nTry another **Cable**, try another **USB-Port**, try another **Board**, try another **Bootloader-variant**, try another **Computer**, try another **OS**.\u003cbr/\u003e\nIn this order.\n\n\u003cbr/\u003e\n\n# Configuration overview\nIf not otherwise noted, the OSCCAL value is calibrated (+/- 1%) after boot for all ATtiny85 configurations\n| Configuration | Free FLASH | Boot-\u003cbr/\u003eloader size | Non default config flags set |\n|-|-|-|-|\n| t85_agressive\u003cbr/\u003e\u003cbr/\u003eIt works for my Digispark boards without any problems :-) | 6778 | 1362 | [Do not provide calibrated OSCCAL, if no USB attached](/firmware/configuration/t85_agressive/bootloaderconfig.h#L220), [ENABLE_UNSAFE_OPTIMIZATIONS](#enable_unsafe_optimizations)\u003cbr/\u003eRelying on calibrated 16MHz internal clock stability, not using the 16.5 MHz USB driver version with integrated PLL. This causes the main memory saving. |\n|  |  |  |  |\n| t85_default | 6650 | 1514 | - |\n| t85_entry_on_powerOn | 6586 | 1550 | [ENTRY_POWER_ON](#entry_power_on-entry-condition), LED_MODE=ACTIVE_HIGH |\n| t85_entry_on_powerOn_\u003cbr/\u003efastExit | 6586 | 1572 | [ENTRY_POWER_ON](#entry_power_on-entry-condition), [FAST_EXIT_NO_USB_MS=300](#fast_exit_no_usb_ms-for-fast-bootloader-exit), LED_MODE=ACTIVE_HIGH |\n| \u003ca id=\"t85recommended\"/\u003e **t85_entry_on_powerOn_\u003cbr/\u003eactivePullup_fastExit**\u003cbr/\u003e[recommended configuration](#recommended-configuration) | 6586 | 1576 | [ENTRY_D_MINUS_PULLUP_ACTIVATED_AND_ENTRY_POWER_ON](#entry_d_minus_pullup_activated_and_entry_power_on-entry-condition), [FAST_EXIT_NO_USB_MS=300](#fast_exit_no_usb_ms-for-fast-bootloader-exit), LED_MODE=ACTIVE_HIGH |\n| t85_entry_on_powerOn_\u003cbr/\u003eactivePullup_fastExit_noLED| 6586 | 1558 | [ENTRY_D_MINUS_PULLUP_ACTIVATED_AND_ENTRY_POWER_ON](#entry_d_minus_pullup_activated_and_entry_power_on-entry-condition), [FAST_EXIT_NO_USB_MS=300](#fast_exit_no_usb_ms-for-fast-bootloader-exit) |\n| t85_entry_on_powerOn_\u003cbr/\u003epullupAt0 | 6650 | 1538 | [ENTRY_POWER_ON](#entry_power_on-entry-condition), USB_CFG_PULLUP_IOPORTNAME + USB_CFG_PULLUP_BIT |\n| t85_entry_on_reset_\u003cbr/\u003eactivePullup_fastExit | 6586 | 1576 | [ENTRY_D_MINUS_PULLUP_ACTIVATED_AND_ENTRY_EXT_RESET](#entry_d_minus_pullup_activated_and_entry_ext_reset-entry-condition), [FAST_EXIT_NO_USB_MS=300](#fast_exit_no_usb_ms-for-fast-bootloader-exit),\u003cbr/\u003eAUTO_EXIT_MS=15000 Bootloader timeout increased to 15 seconds (if connected to USB),\u003cbr/\u003eLED_MODE=ACTIVE_HIGH. |\n| t85_fastExit | 6586 | 1554 | [FAST_EXIT_NO_USB_MS=300](#fast_exit_no_usb_ms-for-fast-bootloader-exit), LED_MODE=ACTIVE_HIGH |\n|  |  |  |  |\n| t88_default | 6778 | 1350 | LED_MODE=ACTIVE_HIGH\u003cbr/\u003eFor 16 MHz quartz |\n| \u003ca id=\"t88recommended\"/\u003e**t88_entry_on_powerOn_\u003cbr/\u003eactivePullup_fastExit**\u003cbr/\u003e[recommended configuration](#recommended-configuration) | 6778 | 1394 |  [ENTRY_D_MINUS_PULLUP_ACTIVATED_AND_ENTRY_POWER_ON](#entry_d_minus_pullup_activated_and_entry_power_on-entry-condition), [FAST_EXIT_NO_USB_MS=300](#fast_exit_no_usb_ms-for-fast-bootloader-exit), LED_MODE=ACTIVE_HIGH\u003cbr/\u003eFor 16 MHz quartz |\n|  |  |  |  |\n| t167_default | 14970 | 1342 | - |\n| \u003ca id=\"t167recommended\"/\u003e**t167_entry_on_powerOn_\u003cbr/\u003eactivePullup_fastExit**\u003cbr/\u003e[recommended configuration](#recommended-configuration) | 14970 | 1406 | [ENTRY_D_MINUS_PULLUP_ACTIVATED_AND_ENTRY_POWER_ON](#entry_d_minus_pullup_activated_and_entry_power_on-entry-condition), [FAST_EXIT_NO_USB_MS=300](#fast_exit_no_usb_ms-for-fast-bootloader-exit), LED_MODE=ACTIVE_HIGH\u003cbr/\u003eFor 16 MHz quartz |\n| t167_entry_on_reset_\u003cbr/\u003eactivePullup_fastExit | 14970 | 1406 | [ENTRY_D_MINUS_PULLUP_ACTIVATED_AND_ENTRY_EXT_RESET](#entry_d_minus_pullup_activated_and_entry_ext_reset-entry-condition), [FAST_EXIT_NO_USB_MS=300](#fast_exit_no_usb_ms-for-fast-bootloader-exit), \u003cbr/\u003eAUTO_EXIT_MS=15000 Bootloader timeout increased to 15 seconds (if connected to USB),\u003cbr/\u003eLED_MODE=ACTIVE_HIGH.\u003cbr/\u003eFor 16 MHz quartz |\n|  |  |  |  |\n| t45_default | 2554 | 1514 |  |\n| t4313_default | 6714 | 1460 |  |\n| Nanite841 | 6586 | 1548 |  |\n| t841_default | 6650 | 1514 |  |\n| t84_default | 6650 | 1480 |  |\n|  |  |  |  |\n| m168p_extclock |  | 1498 |  |\n| m328p_extclock |  | 1498 |  |\n\n### Legend\n- [ENTRY_POWER_ON](#entry_power_on-entry-condition) - Only enter bootloader on power on, not on reset or brownout.\n- [ENTRY_EXT_RESET](#entry_ext_reset-entry-condition) - Only enter bootloader on reset, not on power up.\n- [ENTRY_D_MINUS_PULLUP_ACTIVATED](#entry_d_minus_pullup_activated_and_entry_power_on-entry-condition) - Only enter if pull-up connected and powered.\n- [FAST_EXIT_NO_USB_MS=300](#fast_exit_no_usb_ms-for-fast-bootloader-exit) - If not connected to USB (e.g. powered via VIN) the user program starts after 300 ms (+ initial 300 ms) -\u003e 600 ms. If connected to USB but no upload happens the user program starts after around 1.5 seconds.\n- [LED_MODE=ACTIVE_HIGH](https://github.com/ArminJo/micronucleus-firmware/blob/master/firmware/main.c#L527) - The built in LED flashes during the 5 seconds of the bootloader waiting for commands.\n\n\u003cbr/\u003e\n\n# Descripion of the configuration options\n\n## [`FAST_EXIT_NO_USB_MS`](/firmware/configuration/t85_fastExit/bootloaderconfig.h#L195) for fast bootloader exit\nIf the bootloader is entered, it requires minimum 300 ms to initialize USB connection (disconnect and reconnect). \n100 ms after this 300 ms initialization, the bootloader receives a reset.\u003cbr/\u003e\nThe 100 ms time to reset may depend on the type of host CPU etc., so I took 200 ms to be safe to detect a reset.\u003cbr/\u003e\nThis configuration waits for 200 ms after initialization for a reset and if no reset detected it exits the bootloader and starts the user program.\u003cbr/\u003e\nWith this configuration the **user program is started with a 500 ms delay after power up or reset** if no USB is attached, even if we do not specify a special entry condition.\u003cbr/\u003e\nIF USB is attached, we wait another 1200 ms (to cover slow hosts, otherwise 500 would be OK) after the reset for the host upload program (micronucleus.exe) to request the configuration information. If no upload program is detected, we start the user program.\n\n## [`ENTRY_POWER_ON`](/firmware/configuration/t85_entry_on_powerOn/bootloaderconfig.h#L108) entry condition\nThe `ENTRY_POWER_ON` configuration adds 18 bytes to the ATtiny85 default configuration.\u003cbr/\u003e\nThe content of the `MCUSR` is copied to the `GPIOR0` register to enable the user program to evaluate it and then cleared to prepare for next boot.\u003cbr/\u003e\nIn this configuration **a reset will immediately start your user program** without any delay.\n\n## [`ENTRY_EXT_RESET`](/firmware/configuration/t85_entry_on_reset_activePullup/bootloaderconfig.h#L122) entry condition\nThe ATtiny85 has the bug, that it sets the `External Reset Flag` also on power up. To guarantee a correct behavior for `ENTRY_EXT_RESET` condition, it is checked if only this flag is set **and** `MCUSR` is cleared before start of user program. The latter is done to avoid bricking the device by fogetting to reset the `PORF` flag in the user program.\u003cbr/\u003e\nFor ATtiny167 it is even worse, it sets the `External Reset Flag` and the `Brown-out Reset Flag` also on power up.\u003cbr/\u003e\nThe content of the `MCUSR` is copied to the `GPIOR0` register before clearing it. This enables the user program to evaluate its original content.\u003cbr/\u003e\n**ATTENTION! If the external reset pin is disabled, this entry mode will brick the board!**\n\n## [`ENTRY_D_MINUS_PULLUP_ACTIVATED_AND_ENTRY_POWER_ON`](/firmware/configuration/t85_entry_on_powerOn_activePullup_fastExit/bootloaderconfig.h#L138) entry condition\nActivate the bootloader only if the D- pin is high, i.e. a pull-up resistor is attached and powered **and** we have an `ENTRY_POWER_ON` condition (ref. described [above](#entry_power_on-entry-condition)).\u003cbr/\u003e\nUseful if the pull-up is powered by USB V+ and NOT ATtiny VCC to save power.\nIn this case often a schottky diode is connected between USB V+ and VCC (5V).\u003cbr/\u003e\nThe `ENTRY_D_MINUS_PULLUP_ACTIVATED_AND_ENTRY_POWER_ON` configuration adds 54 bytes to the ATtiny85 default configuration.\u003cbr/\u003e\nThe content of the `MCUSR` is copied to the `GPIOR0` register to enable the user program to evaluate it and then cleared to prepare for next boot.\u003cbr/\u003e\nIn this configuration **a power up with USB disconnected or a reset will immediately start your user program** without any delay.\u003cbr/\u003e\n\n## [`ENTRY_D_MINUS_PULLUP_ACTIVATED_AND_ENTRY_EXT_RESET`](/firmware/configuration/t85_entry_on_reset_activePullup/bootloaderconfig.h#L138) entry condition\nActivate the bootloader only if the D- pin is high, i.e. a pull-up resistor is attached and powered **and** we have an `ENTRY_EXT_RESET` condition.\u003cbr/\u003e\nUseful if the pull-up is powered by USB V+ and NOT ATtiny VCC to save power.\nIn this case often a schottky diode is connected between V* and VCC.\u003cbr/\u003e\nThe `ENTRY_D_MINUS_PULLUP_ACTIVATED_AND_ENTRY_EXT_RESET` configuration adds 54 bytes to the ATtiny85 default configuration.\u003cbr/\u003e\nThe content of the `MCUSR` is copied to the `GPIOR0` register to enable the user program to evaluate it and then cleared to prepare for next boot.\u003cbr/\u003e\nIn this configuration **a power up with USB disconnected or a reset will immediately start your user program** without any delay.\u003cbr/\u003e\n\n## [`ENABLE_UNSAFE_OPTIMIZATIONS`](/firmware/crt1.S#L99)\nThe bootloader reset vector is written by the host and not by the bootloader itself. In case of an disturbed communication the reset vector may be wrong -but I have never experienced it.\n\nYou have a slightly bigger chance to brick the bootloader, which reqires it to be reprogrammed by [avrdude](windows_exe) and an ISP or an Arduino as ISP. Command files for this can be found [here](/utils).\n\n## Recommendedconfiguration\nFor ATtiny85, ATtiny88 and ATtiny167 the recommended configuration is [t85_entry_on_powerOn_activePullup_fastExit.hex](#t85recommended), [t88_entry_on_powerOn_activePullup_fastExit.hex](#t88recommended) and [t167_entry_on_powerOn_activePullup_fastExit.hex](#t167recommended) respectively.\n\nThis configuration has the following features:\n- A hardware reset (e.g., Digispark P5 shorted to ground or brownout happened) will always immediately run the user program.\n- If no user program is loaded, the LED quickly flashes indefinitely.\n- At power-on, we distinguish 3 cases.\n1. The board is connected to an USB. In this case, the bootloader waits for the host program (micronucleus.exe) to upload a program and starts the user program after around 1.5 seconds timeout or after upload completion. The built-in LED flashes while the bootloader is waiting for user program upload and during the upload phase (`LED_MODE=ACTIVE_HIGH`).\n2. The board is **not** connected to an USB. In this case, the bootloader starts the already installed user program after 600 milliseconds (`FAST_EXIT_NO_USB_MS=300` means *Fast exit of bootloader after 300+300 ms*). The 600 ms are required to decide if there is an USB host attached or not.\n3. The **board pull-up resistor supply is modified to be USB-VCC and not CPU-VCC** and not connected to an USB **or the pull-up resistor is removed**. In this case, the pull-up is inactive and the bootloader immediately starts the installed user program (without startup delay, without hang-up and without affecting the internal LED at boot). This is referred to the `ENTRY_D_MINUS_PULLUP_ACTIVATED` part of the configuration flags. The builtin LED remains off in this case (`LED_MODE=ACTIVE_HIGH` has no effect here).\n\n### Hex files for these configuration are available in the [releases](/firmware/releases) and [upgrades](/firmware/upgrades) folders.\n\n## Create your own configuration\nYou can easily create your own configuration by adding a new *firmware/configuration* directory and adjusting *bootloaderconfig.h* and *Makefile.inc*. Before you run the *firmware/make_all.cmd* script, check the arduino directory path in the [`firmware/SetPath.cmd`](https://github.com/ArminJo/micronucleus-firmware/blob/master/utils/SetPath.cmd#L1) file.\u003cbr/\u003e\nIf changes to the configuration lead to an increase in bootloader size, i.e. you see errors like `address 0x2026 of main.bin section '.text' is not within region 'text'`, it may be necessary to change/decrease the bootloader start address as described in the next section and in the *Makefile.inc*.\u003cbr/\u003e\nFeel free to supply a pull request, if you added and tested a previously unsupported device.\n\n\u003cbr/\u003e\n\n# [Compile instructions for the bootloader](firmware#compiling-the-bootloader-firmware)\n\n## Computing the bootloader start address\nThe actual memory footprint for each configuration can be found in the file [*firmware/build.log*](firmware/build.log).\u003cbr/\u003e\nBytes used by the mironucleus bootloader can be computed by taking the data size value in *build.log*, \nrounding it up to the next multiple of the page size which is e.g. 64 bytes for ATtiny85 and 128 bytes for ATtiny176.\u003cbr/\u003e\nSubtracting this (+ 6 byte for postscript) from the total amount of memory will result in the free bytes numbers.\n- Postscript are the few bytes at the end of programmable memory which store tinyVectors.\n\nE.g. for *t85_default.hex* with the new compiler we get 1548 as data size. The next multiple of 64 is 1600 (25 * 64) =\u003e (8192 - (1600 + 6)) = **6586 bytes are free**.\u003cbr/\u003e\nIn this case we have 52 bytes left for configuration extensions before using another 64 byte page.\u003cbr/\u003e\nFor data size from 1470 up to 1536 the address is 1A00 (6650 free), for 1538 to 1600 it is 19C0 (6586 free), for 1602 to 1664 it is 1980 (6522 free).\n\nFor *t167_default.hex* (as well as for the other t167 configurations) with the new compiler we get 1436 as data size. The next multiple of 128 is 1536 (12 * 128) =\u003e (16384 - (1536 + 6)) = 14842 bytes are free.\u003cbr/\u003e\nFor data from 1281 to 1408 the address is 3A80, for size from 1409 to 1536 the address is 3A00\n\n\u003cbr/\u003e\n\n# Bootloader memory comparison of different releases for t85_default.hex\n- V1.6  6012 bytes free\n- V1.11 6330 bytes free\n- V2.3  6522 bytes free\n- V2.04 6522 bytes free\n- [V2.5](firmware/releases/t85_default.hex) **6650** bytes free\n\n\u003cbr/\u003e\n\n# USB device manager entry / disconnect from USB\nTo avoid periodically disconnect-\u003econnect if no sketch is loaded and to avoid an unknown USB Device (Device Descriptor Request Failed) entry in device manager when entering user program, **the bootloader finishes without an active disconnect from USB**.\u003cbr/\u003e\nThis means that you still can see a libusb-win32 decive / Digispark Bootloader in the Device manager, even when it is not alive, since your program has taken over the control of the CPU.\u003cbr/\u003e\nThis behavior is compatible to the old v1 micronucleus versions, which also do not disconnect from the host.\n**You can avoid this by actively disconnecting from the host by pulling the D- line to low for up to 300 milliseconds.**\u003cbr/\u003e\nE.g a short beep at startup with tone(3, 2000, 200) will pull the D- line low and keep the module disconnected.\n\n\u003cbr/\u003e\n\n# Reducing current of digispark bords for low power applications\n\n## Measured Digispark (ATtiny85 fast 64 MHz PLL clock) supply current\n| Current | Voltage | Clock | Configuration | \n|-:|-:|-:|:-:|\n| **20 mA** | 5 V | 16.5 MHz | Standard Hardware |\n| 13 mA   | **3.8 V** | 16.5 MHz | \" |\n| 16 mA   | 5 V |    8 MHz | \" |\n| 11 mA   | 5 V |    1 MHz | \" |\n| 6 mA    | 3.8 V |  1 MHz | \" |\n| 4.5 mA  | 3 V |  1 MHz | \" |\n| **7.7 mA** | 5 V | 1 MHz | SLEEP_MODE_PWR_DOWN + ADC disabled |\n| 17 mA   | 5 V | 16.5 MHz | Voltage regulator removed |\n| 14 mA   | 5 V | 16.5 MHz | Power LED and voltage regulator removed |\n| 9.3 mA  | 5 V |    8 MHz | \" |\n| 4.3 mA  | 5 V |    1 MHz | \" |\n| **14.3 mA** | 5 V | 16.5 MHz | **Power LED, voltage regulator removed + USB D- pull-up reconnected and powered directly at VCC** (loop with delay)|\n| 9.5 mA  | **3.8 V** | 16.5 MHz | \" |\n| 8.3 mA  | 5 V |    8 MHz | \" |\n| 7.5 mA  | 5 V |    8 MHz | All Hardware changes + empty loop + Timer and ADC disabled |\n| **3.0 mA** | 5 V | 1 MHz | **All Hardware changes (loop with delay)** |\n| 2.6 mA    | **3.8 V** | 1 MHz | \" |\n| 2.9 mA    | 5 V |  1 MHz | All Hardware changes + empty loop |\n| 2.4 mA    | 5 V |  1 MHz | All Hardware changes + empty loop + Timer and ADC disabled |\n| 230 \u0026micro;A    | 5 V |  1 MHz | All Hardware changes + SLEEP_MODE_PWR_DOWN |\n| **27 \u0026micro;A** | 5 V |  1 MHz | All Hardware changes + SLEEP_MODE_PWR_DOWN + ADC disabled + Watchdog enabled |\n| 25 \u0026micro;A     | 3 V |  1 MHz | \" |\n|  **7 \u0026micro;A** | 5 V |  1 MHz | All Hardware changes + **SLEEP_MODE_PWR_DOWN + ADC disabled + BOD disabled** + Watchdog enabled |\n| 5.5 \u0026micro;A   | 3.8 V | 1 MHz | \" The Watchdog draws around 5 \u0026micro;A |\n\nBOD can only be disabled by setting fuses via ISP programmer](https://www.google.de/search?q=arduino+as+isp) and a connecting adapter.\nFor reprogramming the fuses, you can use [this script](https://github.com/ArminJo/micronucleus-firmware/blob/master/utils/Write%2085%20Fuses%20E1%20DF%20FE%20-%20Digispark%20default%20without%20BOD%20and%20Pin5.cmd).\u003cbr/\u003e\n\n## Current per device @ 5 volt\n| Current | Device |\n| -:|:-:|\n|   3 mA | Voltage regulator (1.5 mA at 3.8 V)|\n|   2 mA | Power LED |\n|   1 mA | USB D- pull-up |\n| 14.3 mA | CPU + timer @16.5 MHz |\n|  14 mA | CPU + timer @16 MHz |\n|   8 mA | CPU + timer @8 MHz |\n|   3 mA | CPU + timer @1 MHz |\n|  20 \u0026micro;A | BOD |\n| 212 \u0026micro;A | ADC |\n|   5 \u0026micro;A | Watchdog |\n\nWith fast PLL Clock and standard fuses, the **start-up time from sleep is around 64ms and requires 2/3 of regular CPU power**!\u003cbr/\u003e\nIf we use the longest sleep time of 8 seconds and an empty loop, this result in an **average current consumption of 23 \u0026micro;A** (1 year with a 200 mAh button cell 2032).\u003cbr/\u003e\nThe start-up time from sleep can be reduced (at own risk of unstable clock) to 5 ms using [this fuse settings](https://github.com/ArminJo/micronucleus-firmware/blob/master/utils/Write%2085%20Fuses%20C1%20DF%20FE%20-%20Digispark%20default%20without%20BOD%20and%20Pin5%20and%20fast%20startup.cmd).\nThis results in an average current consumption of **9 \u0026micro;A** (2.5 years with a 200 mAh button cell 2032).\u003cbr/\u003e\nThis startup time can even be reduced to 6 clock cycles by [changing fuses to use the internal 8Mhz clock](https://github.com/ArminJo/micronucleus-firmware/blob/master/utils/Write%2085%20Fuses%20E2%20DF%20FF%20-%20ISP%20Mode%20%3D%208MHz%20without%20BOD%20and%20Pin5.cmd), but this **disables the possibility to program the Digispark board via USB** and and on the other hand removes the need for a bootloader and therefore leaves the whole memory for your program.\n\n## Modifying the board\nHere is an [Instructable](https://www.instructables.com/Reducing-Battery-Power-Consumption-for-Digispark-A/) covering the topic.\n### Disabling the power LED\nBreak the copper wire that connects the power LED to the diode with a knife or remove / disable the 102 resistor.\n### Removing the VIN voltage regulator\nFirst, lift the outer pins with the help of a solder iron and a pin. Then solder the big connector and remove the regulator. For small regulators, use much solder and heat up all 3 pins together, then remove it.\n### Disconnecting the USB D- Pullup resistor (marked 152) from 5 volt (VCC)\nBreak the copper wire on the side of the resistor that points to the ATtiny.\u003cbr/\u003e\n**This disables the USB interface** and in turn the possibility to program the Digispark board via USB. To **enable it again**, but still save power, **connect the resistor (marked 152) directly to the USB V+** that is easily available at the outer side of the schottky diode.\u003cbr/\u003e\nThe diode and its correct sides can be found by using a continuity tester. One side of this diode is connected to pin 8 of the ATtiny (VCC) and Digispark 5V. The other side is connected to the USB V+.\u003cbr/\u003e\nNow the USB pull-up resistor is only activated if the Digispark board is connected to USB e.g. during programming.\n\n![Final power reduction](https://github.com/ArminJo/Arduino-OpenWindowAlarm/blob/master/pictures/Final-Version-Detail_annotated.jpg)\n\n## Another example for current reduction\n\n\u003cimg src=\"pictures/modding_front.png\" width=\"300\" title=\"Modding front\"/\u003e\u003cimg src=\"pictures/modding_back.png\" width=\"300\" title=\"Modding back\"/\u003e\n\n### Moddings:\n\n- Connect A to C (A is the right terminal of the 1kohm resistor; C is USB V+)\n- Cut B with a cutter (power supply rail interconnecting the 1kohm resistor with 5V)\n- Connect C with D (C is USB V+, D is the left terminal of the green LED resistor)\n- Remove the 78M05 linear regulator G\n- Connect E with F (short the two input/output terminals of the removed linear regulator)\n- Cut H with a cutter (power supply rail connecting 5V with the output of the linear regulator)\n\nNow we have 3 power supply variants:\n1 Use the USB to upload a sketch (the green LED is lighted) - Disconnect 5V and VIN.\n2 Use 5V - GND to test the device with D- pull-up (the green LED is lighted) - Disconnect USB and VIN.\n3 Use VIN - GND for standard operation in low current consumption. The power supply can be 3V to 5V (the green LED can be used as debug output of PB3). - Disconnect USB and 5V.\n\n\u003cbr/\u003e\n\n# Pin layouts\n### ATtiny85 on Digispark\n\n```\n                       +-\\/-+\n RESET/ADC0 (D5) PB5  1|    |8  VCC\n  USB- ADC3 (D3) PB3  2|    |7  PB2 (D2) INT0/ADC1 - default TX Debug output for ATtinySerialOut\n  USB+ ADC2 (D4) PB4  3|    |6  PB1 (D1) MISO/DO/AIN1/OC0B/OC1A/PCINT1 - (Digispark) LED\n                 GND  4|    |5  PB0 (D0) OC0A/AIN0\n                       +----+\n  USB+ and USB- are each connected to a 3.3 volt Zener to GND and with a 68 ohm series resistor to the ATtiny pin.\n  On boards with a micro USB connector, the series resistor is 22 ohm instead of 68 ohm.\n  USB- has a 1.5k pull-up resistor to indicate a low-speed device.  \n  USB+ and USB- are each terminated on the host side with 15k to 25k pull-down resistors.\n```\n\n### ATtiny167 on Digispark pro\nDigital Pin numbers in parenthesis are for ATTinyCore library\n\n```\n                  +-\\/-+\nRX   6 (D0) PA0  1|    |20  PB0 (D8)  0 OC1AU\nTX   7 (D1) PA1  2|    |19  PB1 (D9)  1 OC1BU - (Digispark) LED\n     8 (D2) PA2  3|    |18  PB2 (D10) 2 OC1AV\nINT1 9 (D3) PA3  4|    |17  PB3 (D11) 4 OC1BV USB-\n           AVCC  5|    |16  GND\n           AGND  6|    |15  VCC\n    10 (D4) PA4  7|    |14  PB4 (D12)   XTAL1\n    11 (D5) PA5  8|    |13  PB5 (D13)   XTAL2\n    12 (D6) PA6  9|    |12  PB6 (D14) 3 INT0  USB+\n     5 (D7) PA7 10|    |11  PB7 (D15)   RESET\n                  +----+\n  USB+ and USB- are each connected to a 3.3 volt Zener to GND and with a 51 ohm series resistor to the ATtiny pin.\n  USB- has a 1k5 pull-up resistor to indicate a low-speed device.\n  USB+ and USB- are each terminated on the host side with 15k to 25k pull-down resistors.\n\n```\n\n### MH-ET LIVE Tiny88 (16.0MHz) board\nDigital Pin numbers in parenthesis are for ATTinyCore library\n\n```\n                        USB\n                      +-\\__/-+\n               PA2  15|      |14  PB7\n               PA3  16|      |13  PB5 SCK\n           D17 PA0  A6|      |12  PB4 MISO\n           D18 PA1  A7|      |11  PB3 MOSI\n     (D17) D19 PC0  A0|      |10  PB2 OC1B/PWM SS\n     (D18) D20 PC1  A1|      |9   PB1 OC1A/PWM\n     (D19) D21 PC2  A2|      |8   PB0\n     (D20) D22 PC3  A3|      |7   PD7 RX\nSDA  (D21) D23 PC4  A4|      |6   PD6 TX\nSCL  (D22) D24 PC5  A5|      |5   PD5\n     (D23)     PC7  25|      |4   PD4\nRESET          PC6 RST|      |3   PD3 INT1\nLED            PD0   0|      |5V\nUSB-           PD1   1|      |GND\nUSB+  INT0     PD2   2|      |VIN\n                      +------+\n  USB+ and USB- are each connected to a 3.3 volt Zener to GND and with a 68 ohm series resistor to the ATtiny pin.\n  USB- has a 1k0 pullup resistor to indicate a low-speed device.\n  USB+ and USB- are each terminated on the host side with 15k to 25k pull-down resistors.\n\n  Pins not available: PB6 is CLOCK_IN, PC7 is 25\n\n```\n\n\u003cbr/\u003e\n\n# Revision History\n### Version 2.6.0\n- Added compile flag `STORE_CONFIGURATION_REPLY_IN_RAM`.\n- Added 2 bytes USB config data for Bootloader feature flags and application version.\n- Added `--info` flag for micronucleus executable.\n\n### Version 2.5.2\n- Swapped D+ and D- again and set `OSCCAL_HAVE_XTAL`for t88 to support MH-ET LIVE Tiny88 boards.\n- Renamed the different pre-built configurations.\n- Saved 22 bytes by changing OSCCAL calibration function to Nerdralph's version.\n- Removed `START_WITHOUT_PULLUP` and extended `FAST_EXIT_NO_USB_MS`.\n- Executables are now included.\n\n### Version 2.5.1\n- Saved 28 bytes by `#define USB_CFG_DESCR_PROPS_STRINGS 1`. See #10, thanks to [nerdralph](https://github.com/nerdralph).\n- Use 12 byted by re enabling push and pop of Y register in *usbdrvasm165.inc*. See #11.\n- Swapped D+ and D- for t88 to support MH-ET LIVE Tiny88 boards.\n\n### Version 2.5\n- Saved 2 bytes by removing for loop at leaveBootloader().\n- Saved 2 bytes by defining __DELAY_BACKWARD_COMPATIBLE__ for _delay_ms().\n- Saved 22 bytes by converting USB_handler in *usbdrvasm165.inc* from ISR with pushes to a plain function.\n- Saved 2 bytes by improving small version of usbCrc16 in *usbdrvasm.S*.\n- Saved 4 bytes by inlining usbCrc16 in *usbdrvasm.S*.\n- Renamed `AUTO_EXIT_NO_USB_MS` to `FAST_EXIT_NO_USB_MS` and implemented it.\n- New configurations using `FAST_EXIT_NO_USB_MS` set to 300 ms.\n- Light refactoring and added documentation.\n- No USB disconnect at bootloader exit. This avoids \"Unknown USB Device\" entry in device manager.\n- Gained 128 byte for `t167_default` configuration.\n\n- Fixed wrong condition for t85 `ENTRYMODE==ENTRY_EXT_RESET`.\n- ATtiny167 support with MCUSR bug/problem at `ENTRY_EXT_RESET` workaround.\n- `MCUSR` handling improved.\n- no_pullup targets for low energy applications forever loop fixed.\n- `USB_CFG_PULLUP_IOPORTNAME` disconnect bug fixed.\n- New `ENTRY_POWER_ON` configuration switch, which enables the program to start immediately after a reset.\n- Copy `MCUSR` to `GPIOR0` and clear it on exit for all `ENTRY_POWER_ON` and `ENTRY_EXT_RESET` configurations.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farminjo%2Fmicronucleus-firmware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farminjo%2Fmicronucleus-firmware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farminjo%2Fmicronucleus-firmware/lists"}