Skip to content

Instantly share code, notes, and snippets.

@nickyonge
Last active March 12, 2024 19:15
Show Gist options
  • Save nickyonge/69bf8889f9c26f0a6661cdb72e56620c to your computer and use it in GitHub Desktop.
Save nickyonge/69bf8889f9c26f0a6661cdb72e56620c to your computer and use it in GitHub Desktop.
WIP: ATtiny Platform.io INI Template
; PLATFORM.IO .ini TEMPLATE FOR ATTINYx4 ICs
; by Nick Yonge
; https://gist.github.com/nickyonge/69bf8889f9c26f0a6661cdb72e56620c
;
; Default values are all preselected, with commented-out sections for common modifications (eg clock customization)
; Look for the headlines, and just uncomment the sections as needed!
;
; Useful Resources:
; ATtiny 24/44/84 Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/doc8006.pdf
; confFUSE AVR Fuse Calculator: https://www.engbedded.com/conffuse/
; Eleccelerator AVR Fuse calculator: https://bit.ly/3D2agRL (Note: confFUSE is more recommended, but I find Eleccelerator's better documented, if a bit clunkier)
; SpenceKonde ATTinyCore Board Definitions (attinyx4): https://bit.ly/3iVeJ1L
; "All You Need To Know About AVR Fuses" by EMBEDDS: https://embedds.com/all-you-need-to-know-about-avr-fuses/
; "How to Use AVR Fuses – and Understanding What They Do" by Crash-Bang: http://www.crash-bang.com/programme-avr-fuse/
[env:attiny84]
platform = atmelavr
; ----------------------------------------- BOARD SELECTION - Uncomment the board you're using (default 84)
board = attiny84
;board = attiny44
;board = attiny24
framework = arduino
upload_protocol = custom
; ----------------------------------------- PORT SELECTION
;upload_port = COM5 ; CHANGE THIS AS NEEDED. Leave commented to use VSCode Auto selection
;
;
upload_speed = 19200
; NOTE: Upload flags sourced from platform.io's AVR platform docs, for "Arduino as ISP", https://docs.platformio.org/en/latest/platforms/atmelavr.html
upload_flags =
-C
${platformio.packages_dir}/tool-avrdude/avrdude.conf
-p
$BOARD_MCU
-P
$UPLOAD_PORT
-b
$UPLOAD_SPEED
-c
stk500v1
; pass in above defined upload flags and flash source code
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i
;
; ----------------------------------------- LOCK BITS SELECTION - Uncomment the security selection you want! (Default 0xFF)
;
-U lock:w:0xFF:m ; Unlocked / rewriteable (eg, rewriting, testing)
;-U lock:w:0xFE:m ; Programming disabled (eg, QA)
;-U lock:w:0xFC:m ; Programming AND verification disabled (eg, consumer distribution)
;
; ----------------------------------------- FUSE SETUP (Clock speed, brownout detection, self-programming)
;
; ----------------------------------------- - CLOCK SOURCE (External or Internal, only choose one code block)
; - INTERNAL CLOCK (Default)
build_flags = -DCLOCK_SOURCE=0
; - EXTERNAL CLOCK
;build_flags = -DCLOCK_SOURCE=1
; ----------------------------------------- - CLOCK FUSE SETUP (Code block must match External/Internal source choice)
; - INTERNAL CLOCK SELECTIONS
;board_fuses.lfuse = 0x62 ; 1MHz Internal (Default)
board_fuses.lfuse = 0xE2 ; 8MHz Internal
; - EXTERNAL CLOCK SELECTIONS
; - - CRYSTAL XTAL (16K CK Startup Delay, 14 CK + 65ms Reset Delay) (generally recommended external)
;board_fuses.lfuse = 0xFF ; 8MHz or GREATER (16, 20, etc), Crystal
;board_fuses.lfuse = 0xFD ; 3-8MHz, Crystal
;board_fuses.lfuse = 0xFB ; 0.9-3MHz, Crystal
;board_fuses.lfuse = 0xF9 ; 0.9MHz or LESS, Crystal
; - - CERAMIC XTAL (1K CK Startup Delay, 14 CK + 65ms Reset Delay)
;board_fuses.lfuse = 0xCF ; 8MHz or GREATER (16, 20, etc), Ceramic
;board_fuses.lfuse = 0xCD ; 3-8MHz, Ceramic
;board_fuses.lfuse = 0xCB ; 0.9-3MHz, Ceramic
;board_fuses.lfuse = 0xC9 ; 0.9MHz or LESS, Ceramic
; - - CRYSTAL XTAL, (16K CK Startup Delay, No Reset Delay)*
;board_fuses.lfuse = 0xDF ; 8MHz or GREATER (16, 20, etc), Crystal, No Reset Delay
;board_fuses.lfuse = 0xDD ; 3-8MHz, Crystal, No Reset Delay
;board_fuses.lfuse = 0xDB ; 0.9-3MHz, Crystal, No Reset Delay
;board_fuses.lfuse = 0xD9 ; 0.9MHz or LESS, Crystal, No Reset Delay
; - - CERAMIC XTAL, (1K CK Startup Delay, No Reset Delay)*
;board_fuses.lfuse = 0xEE ; 8MHz or GREATER (16, 20, etc), Ceramic, No Reset Delay
;board_fuses.lfuse = 0xEC ; 3-8MHz, Ceramic, No Reset Delay
;board_fuses.lfuse = 0xEA ; 0.9-3MHz, Ceramic, No Reset Delay
;board_fuses.lfuse = 0xE8 ; 0.9MHz or LESS, Ceramic, No Reset Delay
;
; *: No Reset Delay means there is no induced startup delay on reset. This is optional,
; but recommended by the datasheet IF you ARE using Brownout Detection (BOD).
; For more info, see datasheet link, p29, table 6-10 (as of time of this commit)
;
; ----------------------------------------- CLOCK SPEED SELECTION - Note: these are all common presets, but you can
; easily customize it by entering the value in Hertz
; - - 1 MHz (Default)
;board_build.f_cpu = 1000000L ; 1 MHz (Default, Internal or External)
;board_build.f_cpu = 4000000L ; 4 MHz (External Only)
;board_build.f_cpu = 7372800L ; 7.372 MHz (External Only)
;board_build.f_cpu = 6000000L ; 6 MHz (External Only)
board_build.f_cpu = 8000000L ; 8 MHz (Internal or External)
;board_build.f_cpu = 9216000L ; 9.216 MHz (External Only)
;board_build.f_cpu = 11000000L ; 11.0592 MHz (External Only)
;board_build.f_cpu = 12000000L ; 12 MHz (External Only)
;board_build.f_cpu = 14745600L ; 14.7456 MHz (External Only)
;board_build.f_cpu = 16000000L ; 16 MHz (External Only)
;board_build.f_cpu = 20000000L ; 20 MHz (External Only)
;board_build.f_cpu = 24000000L ; 24 MHz (External Only)
;
; ----------------------------------------- BROWNOUT DETECTION (BOD) - Only settings for common Vin values are here
board_fuses.hfuse = 0xDC ; 4.3V BOD (Preset default, used for 5Vin, highest possible)
;board_fuses.hfuse = 0xDD ; 2/7V BOD (Used for 3/3v3 Vin)
;board_fuses.hfuse = 0xDD ; BOD Disabled (Factory default. Should generally avoid, and you should DEFINITELY use BOD if you're using EEPROM)
;
; ------ NOTE re: HIGH FUSE*: The hfuse byte doesn't just control BOD. In total, it controls:
; - BOD, Brownout detection (above). Bits 2/1/0. Default disabled. For additional BOD settings, see datasheet link, p179, table 20-7 (as of time of this commit)
; - EESAVE, EEPROM Preservation. Bit 3. Default disabled. Preserves EEPROM memory when chip gets erased/reprogrammed. Should generally leave it unless you're saving setup values during development. (Startup/reset does not erase EEPROM, regardless of this fuse.)
; - WDTON, Watchdog Timer Always On. Default disabled. Discouraged unless you're using the watchdog timer and know what you're doing. Will periodically reset your chip unless you tell it not to.
; - SPIEN**, SPI Enable. Default enabled. Disables serial programming. Don't set unless you have an HV programmer handy and know what you're doing. If you're trying to secure your chip, use lock bits (above).
; - DWEN**, DebugWIRE Enable. Default disabled. Used for debugging, esp for fuses. See datasheet for more info.
; - RSTDSBL**, Reset Disable. Default disabled. Disables reset function, turning the RESET pin into a general I/O pin. Generally discouraged unless you REALLY need that pin.
; If you want to modify any of those parameters, your hfuse value will differ. It's recommended you use
;
; *: Fuse High Byte is described in detail in the datasheet link, p160, table 19-4 (as of time of this commit). Other fuses are listed there too.
; **: Cannot be modified by ISP. Can be modified from HV (High-Voltage) programmer or while in DebugWire mode.
;
; TODO: SELF-PROGRAMMING COMMENTS
;
board_fuses.efuse = 0xFF ; extended fuse, FF for SELFPRGEN (self programmng) disabled, FE for enabled,
;
; library dependencies
lib_deps =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment