Lecture
Review
Weekly assignments
Group Assignment
- Characterize the design rules for your in-house PCB production process: document feeds, speeds, plunge rate, depth of cut (traces and outline) and tooling document your work (in a group or individually)
- Document your work to the group work page and reflect on your individual page what you learned
Individual Assignments
- Make an in-circuit programmer that includes a microcontroller by milling and stuffing the PCB, test it to verify that it works
Have you?
- Linked to the group assignment page
- Documented how you made (mill, stuff, solder) the board
- Documented that your board is functional
- Explained any problems and how you fixed them
- Included a ‘hero shot’ of your board
Making a UPDI programmer board
Fab Academy has kindly worked on a set of different programmer boards that can be found here: Fab Academy programmers
I am going to make a UPDI programmer based on the ATSAMD11C14 microcontroller
At Aalto Fab Lab we have two milling machines suitable for making PCBs. SRM-20 and MDX-40, I used the SRM-20 to make my board.
SRM-20
CopperCAM
Results
This was the result after milling, there were a few traces in the USB connector part that did not go all the way through. This was not a big deal since I had to go with the knife anyway to remove the edges from that part. I also used a knife to clean up some extra copper between some of the traces just in case.
First I soldered the microcontroller.
Then I drew the rest of the owl… I mean soldered the other parts.
Using an SWD Programmer to program my UDPI programmer
I haven’t been able to be at the lab during any reasonable time, so I couldn’t ask Krisjanis to burn the bootloader for my board. So I tried to figure it out on my own.
Instructions are not very clear, but I got it working.
Install edbg
- Install hidapi:
brew install hidapi
(this is a dependency for edbg on Mac) - Download the edbg source code (or clone the repository)
- Navigate to the edbg folder that you just downloaded
make all
- This should compile a little program called edbg
- Test that it works:
./edbg -h
I got this as a reply:
CMSIS-DAP SWD programmer. Built Feb 23 2022 00:47:13.
Usage: ./edbg [options]
Options:
-h, --help print this help message and exit
-b, --verbose print verbose messages
-x, --reset <duration> assert the reset pin before any other operation (duration in ms)
-e, --erase perform a chip erase before programming
-p, --program program the chip
-v, --verify verify memory
-k, --lock lock the chip (set security bit)
-u, --unlock unlock the chip (forces chip erase in most cases)
-r, --read read the whole content of the chip flash
-f, --file <file> binary file to be programmed or verified; also read output file name
-t, --target <name> specify a target type (use '-t list' for a list of supported target types)
-l, --list list all available debuggers
-s, --serial <number> use a debugger with a specified serial number or index in the list
-c, --clock <freq> interface clock frequency in kHz (default 16000)
-o, --offset <offset> offset for the operation
-z, --size <size> size for the operation
-F, --fuse <options> operations on the fuses (use '-F help' for details)
Find a working SWD programmer
I noticed an SWD programmer at the lab that looked promising. This is probably what Kris has been using.
I plugged it in and tried to see if edbg recognizes it:
./edbg -l
and got:
Attached debuggers:
0: 4344C80D - Alex Taradov Generic CMSIS-DAP Adapter
I’m assuming this is what I was supposed to see.
Download and burn the bootloader for the SAMD11C14A chip
You can find the bootloaders for these chips from: https://github.com/qbolsee/ArduinoCore-fab-sam/tree/master/bootloaders/zero/binaries
I needed to download the file sam_ba_SAMD11C14A.bin
. Here is a direct link.
I moved the file to the same folder where my edbg program is. Then I connected the connector from the SWD programmer to the board I made. Making sure to get the orientation right by figuring out which pin is GND.
The SWD connector does not power the other board, so I had to also plug it in with the USB connector.
Attempt #1: using edbg
I tried to do:
./edbg -ebpv -t samd11 -f sam_ba_SAMD11C14A.bin
But just got:
Error: invalid response received
Not sure what’s wrong…
I found out a fix for this issue during the Embedded Programing week. See the solution here.
Attempt #2: using Arduino IDE
The instructions also said that I could use Arduino IDE to do this, so that was my next attempt.
At first, it failed, but then I changed the programmer to “Atmel EDBG”. After that it seemed to work.
I unplugged the SWD programmer and checked my serial port list:
🙌 At least it appears in the list. I would call this at least a partial success!
Programming another microcontroller with my UPDI programmer board
I haven’t had the time this week to make another board, so I went through Kris’s box to see if there was some type of board that I could use to test my programmer on. I did find a board that said “HELLO T412”. Perfect. This is a hello board for the ATtiny412. I should be able to make the LED on this board blink the way I want to.First step, connect the 2x3 cable to both boards. It can be connected either way (very nice feature). There was some code already on this board so it started blinking in a specific pattern.
I then opened Arduino IDE and installed the megaTinyCore board definitions. First, I added the board manager URL:
http://drazzy.com/package_drazzy.com_index.json
Then I openened the Boards Manager, searched for “megaTinyCore” and installed the latest version.
Then I openend the trusty Blink example. Selected the ATtiny412 option from the Board menu and SerialUPDI (Slow) as the programmer. I left everything else at the default options.
Failed.
Looking at the errors, I realize that this is using python somehow. I have a new computer and I didn’t have python3 yet installed here, so I thought that maybe that might be the issue I’m having. So I used pyenv to setup the latest version of python3 on this computer.
Ok, python installed, restart Arduino, try to upload again. Still not working. I now rewind my thinking a bit and do some research. I realize that I need to first upload a specific code to UPDI programmer that it actually is able to act as a programmer. Obviously, it’s not enough to just have the bootloader.
So I disconnect the ATtiny board, set the tool options back for my D11C14A board. Then I upload the following code I found from Quentin Bolsee’s page. The code just passes through anything that is sent over the USB serial port to the other serial port available on the microcontroller.
void setup() {
SerialUSB.begin(0);
Serial2.begin(115200, SERIAL_8E2);
}
void loop() {
if (SerialUSB.available()) {
Serial2.write((char) SerialUSB.read());
}
if (Serial2.available()) {
SerialUSB.write((char) Serial2.read());
}
}
CORRECTION
Instead of the simple version above, a better firmware for your programmer board is actually this:
https://github.com/qbolsee/SAMD11C_serial
Ok, getting closer. Then I did this:
- Switched the board settings back to the ATtiny412
- Plugged it back in
- figured out what pin number the LED is connected to. (It’s pin #4 on the chip but digital output pin #2 in the Arduino world)
- Uploaded the code
- Success!
Now I can go home. I know I kind of stepped to the Embedded Programming week here already, but I really wanted to see this board working for real.
Round 2: SWD Programmer
I wanted to make my own SWD programmer so I don’t have to go digging into Kris’ box of boards anymore. I like the ATSAMD microcontrollers and I feel like I’m going to be using a lot of them during the spring. So now is a good time to make sure I make a programmer for them.
openocd
I tried edbg again. No luck, still getting Error: invalid response received
. This seems to be a thing on MacOS. This time, I tried to follow the instructions and use openocd to program my board.
❯ openocd
Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
DEPRECATED! use 'adapter driver' not 'interface'
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: FW Version = v0.1
Info : CMSIS-DAP: Serial# = 4344C80D
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 400 kHz
Error: Error connecting DP: cannot read IDR
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
After scratching my head for a little while and trying all kinds of things to make this work, I went and double-checked the programming cable. Of course, it was connected the wrong way on the programmer side 😵💫.
Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
DEPRECATED! use 'adapter driver' not 'interface'
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: FW Version = v0.1
Info : CMSIS-DAP: Serial# = 4344C80D
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 400 kHz
Info : SWD DPIDR 0x0bc11477
Info : at91samd11c14a.cpu: hardware has 4 breakpoints, 2 watchpoints
Error: at91samd11c14a.cpu -- clearing lockup after double fault
Polling target at91samd11c14a.cpu failed, trying to reexamine
Info : at91samd11c14a.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for at91samd11c14a.cpu on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0xd1000000 pc: 0xfffffffe msp: 0xfffffffc
target halted due to debug-request, current mode: Thread
xPSR: 0xd1000000 pc: 0xfffffffe msp: 0xfffffffc
** Programming Started **
Info : SAMD MCU: SAMD11C14A (16KB Flash, 4KB RAM)
** Programming Finished **
** Verify Started **
** Verified OK **
shutdown command invoked
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
So now I have my own SWD programmer also. Great, I can start to make real boards that do something else than just blink LEDs.