Lecture

Review

Recitation: Programming

Weekly assignments

Group Assignment

  1. Compare the performance and development workflows for other architectures
  2. Document your work to the group work page and reflect on your individual page what you learned

Individual Assignments

  1. Read the datasheet for your microcontroller
  2. Use your programmer to program your board to do something

Have you?

  • Linked to the group assignment page
  • Documented what you learned from reading a microcontroller datasheet.
  • Programmed your board
  • Described the programming process/es you used
  • Included your source code
  • Included a short ‘hero video’ of your board

My goals for this week

My personal goal this week is to redo the two boards that I made during the Electronics Design week but this time I want to use the SAMD21 microcontroller to get around the memory issues I had last time. I am not interested in trying to reduce the memory usage by bypassing the Arduino libraries, since the idea of the two boards that I’m trying to make is for them to be really easy to use for people without too much technical knowledge.

I am much more concerned about the memory, well-being, and processing power of the humans using theses boards than I am of the microcontroller’s stress-levels.

Reading a datasheet

Step #1: Datasheet for ATSAMD21

The chips we have at Aalto Fab Lab are the ATSAMD21-E17A versions. I can get the datasheet from Microchip’s website. This microcontroller has the following basic features:

  • CPU Type: Cortex-M0+
  • 128KB in-system self-programmable Flash
  • 16KB of SRAM
  • Up to 48MHz operating frequency
  • Max I/O Pins: 26
  • 10 ADC pins
  • Four serial communication modules (SERCOM) configurable as:
    • UART/USART
    • SPI
    • I2C
    • three 16-bit timer/counters
    • 32-bit Real-Time Clock and calendar
    • 18 PWM channels
    • one 14-channel 12-bit ADC
    • one 10-bit DAC
  • Full Speed USB Device and embedded Host
  • Support for up to 60 touch channels
  • 12 Direct Memory Access (DMA) Channels

Based on my previous experience with the SAMD11, I understand the basics of the architecture and some of the possibilities and limitations of them. I have also used various boards from Sparkfun and Adafruit that use this chip.

Question #1: What are all these different power pins?

Looking at the pinout, the first thing that catches my eye is that the ATSAMD21 has multiple power pins:

  • VDDIO
  • VDDCORE
  • VDDANA

The device has several different power supply pins:

  • VDDIO: Powers I/O lines, OSC8M and XOSC. Voltage is 1.62V to 3.63V.
  • VDDIN: Powers I/O lines and the internal regulator. Voltage is 1.62V to 3.63V.
  • VDDANA: Powers I/O lines and the ADC, AC, DAC, PTC, OSCULP32K, OSC32K, XOSC32K. Voltage is 1.62V to 3.63V.
  • VDDCORE: Internal regulated voltage output. Powers the core, memories, peripherals, FDPLL96M, and DFLL48M. Voltage is 1.2V.

The same voltage must be applied to both VDDIN, VDDIO and VDDANA. This common voltage is referred to as VDD in the datasheet.

The ground pins, GND, are common to VDDCORE, VDDIO and VDDIN. The ground pin for VDDANA is GNDANA. For decoupling recommendations for the different power supplies. Refer to Schematic Checklist for details.

These are the recommended power supply connections:

Power pins schematic

Pin Configuration in the Fab SAM Core

I got these pin diagrams from the Github repo.

============================= MattairTech MT-D21E (ATsamD21EXXA) ========================
Other  COM    PWM   Analog  INT  Arduino*             Arduino*  INT   PWM     COM   Other
=========================================================================================
                                      -------------------
Xin32                                | A0            RST |                           BOOT
Xout32                               | A1            NC  |
DAC                   *            2 | A2            NC  |
REFA                  *            3 | A3            A31 | 31    *   TCC11   RX3   SWDIO*
REFB                  *      *     4 | A4            A30 | 30    *   TCC10   TX3   SWDCLK
                      *      *     5 | A5            NC  |
                      *            6 | A6            A28 | 28    *                   LED
VM                    *            7 | A7            A27 | 27    *                   BTNA
  SDA1/MISO1  TCC00   *     NMI    8 | A8            A23 | 23    *   TC41     SS
   SCL1/SS1   TCC01   *      *     9 | A9            A22 | 22    *   TC40     MISO
      TX1     TCC02   *           10 | A10           A19 | 19    *            SCK
      RX1     TCC03   *           11 | A11           A18 | 18    *            MOSI
   TX2/MOSI1   TC30          *    14 | A14           A17 | 17    *   TCC21    SCL/RX4
    RX2/SCK1   TC31               15 | A15           A16 | 16    *   TCC20    SDA/TX4
                                     | NC            NC  |
                                     | NC            NC  |
                                     | Vbus          3.3V|   * Button B available on 31.
USB D-       TC50                    | A24-  _____   Vcc |
USB D+       TC51                    | A25+ |     |  Vin |
                                     | Gnd  | USB |  Gnd |
                                      -------------------

* Most pins can be used for more than one function. The port pin number printed
  on the board is also used in Arduino (but without the 'A') for all of the supported
  functions (ie: digitalRead(), analogRead(), analogWrite(), attachInterrupt(), etc.).
* When USB CDC is enabled, Serial refers to SerialUSB, otherwise it refers to Serial1.
* Leave pin A30 floating (or use external pullup) during reset.
* DO NOT connect voltages higher than 3.3V!
* Tone available on TC5.
============================================================================================================================================
Arduino	| Silk	| Port	| Alternate Function	| Comments (! means not used with this peripheral assignment)
--------|-------|-------|-----------------------|-------------------------------------------------------------------------------------------
0	| A0	| PA00	| Xin32			| Xin32
1	| A1	| PA01	| Xout32		| Xout32
2	| A2	| PA02	|			| !EIC/EXTINT[2] ADC/AIN[0] PTC/Y[0] DAC/VOUT
3	| A3	| PA03	| REFA			| !EIC/EXTINT[3] REF/ADC/VREFA REF/DAC/VREFA ADC/AIN[1] PTC/Y[1]
4	| A4	| PA04	| REFB			| EIC/EXTINT[4] REF/ADC/VREFB ADC/AIN[4] AC/AIN[0] PTC/Y[2] !SERCOM0/PAD[0] !TCC0/WO[0]
5	| A5	| PA05	|			| EIC/EXTINT[5] ADC/AIN[5] AC/AIN[1] PTC/Y[3] !SERCOM0/PAD[1] !TCC0/WO[1]
6	| A6	| PA06	|			| !EIC/EXTINT[6] ADC/AIN[6] AC/AIN[2] PTC/Y[4] !SERCOM0/PAD[2] !TCC1/WO[0]
7	| A7	| PA07	| Voltage Divider	| !EIC/EXTINT[7] ADC/AIN[7] AC/AIN[3] PTC/Y[5] !SERCOM0/PAD[3] !TCC1/WO[1]
8	| A8	| PA08	| SDA1/MISO1		| EIC/NMI ADC/AIN[16] PTC/X[0] !SERCOM0/PAD[0] SERCOM2/PAD[0] TCC0/WO[0] !TCC1/WO[2]
9	| A9	| PA09	| SCL1/SS1		| EIC/EXTINT[9] ADC/AIN[17] PTC/X[1] !SERCOM0/PAD[1] SERCOM2/PAD[1] TCC0/WO[1] !TCC1/WO[3]
10	| A10	| PA10	| TX1			| !EIC/EXTINT[10] ADC/AIN[18] PTC/X[2] SERCOM0/PAD[2] !SERCOM2/PAD[2] !TCC1/WO[0] TCC0/WO[2]
11	| A11	| PA11	| RX1			| !EIC/EXTINT[11] ADC/AIN[19] PTC/X[3] SERCOM0/PAD[3] !SERCOM2/PAD[3] !TCC1/WO[1] TCC0/WO[3]
12	| ---	| ----	| NOT A PIN		| NOT A PIN
13	| ---	| ----	| NOT A PIN		| NOT A PIN
14	| A14	| PA14	| Xin, TX2/MOSI1	| EIC/EXTINT[14] SERCOM2/PAD[2] TC3/WO[0] !TCC0/WO[4] Xin, HOST_ENABLE
15	| A15	| PA15	| Xout, RX2/SCK1	| !EIC/EXTINT[15] SERCOM2/PAD[3] TC3/WO[1] !TCC0/WO[5] Xout
16	| A16	| PA16	| SDA/TX4 w/pullup	| EIC/EXTINT[0] PTC/X[4] SERCOM1/PAD[0] SERCOM3/PAD[0] TCC2/WO[0] !TCC0/WO[6]
17	| A17	| PA17	| SCL/RX4 w/pullup	| EIC/EXTINT[1] PTC/X[5] SERCOM1/PAD[1] SERCOM3/PAD[1] TCC2/WO[1] !TCC0/WO[7]
18	| A18	| PA18	| SPI			| EIC/EXTINT[2] PTC/X[6] !SERCOM1/PAD[2] SERCOM3/PAD[2] !TC3/WO[0] !TCC0/WO[2]
19	| A19	| PA19	| SCK			| EIC/EXTINT[3] PTC/X[7] !SERCOM1/PAD[3] SERCOM3/PAD[3] !TC3/WO[1] !TCC0/WO[3]
20	| ---	| ----	| NOT A PIN		| NOT A PIN
21	| ---	| ----	| NOT A PIN		| NOT A PIN
22	| A22	| PA22	| MISO			| EIC/EXTINT[6] PTC/X[10] SERCOM3/PAD[0] TC4/WO[0] !TCC0/WO[4]
23	| A23	| PA23	| SS			| EIC/EXTINT[7] PTC/X[11] SERCOM3/PAD[1] TC4/WO[1] !TCC0/WO[5]
24	| A24-	| PA24	| USB_NEGATIVE		| USB/DM TC5/WO[0]
25	| A25+	| PA25	| USB_POSITIVE		| USB/DP TC5/WO[1]
26	| ---	| ----	| NOT A PIN		| NOT A PIN
27	| A27	| PA27	| Button A		| EIC/EXTINT[15] Button A
28	| A28	| PA28	| LED			| EIC/EXTINT[8] LED
29	| ---	| ----	| NOT A PIN		| NOT A PIN
30	| A30	| PA30	| SWDCLK / TX3		| EIC/EXTINT[10] SERCOM1/PAD[2] TCC1/WO[0] SWD CLK, leave floating during boot
31	| A31	| PA31	| Button B / SWDIO / RX3| EIC/EXTINT[11] SERCOM1/PAD[3] TCC1/WO[1] Button B SWD IO
--	| RST	| ----	|			| Reset, BOOT (double tap bootloader entry)
============================================================================================================================================

* Most pins can be used for more than one function. The port pin number printed
  on the board is also used in Arduino (but without the 'A') for all of the supported
  functions (ie: digitalRead(), analogRead(), analogWrite(), attachInterrupt(), etc.).
* The following Arduino pin numbers are not mapped to a physical pin: 12, 13, 20, 21, 26, and 29.
* Pins 24 and 25 are by default in use by USB (USB_NEGATIVE and USB_POSITIVE).
* TC5(D21) is available on these pins otherwise. The tone library uses TC5.
* A0 and A1 are by default connected to the 32.768KHz crystal.
* Leave pin A30 floating (or use external pullup) during reset.

USB Data

For USB data connection, I should use these pins:

  • USB D- PA24, physical pin 23
  • USB D+ PA25, physical pin 24

I2C Pins

The I2C pins will be connectod on the JST SH connector so that I can use sensors from Sparkfun or Adafruit.

  • SDA: PA16, physical pin 16
  • SCL: PA17, physical pin 17

Analog Input pins (ADC)

  • A2
  • A3
  • A4
  • A5
  • A6
  • A7
  • A8
  • A9
  • A10 (I will add a phototransistor as a light sensor on this pin)
  • A11 (I will ad an RTD temperature sensor on this pin)

Kimchi Mandu Board

I designed a new board this week.

Kimchi Mandu Board

Features

  • 1A/3.3V voltage regulator
  • One LED
  • One Neopixel LED (RGBW)
  • Phototransistor
  • Thermistor
  • Qwiic connector for I2C enabled sensors
  • Rest of the pins broken out to header pins (I’m planning to make some shields for it in the next weeks)

EDBG issues on Mac

During the Electronics Production week, I was having problems getting edbg to work on macOS. Neil asked to document this issue in detail so I will attempt to do so.

I found this closed GitHub issue that seems to be related](https://github.com/ataradov/edbg/issues/112)

The problem seems to be:

“USB HID protocol that is used for CMSIS-DAP communication requires frames to be sent with fixed size. USB Full Speed devices support 64 bytes max, so this is the size that is commonly used. USB High Speed devices can go higher, so 512 or 1024 bytes are common.

Linux and Windows ports use OS-specific APIs to determine the size of the endpoint and automatically adjust. MAC port is not really maintained, since I don’t use macs and don’t have any apple hardware. So the size is just set to a fixed value.”

Alex Taradov

So the change that is suggested would be to change one line of the code from this:

static int report_size = 512; // TODO: read actual report size

to this:

static int report_size = 64; // TODO: read actual report size

It did not say what file this is, but I found out that it is dbg_mac.c. So I changed this line of code, did make all again.

Then I tried the uploading process again

./edbg -ebpv -t samd11 -f sam_ba_SAMD11C14A.bin
Debugger: Alex Taradov Generic CMSIS-DAP Adapter 7217091F v0.1 (S)
Clock frequency: 16.0 MHz
Target: SAM D11C14A (Rev B)
Erasing... done.
Programming.... done.
Verification.... done.

Success! This suggested change seemed to fix it. I’m not smart enough to do what ataradov suggest next, which is to somehow read the report_size automatically based on what USB protocol is used.

The full process on macOS to get edbg working

  1. Using Homebrew, install hidapi with the command brew install hidapi
  2. Clone or download the edbg source code from GitHub
  3. Open the file called dbg_mac.c
  4. Find the line that says static int report_size = 512;
  5. Change it to static int report_size = 64;
  6. Using terminal, navigate to the folder where the edbg source code is
  7. Type make alland hit enter
  8. The program should compile and a little program called edbg should appear in the folder
  9. If you get some errors in the previous step, read the error messages carefully. You might be missing some dependencies, install any missing things using Homebrew and try again.
  10. Download the bootloader that you wish to use (check the documentation of your board/microcontroller on what to use). You might be looking for some of these: