npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

avrgirl-ispmkii

v1.0.6

Published

avrgirl wrapper for flashing chips via the AVRISPmkII programmer

Downloads

27

Readme

Build Status Coverage Status

avrgirl-ispmkii

A NodeJS interface layer for the AVRISP mkII programmer from Atmel®.

avrgirl logo

Installation

OSX:

npm install avrgirl-ispmkii

Linux:

apt-get install build-essential libudev-dev
npm install avrgirl-ispmkii

Windows:

Use Zadig to install the WinUSB driver for your USB device. Otherwise you will get weird LIBUSB_ERROR_NOT_SUPPORTED errors, oops!

Then:

npm install avrgirl-ispmkii

What is this?

Known for its rather awkward enclosure/case, the AVRISP mkII programmer is a great little device to have around. Flashing and reading chips with it is a relatively easy affair. It follows the STK500v2 protocol.

avrispmkii

You can use this library with an AVRISP mkII programmer to do many tasks with connected AVR microchips:

  • Enter / leave programming mode
  • Read chip signatures
  • Write to EEPROM and Flash memory
  • Read from EEPROM and Flash memory
  • Erase chip memory
  • Read and write fuses
  • Get and set parameters

What would I use this for?

Let's say you'd like to use NodeJS to flash and erase AVR branded microchips. This is the library for you! ❤️

How to use

avrgirl-ispmkii takes only one argument on instantiation: a JSON object containing the configuration for the microchip you're using. Please see the providing your chip configuration section for more information on how to do this. The example below uses avrgirl-chips-json to achieve this.

Example to get you set up:

var AvrgirlIspmkii = require('avrgirl-ispmkii');
var chips = require('avrgirl-chips-json');

var attiny45 = chips.attiny45;
var avrgirl = new AvrgirlIspmkii(attiny45);

avrgirl.on('ready', function() {
  // do cool stuff
});

Providing your chip configuration

The chip property is an object that follows a strict format / signature. It specifies the configuration properties of the microchip you are using. You'll need to know and supply this configuration. You can find this from AVR Studio, the avrgirl-chips-json package, or use the AVRDUDE conf API. Pull requests to the avrgirl-chips-json repo with additional chips is most welcome.

Here is the signature, provided as an example of the ATtiny85:

var attiny85 = {
  "name": "ATtiny85",
  "timeout": 200,
  "stabDelay": 100,
  "cmdexeDelay": 25,
  "syncLoops": 32,
  "byteDelay": 0,
  "pollIndex": 3,
  "pollValue": 83,
  "preDelay": 1,
  "postDelay": 1,
  "pgmEnable": [172, 83, 0, 0],
  "erase": {
    "cmd": [172, 128, 0, 0],
    "delay": 45,
    "pollMethod": 1
  },
  "flash": {
    "write": [64, 76, 0],
    "read": [32, 0, 0],
    "mode": 65,
    "blockSize": 64,
    "delay": 10,
    "poll2": 255,
    "poll1": 255,
    "size": 8192,
    "pageSize": 64,
    "pages": 128,
    "addressOffset": 0
  },
  "eeprom": {
    "write": [193, 194, 0],
    "read": [160, 0, 0],
    "mode": 65,
    "blockSize": 4,
    "delay": 5,
    "poll2": 255,
    "poll1": 255,
    "size": 512,
    "pageSize": 4,
    "pages": 128,
    "addressOffset": 0
  },
  "sig": [30, 147, 11],
  "signature": {
    "size": 3,
    "startAddress": 0,
    "read": [48, 0, 0, 0]
  },
  "fuses": {
    "startAddress": 0,
    "write": {
      "low": [172, 160, 0, 0],
      "high": [172, 168, 0, 0],
      "ext": [172, 164, 0, 0]
    },
    "read": {
      "low": [80, 0, 0, 0],
      "high": [88, 8, 0, 0],
      "ext": [80, 8, 0, 0]
    }
  }
}

Available methods

quickFlash

This is a convenient, fast way to write to the flash memory of the microchip.

Underneath, this method is doing the following:

  1. Enters programming mode
  2. Calls writeFlash and writes to the flash memory on the chip
  3. Exits programming mode and calls back

It does not erase the chip before writing.

Provide a filepath string, and a callback, respectively. Alternatively, you may also provide a pre-parsed Buffer in in place of the filepath.

Returns a null error upon callback if successful.

avrgirl.quickFlash('Blink.cpp.hex', function(error) {
  console.log(error);
});

quickEeprom

This is a convenient, fast way to write to the eeprom memory of the microchip.

Underneath, this method is doing the following:

  1. Enters programming mode
  2. Calls writeEeprom and writes to the eeprom memory on the chip
  3. Exits programming mode and calls back

It does not erase the chip before writing.

Provide a filepath string, and a callback, respectively. Alternatively, you may also provide a pre-parsed Buffer in in place of the filepath.

Returns a null error upon callback if successful.

avrgirl.quickEeprom('myEeprom.cpp.hex', function(error) {
  console.log(error);
});

getChipSignature

Gets the signature of the microchip.

Returns a buffer containing the signature bytes.

Usage:

avrgirl.getChipSignature(function(error, signature) {
  console.log(signature);
});

enterProgrammingMode

Enables programming mode on the microchip.

Returns a null error upon callback if successful.

avrgirl.enterProgrammingMode(function(error) {
  console.log(error);
});

exitProgrammingMode

Leaves programming mode on the microchip. Returns a null error upon callback if successful.

avrgirl.exitProgrammingMode(function(error) {
  console.log(error);
});

eraseChip

Erases both the flash and EEPROM memories on the microchip. Good practice to do before flashing any new data.

💣💣💣 Literally erases everything please be careful 💣💣💣

Returns a null error upon callback if successful.

avrgirl.eraseChip(function(error) {
  console.log(error);
});

getParameter

Gets the value of a specified parameter for AVRISP mkII's settings. Pass in the parameter's byte label and a callback respectively.

Returns a null error and the parameter value upon callback if successful.

avrgirl.getParameter(0x94, function(error, data) {
  console.log(error, data);
});

setParameter

Sets the value of a specified parameter for AVRISP mkII's settings. Pass in the parameter's byte label, the requested value, and a callback respectively.

Returns a null error upon callback if successful.

avrgirl.setParameter(0x94, 0x00, function(error) {
  console.log(error);
});

writeFlash

Writes a buffer to the flash memory of the microchip. Provide a filepath string, and a callback, respectively. Alternatively, you may also provide a pre-parsed Buffer in in place of the filepath.

Returns a null error upon callback if successful.

avrgirl.writeFlash(buffer, function(error) {
  console.log(error);
});

writeEeprom

Writes a buffer to the eeprom memory of the microchip. Provide a filepath string, and a callback, respectively. Alternatively, you may also provide a pre-parsed Buffer in in place of the filepath.

Returns a null error upon callback if successful.

avrgirl.writeEeprom(buffer, function(error) {
  console.log(error);
});

readFlash

Reads a specified length of flash memory from the microchip. Takes a length integer (or hex) for the number of bytes to read, and a callback as the arguments, respectively.

Returns a null error and a buffer of the read bytes upon callback if successful.

Usage:

avrgirl.readFlash(64, function(error, data) {
  console.log(data);
});

readEeprom

Reads a specified length of flash memory from the microchip. Takes a length integer (or hex) for the number of bytes to read, and a callback as the arguments, respectively.

Returns a null error and a buffer of the read bytes upon callback if successful.

Usage:

avrgirl.readFlash(64, function(error, data) {
  console.log(error, data);
});

readFuses

Reads all of the available fuse values on the microchip.

Returns a null error and an object containing the fuse key and byte value pairs upon callback if successful.

Usage:

avrgirl.readFuses(function(error, data) {
  console.log(error, data);
});

readFuse

Reads a specific fuse on the microchip. Pass in a string of the right fuse key from the chip properties.

Returns a null error and a buffer containing the fuse byte value upon callback if successful.

Usage:

avrgirl.readFuse('low', function(error, data) {
  console.log(error, data);
});

writeFuse

💣💣💣 OMG, please be careful with this. 💣💣💣 please please please.

You can brick your chip if you do not know exactly what you're doing. Use an online fuse calculator first, and triple check before running this method.

I accept no responsibility for bricked chips 💀😱😭

Takes a fuse key string, a value to set it to, and a callback.

Usage:

// *********
// please do not run this code unless you're sure that 0x62 is a good idea for your chip ;___;
// *********
avrgirl.writeFuse('low', 0x62, function(error) {
  // note: a null error doesn't necessarily mean you didn't do something foolish here.
  console.log(error);
});

Other methods

NOTE: The following methods below are rarely needed, but documented in case you have need for them.

open

Void. Upon instantiation, avrgirl-ispmkii opens a connection to the AVRISP mkII. You shouldn't need to call this method unless you've previously closed the connection manually.

Usage:

avrgirl.open();

close

Void. Closes the connection to the AVRISP mkII.

Usage:

avrgirl.close();

write

Writes a buffer of data to the microchip. Takes a buffer and a callback as the arguments, respectively.

Usage:

var buffer = new Buffer([0x01, 0x00, 0x00]);

avrgirl.write(buffer, function(error) {
  console.log('written.');
});

read

Reads the last response from the microchip. Takes a length integer (number of bytes to read), and a callback as the arguments, respectively. Generally you'll want to call this immediately after a write.

Usage:

var buffer = new Buffer([0x01, 0x00, 0x00]);

avrgirl.write(buffer, function(error) {
  avrgirl.read(2, function(error, data) {
	console.log(data);
  });
});

sendCmd

SendCmd is a shortcut to sending an instruction buffer, of which you're simply expecting an 'OK' back. Your instruction will be sent, and the callback will return a null error if an 'OK' response returned.

The requires response length needs to be 2 bytes. Not compatible with instructions that aren't simply a simple command for the device. Use write, or the matched method for what you're wanting to achieve.

Returns a null error if successful.

var buffer = new Buffer([0x01, 0x00, 0x00]);

avrgirl.sendCmd(buffer, function(error) {
  console.log(error);
});