Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Digispark ATtiny85 setup with command line interface. Simple LED blinking example to test frequency and timing.

License

NotificationsYou must be signed in to change notification settings

aabbtree77/digispark-attiny85-command-line

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCS Digistump Digispark Attiny 85 is the cheapest complete MCU board whose (five-euro) price is close to that of the MCU chip (Attiny 85) alone.

gThumb

The problem is that its programming (flashing)is not as trivial as it should be. Most tutorials involve theArduino IDE,but those IDE-centered workflows depend on the IDE version number and are not flexible and portable enough. Here are some notes about programming this board directly from the Ubuntu 22.04 command line terminal.

Install gcc-avr tool chain:

sudo apt-get install gcc build-essential gcc-avr binutils-avr avr-libc gdb-avr avrdude libusb-dev

Install micronucleus:

git clone https://github.com/micronucleus/micronucleus.gitcd micronucleus/commandlinemake

Add this line to .bashrc (note your path to micronucleus, mine is /home/tokyo/):

export PATH=$PATH:/home/tokyo/micronucleus/commandline

Workflow:

Once (with USBasp or ISP):

Flash Micronucleus bootloader t85_default.hex, and set the correct fuse values. See Updating Micronucleus for details.

This establishes the board as a "Digispark".

Afterwards:

Use Micronucleus over USB to upload code:

make cleanmakemake install

or simply upload main.hex if you have obtained it by other means:

sudo -E env "PATH=$PATH" micronucleus --run main.hex

The fuses remain as they were (you don’t touch them again).

In the included Makefile,make install runs sudo with the environment PATH borrowed from the user spaceso that the micronucleus program becomes visible.

The promt issues

>Please plugin the device ...

and one then needs to unplug and plug the board to USB port again before succeeding:

>Device is found!connecting: 33% complete>Device has firmware version 1.6>Available spacefor user applications: 6012 bytes>Suggested sleeptime between sending pages: 8ms>Whole page count: 94  page size: 64>Erasefunctionsleep duration: 752msparsing: 50% complete>Erasing the memory ...erasing: 66% complete>Starting to upload ...writing: 83% complete>Starting the user app ...running: 100% complete>> Micronucleus done. Thank you!

A sample code is included in this folder.

Executelsusb to check if the board is still visible on the USB port. If not, update/upload Micronucleus as shown below.

gThumb

Updating Micronucleus

One problem with this board is that in order to update Micronucleus (bootloader), one still needs to wire an external ISP programmer such as USBasp to the corresponding pins MISO, MOSI, SCK and RESET. In order to update it:

cd micronucleus-master/firmware/releases

avrdude -P usb -c usbasp -p t85 -U flash:w:t85_default.hex

avrdude -P usb -c usbasp -p t85 -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xfe:m

This particular low fuse bit setting uses an internal 8 MHz oscillator with a division by 8 yielding F_CPU = 1000000u.

The above does not work.Micronucleus expects 16.5 MHz. Otherwise the USB signals are too slow and the USB device will not be detected.

Instead:

cd micronucleus-master/firmware/releasesavrdude -c usbasp -p t85 \  -U flash:w:t85_default.hex:i \  -U lfuse:w:0xe1:m \  -U hfuse:w:0xdd:m \  -U efuse:w:0xfe:m

Micronucleus is tied to specific fuses to run USB:

lfuse = 0xE1 → enable 16.5 MHz PLL clock, disable CKDIV8.

hfuse = 0xDD → keep reset pin enabled, set boot size properly.

efuse = 0xFE → default extended fuse.

Always set the main clock to 16.5 MHz.

Fuse Bits

Fuse bits (fuses) = stored in a dedicated NVM area in the chip. Persistent w.r.t. resets and power on/off until explicitly changed. They also determine the CPU clock.#define F_CPU 16500000UL inside code/firmware only tells the compiler what we think the clock speed is. Has no effect on hardware, but affects certain functions such as_delay_ms().

One should be extremely careful with the fuse bits. There are many ways to brick the device:

  • Changing the lock bits. Only the omitted (shown above) or the default -U lock:w:0xFF:m is non-locking!
  • High DWEN or RSTDISBL overrides RESET and will thus irreversibly break SPI and the ability to program!
  • SPIEN should be 1, Enable Serial Program and Data Downloading, otherwise no SPI anymore!
  • SELFPRGEN should be 1 if you want to use micronucleus.

By default, all the pins of the port B are set to the output pins, this even includes the reset pinPB5!

I wish I read aboutfuse settings earlier.

References

About

Digispark ATtiny85 setup with command line interface. Simple LED blinking example to test frequency and timing.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp