Microcontroller Resources
Learning C Programming
This is a very basic video lecture from my ES52 class on what programming is using the Arduino as the example. This is designed for someone who has no prior programming experience but it does discuss the basic constructs of the C language (which is what Arduino uses). You will need to watch it full screen on something bigger than a cell phone to read the stuff I write on the whiteboard.
Here is a nice written summary of C courtesy of Nick Parlante, Standford University: Standford Essential C (PDF)
Note that while C does not have a native boolean data type, we will often “#include <stdbool>” in our code to add a boolean type, e.g.:
#include <stdbool> bool pressed = false; if (pressed == true) { <do something here> }
There is an interactive C tutorial at learn-c.orgs that might be useful.
If you are familiar with Arduino programming, you know much of the basic structure of C. We discuss pointers, structures and unions (which exist in Arduino but are not documented in the language reference) in class since understanding these C features are necessary in using the CMSIS abstraction layer. We will only need to use integer and boolean data types in this course so you can ignore any reference to floating point numbers and functions.
And a somewhat more basic online tutorial is available at The C Programming Handbook for Beginners.
Microcontroller References and Programs
Here are reference materials for the SAMD21 Cortex M uController
We don’t expect you to read through this great blob of stuff. It’s here for occasional reference.
References
SparkFun SAMD21 Mini Breakout.
The microcontroller board we using has a SAMD21G18 ARM Cortex M0+ processor along with the minimal support circuitry (voltage regulator, LEDs, switches, etc.) necessary to make it useful as a standalone microcontroller. It is provided in a DIP form factor to allow you to plug it into your breadboard.
Board Schematic Links
Board Pin Connections (here is a Simplified Version)
SAMD21 Datasheet (8Mb)
Hookup Guide
While the board is also usable with the Arduino programming environment, we will be using it “bare metal” and coding it directly in C. You may ignore any references to the Arduino environment in the hookup guide.
The SAMD21G18 Microcontroller
The SAMD21G18 microcontroller we are using is a modern, high-performance RISC (Reduced Instruction Set Computer) microcontroller well suited for electronic control applications. It is made by Microchip operates at up to 48MHz clock frequency (most instructions execute in one clock cycle) and includes:
256KB of flash memory for storing program code
32KB of static RAM for variables and data
Six serial communication channels (each individually configurable as either UART/SPI/I2C)
Multiple timer/counters
One USB bus
Real Time Clock
A 14-channel, 12-bit ADC capable of sampling at 350ksps
One 10-bit DAC (plus 20 PWM analog outputs)
Two analog comparators
A Peripheral Touch Controller (PTC) for capacitive touch sensing
Up to 16 external interrupt sources
38 I/O pins (18 of which are available at the pins of the SparkFun breakout board)
The breakout board operates on 5V and provides 3.3V to the uController. It may also be powered from the USB port. Inputs and outputs of the uController must be limited to 3.3V
Development Environment
We will be using the Seeger Embedded Studio (free for non-commercial use) to develop and debug code for the SparkFun board. This is an integrated development environment (IDE) which allows you to edit code for the target system, compile it, link your code with standard libraries, then download and debug your code on the SAMD21 board. It also includes a uController simulator to test your code on even when the actual hardware is not available. It runs on Windows, MacOS and Linux. You should download and install the appropriate version for your operating system. A wiki with miscellaneous information on installing and using Embedded Studio is available at https://wiki.segger.com/Embedded_Studio
CMSIS (Cortex Microcontroller Software Interface Standard)
CMSIS is a [semi-]standard way of accessing resources in different versions and manufacturer’s ARM microcontrollers with minimal code rewrite. Most of the CMSIS interface documentation specific to the M0+ version we will be using is contained in the include files (port.h, sercom.h, etc.) but a general reference is available at:
embOS (Segger Real Time Operating System)
A Real Time Operating System (RTOS) is a small piece of supervisory code that makes writing complex controller programs easier. It adds a set of functions to allow the various pieces of the system to operate as independent tasks. It also provides communication functions to allow tasks to pass information and signal events to each other. We will be using Segger’s RTOS in the final lab to build a useful uController application.
embOS User Guide & Reference Manual (PDF 4Mb)
Debugger
We will use the J-Link EDU Mini to download and debug code on the target system. This small hardware board connects to the 10-pin programming/debugging header on the SAMD21 board to program the flash memory, read and write data memory, read and write registers and control the operation of the uController by single-stepping instructions and setting breakpoints. It is controlled by the IDE via a USB port on your PC. Support for the J-Link Mini is built into the Segger IDE.
ARM Cortex-M Instruction Reference
Cortex-M0+ Technical reference Manual (See section 3.3 for detailed instruction reference and timing)
A compilation of Cortex-M resources
Microchip SAMD Developer Help – An online reference for the uController on the SparkFun board with example code.
A Set of Comprehensive Videos on Embedded Systems Programming Using Cortex M
This set of videos provides an excellent introduction to programming embedded systems using the Cortex M microcontroller. I may ask you to view some of the more basic lessons for the class. (The later lessons get too advanced for the course but you may want to watch them late to get more depth on subjects such as the creation of a RTOS.) The videos use a Cortex M4, but the main difference over the M0+ is addition of a floating point processor which is not used in the lessons. These videos also use a different development board and IDE, but the differences are not that significant. You should still be able to translate the projects to the SparkFun board and Seeger IDE.
https://www.state-machine.com/quickstart/
Freeware Program Editor
reprinted with permission