Skip to content
Permalink
Browse files

Add µduino port

This is essentially a clone of the itsybitsy5v code with the name
changed and the SPI pins disabled as they aren't available on this
device.

Signed-off-by: Keith Packard <keithp@keithp.com>
  • Loading branch information
keith-packard committed Dec 16, 2019
1 parent beb5603 commit 139efe514f23a75cdb214e02aeee9ac12630a3f1
@@ -2361,12 +2361,12 @@ $ avrdude -F -V -c usbtiny -p ATMEGA328P -U flash:w:snek-duemilanove-{version}.h

[%nonfacing]
[appendix]
= Snek on Adafruit ItsyBitsy (both 3v and 5v boards)
= Snek on Adafruit ItsyBitsy and the Crowd Supply µduino

Snek for the Adafruit ItsyBitsy includes the Common System, GPIO
Snek for the ItsyBitsy and µduino includes the Common System, GPIO
(without the `neopixel` function), and EEPROM
functions. Snek for the itsybitsy provides pre-defined
variables for all of the the GPIO pins:(((ItsyBitsy)))
variables for all of the the GPIO pins:(((ItsyBitsy)))(((µduino)))

D0 - D13::
Digital input and output pins. By default, when used as input pins,
@@ -2384,16 +2384,22 @@ an indeterminate value. Change this using `pullnone`, `pullup` or
`pulldown` functions.

MISO, MOSI, SCK::
Additional digital input and output pins. These work just like D0-D13.
Additional digital input and output pins. These work just like
D0-D13. These are not present on the µduino board.

Snek fills the ATMega 32u4 flash completely leaving no space for the
usual USB boot loader, so installing Snek requires a programming
puck, such as the USBTiny device.

On Linux, the Snek installation includes a shell script,
snek-itsybitsy-install, to install the binary using 'avrdude'. Read the
snek-itsybitsy-install manual (also included in the installation) for more
information.
On Linux, the Snek installation includes shell scripts,
snek-itsybitsy-install and snek-µduino-install which install the
binary using 'avrdude'. Read the snek-itsybitsy-install or
snek-µduino-install manual (also included in the installation) for
more information.

The µduino programming wires are only available while the device is
still connected to the carrier board. Normally the µduino has been
broken off of that during manufacturing.

On other hosts, you'll need to install 'avrdude'. Once you've done that, there
are two steps to getting Snek installed on the device.
@@ -2407,7 +2413,7 @@ are two steps to getting Snek installed on the device.
[source]
$ avrdude -F -V -c usbtiny -p m32u4 -U lfuse:w:0xff:m -U hfuse:w:0x91:m -U efuse:w:0xfd:m
+
2. Install the Snek binary. Pick the right voltage for your board as that
2. Install the Snek binary. Pick the version for your board as that
also sets the right clock speed. For 5v boards, install the 5v binary:
+
[source,subs="attributes+"]
@@ -2417,6 +2423,11 @@ for 3v boards, use the 3v binary.
+
[source,subs="attributes+"]
$ avrdude -F -V -c usbtiny -p m32u4 -U flash:w:snek-itsybitsy3v-{version}.hex
+
for µduino boards, use the µduino binary.
+
[source,subs="attributes+"]
$ avrdude -F -V -c usbtiny -p m32u4 -U flash:w:snek-µduino-{version}.hex

[%nonfacing]
[appendix]
@@ -0,0 +1,5 @@
snek-µduino-*.elf
snek-µduino-*.hex
snek-µduino-*.map
snek-µduino-install
ao-product.h
@@ -0,0 +1,67 @@
#
# Copyright © 2019 Keith Packard <keithp@keithp.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#

SNEK_ROOT = ../..
SNEK_AVR = $(SNEK_ROOT)/chips/avr

PROGNAME=snek-µduino
PRODUCT_NAME=snek-µduino

AVR_CLOCK=16000000UL

include $(SNEK_AVR)/snek-avr.defs

SNEK_LOCAL_SRC = \
$(SNEK_AVR_SRC)

SNEK_LOCAL_INC = \
$(SNEK_AVR_INC)

SNEK_LOCAL_BUILTINS = \
$(SNEK_AVR_BUILTINS) \
snek-µduino.builtin

include $(SNEK_ROOT)/snek-install.defs

all: $(ELF) $(HEX) snek-µduino-install

$(PROG): Makefile $(SNEK_OBJ)
$(CC) $(CFLAGS) -o $@ $(SNEK_OBJ) $(LDFLAGS)
@awk '/__data_load_end/{printf("ROM used: %d bytes\n", strtonum($$1)); }' $(MAP)

snek-µduino-install: snek-µduino-install.in
$(SNEK_SED) $^ > $@
chmod +x $@

install:: $(HEX)
install -d $(DESTDIR)$(SHAREDIR)
install -m 0644 $(HEX) $(DESTDIR)$(SHAREDIR)

install:: snek-µduino-install snek-µduino-install.1
install -d $(DESTDIR)$(BINDIR)
install snek-µduino-install $(DESTDIR)$(BINDIR)
install -d $(DESTDIR)$(MANDIR)/man1
install -m 0644 snek-µduino-install.1 $(DESTDIR)$(MANDIR)/man1

clean::
rm -f snek-µduino-install
rm -f *.hex *.elf *.map
rm -f ao-product.h

uninstall::

ISP=avrisp2

load: $(HEX) snek-µduino-install
./snek-µduino-install -quick -isp $(ISP) -hex $(HEX) load
@@ -0,0 +1,95 @@
/*
* Copyright © 2019 Keith Packard <keithp@keithp.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef _AO_PINS_H_
#define _AO_PINS_H_

#define HAS_USB 1
#define HAS_BEEP 0
#define AO_FIFO_SIZE 64

#define AVR_VCC_5V 1
#define AVR_VCC_3V3 0

#define SNEK_IO_GETC(file) ao_usb_getc()
#define SNEK_GETC() (snek_avr_file.get(stdin))
#define fflush(x) ao_usb_flush(x)

#define PIN_MAP { \
[0] = MAKE_MAP(PD, 2), \
[1] = MAKE_MAP(PD, 3), \
[2] = MAKE_MAP(PD, 1), \
[3] = MAKE_MAP(PD, 0), \
[4] = MAKE_MAP(PD, 4), \
[5] = MAKE_MAP(PC, 6), \
[6] = MAKE_MAP(PD, 7), \
[7] = MAKE_MAP(PE, 6), \
[8] = MAKE_MAP(PB, 4), \
[9] = MAKE_MAP(PB, 5), \
[10] = MAKE_MAP(PB, 6), \
[11] = MAKE_MAP(PB, 7), \
[12] = MAKE_MAP(PD, 6), \
[13] = MAKE_MAP(PC, 7), \
[14] = MAKE_MAP(PF, 7), \
[15] = MAKE_MAP(PF, 6), \
[16] = MAKE_MAP(PF, 5), \
[17] = MAKE_MAP(PF, 4), \
[18] = MAKE_MAP(PF, 1), \
[19] = MAKE_MAP(PF, 0), \
}

#define ADC_MAP { \
[14 - FIRST_ADC] = 7, \
[15 - FIRST_ADC] = 6, \
[16 - FIRST_ADC] = 5, \
[17 - FIRST_ADC] = 4, \
[18 - FIRST_ADC] = 1, \
[19 - FIRST_ADC] = 0, \
}

#define OCR_REG_ADDRS { \
[3] = (uint8_t) (uintptr_t) &OCR0B, \
[5] = (uint8_t) (uintptr_t) &OCR3AL, \
[6] = (uint8_t) (uintptr_t) &OCR4D, \
[9] = (uint8_t) (uintptr_t) &OCR1AL, \
[10] = (uint8_t) (uintptr_t) &OCR1BL, \
[11] = (uint8_t) (uintptr_t) &OCR0A, \
[13] = (uint8_t) (uintptr_t) &OCR4A, \
}

#define TCC_REG_ADDRS { \
[3] = (uint8_t) (uintptr_t) &TCCR0A, \
[5] = (uint8_t) (uintptr_t) &TCCR3A, \
[6] = (uint8_t) (uintptr_t) &TCCR4A, \
[9] = (uint8_t) (uintptr_t) &TCCR1A, \
[10] = (uint8_t) (uintptr_t) &TCCR1A, \
[11] = (uint8_t) (uintptr_t) &TCCR0A, \
[13] = (uint8_t) (uintptr_t) &TCCR4A, \
}

#define TCC_REG_VALS { \
[3] = 1 << COM0B1, \
[5] = 1 << COM3A1, \
[6] = 1 << COM4D1, \
[9] = 1 << COM1A1, \
[10] = 1 << COM1B1, \
[11] = 1 << COM0A1, \
[13] = 1 << COM4A1, \
}

#endif /* _AO_PINS_H_ */
@@ -0,0 +1,52 @@
.\"
.\" Copyright © 2019 Keith Packard <keithp@keithp.com>
.\"
.\" This program is free software; you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation, either version 3 of the License, or
.\" (at your option) any later version.
.\"
.\" This program is distributed in the hope that it will be useful, but
.\" WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
.\" General Public License for more details.
.\"
.TH SNEK-ITSYBITSY-INSTALL 1 "snek-itsybitsy-install" ""
.SH NAME
snek-itsybitsy-install \- Install Snek to Adafruit ItsyBitsy board
.SH SYNOPSIS
.B "snek-itsybitsy-install" [OPTION]... [COMMAND]
.SH DESCRIPTION
.I snek-itsybitsy-install
installs the Snek programming language on an Adafruit ItsyBitsy board
with an ATmega32u4.
.SH OPTIONS
.TP
\-isp <ISP model>
Specifies the programmer to use, common options are 'usbtiny'
and 'avrisp2'. The default is 'usbtiny'.
.TP
\-hex <snek.hex>
Specifies the hex file to load to the board. The default is the
currently installed version of Snek.
.TP
\-3v
Use the 3v binary instead of the default 5v binary.
.SH COMMANDS
.TP
fuseload
Sets the target fuse bits for Snek usage and then loads Snek to the
device. This is the default command
.TP
load
Loads Snek to the device without first setting the fuse bits. Snek
will not work correctly if the fuse bits are not set correctly, so
only do this if the target has already had the fuse bits set correctly.
.TP
fuse
Sets the target fuse bits suitable for Snek usage. You must do this
before Snek will work on the target device, although you may do it
before or after loading the Snek system. You only need to do this once
per board.
.SH AUTHOR
Keith Packard
@@ -0,0 +1,62 @@
#!/bin/sh

SHAREDIR="@SHAREDIR@"

SNEKUDUINOBASE="$SHAREDIR/snek-µduino"
SNEKUDUINOREST="-@SNEK_VERSION@.hex"
SNEKUDUINO="$SNEKUDUINOBASE""$SNEKUDUINOREST"

action="fuseload"

ISP=usbtiny

mode=arg

verify=""

for i in "$@"; do
case "$mode" in
arg)
case "$i" in
fuse|load|fuseload)
action="$i"
;;
-isp|--isp)
mode=isp
;;
-hex|--hex)
mode=hex
;;
-quick)
verify="-V"
;;
*)
echo "Usage: $0 {-isp usbtiny} {-isp avrisp2} {-hex snek-µduino.hex} {fuseload|load|fuse}" 1>&2
exit 1
;;
esac
;;
isp)
ISP="$i"
mode=arg
;;
hex)
SNEKUDUINO="$i"
mode=arg
;;
esac
done

FUSES="-U lfuse:w:0xff:m -U hfuse:w:0x91:m -U efuse:w:0xfd:m"

case "$action" in
fuse)
avrdude -V -c $ISP -p m32u4 -u $FUSES
;;
fuseload)
avrdude -V -c $ISP -p m32u4 -u $FUSES && avrdude $verify -c $ISP -p m32u4 -U flash:w:"${SNEKUDUINO}"
;;
load)
avrdude $verify -c $ISP -p m32u4 -U flash:w:"${SNEKUDUINO}"
;;
esac
@@ -0,0 +1,37 @@
#
# Copyright © 2019 Keith Packard <keithp@keithp.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
D0, -2, 0
D1, -2, 1
D2, -2, 2
D3, -2, 3
D4, -2, 4
D5, -2, 5
D6, -2, 6
D7, -2, 7
D8, -2, 8
D9, -2, 9
D10, -2, 10
D11, -2, 11
D12, -2, 12
D13, -2, 13
A0, -2, 14
A1, -2, 15
A2, -2, 16
A3, -2, 17
A4, -2, 18
A5, -2, 19
#include <ao.h>
#include <snek-avr.h>
#define SNEK_POOL 1088
#define SNEK_MAX_TOKEN 63
@@ -26,7 +26,8 @@ FIRMWARE ?= \
$(SNEK_PORTS)/playground/snek-playground-$(SNEK_VERSION).uf2 \
$(SNEK_PORTS)/qemu-arm/snek-qemu-arm-$(SNEK_VERSION).elf \
$(SNEK_PORTS)/qemu-riscv/snek-qemu-riscv-$(SNEK_VERSION).elf \
$(SNEK_PORTS)/snekboard/snek-board-$(SNEK_VERSION).uf2
$(SNEK_PORTS)/snekboard/snek-board-$(SNEK_VERSION).uf2 \
$(SNEK_PORTS)/µduino/snek-µduino-$(SNEK_VERSION).hex

USBFIRMWARE ?= \
$(SNEK_PORTS)/mega/Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex \

0 comments on commit 139efe5

Please sign in to comment.
You can’t perform that action at this time.