Skip to main content

Appendix E Starter Files

These are the starter files we hand out during the term, grouped by the day on which you first use each one. Each file name links to the file itself.

Day 1: GPIO and Blinky.

Day 2: Lab 1.

  • template.c is the template for each C file of Lab 1, an empty main() under a header comment block for your name, the assignment, the I/O pins and a revision history, and it is also on Canvas.

Day 3: Digital Inputs.

  • button.c lights the on-board LED while the pushbutton on D5 (PB4), read through the internal pull-up, is pressed.

Day 5: UART.

  • counter.c prints a count in hexadecimal and decimal to CoolTerm over the UART.
  • uart.c is the USART2 driver, with uart2_init(), uart2_write(), uart2_read() and the __io_putchar() that sends the characters of printf() over the UART, and it goes in Library/mylib.
  • uart.h holds the prototypes of the three uart2_ functions and goes in Library/mylib beside uart.c.

Day 7: Analog-to-Digital Conversion.

  • ADCPot.c is the skeleton, with TODO blanks, of a program that reads a potentiometer on PA0 with the ADC and prints the result over the UART.

Day 8: Timers and Interrupts.

Day 9: GPIO Interrupts.

Day 9X: I2C.

  • i2c.c is the I2C1 interface driver on PB8 (SCL) and PB9 (SDA), with functions that write and read single bytes and runs of registers, and it goes in Library/mylib.
  • i2c.h holds the prototypes of the five i2c1_ functions and goes in Library/mylib beside i2c.c.
  • helloDisplay.c puts four characters on the seven-segment display through the I2C library.

Day 10: The Displayโ€™s Device Driver.

Day 11: DC Motors and PWM.

  • TTmotor_ramp.c ramps the speed of a TT motor up and down in both directions through the TB6612FNG motor driver, with a TIM14 PWM signal on PA7.

Day 13: The Accelerometer.

  • whoami_test.c reads the LSM303AGRโ€™s WHO_AM_I register to confirm that the I2C link to the accelerometer works.
  • lsm303agr.h is the header of the accelerometerโ€™s device driver, with its I2C address, its register addresses and the prototypes of the driver functions.

Day 14: The Accelerometerโ€™s Data.

Day 15: Servomotors.

  • Day15_servo_template.c sets a servoโ€™s position from a potentiometer through the ADC and a PWM pulse, and it is complete except for five #define values and the line that maps the potentiometer reading to a pulse width.
  • tim.c is the timer driver, with a TIM16 interrupt every given number of milliseconds and TIM14 PWM on PA7.
  • tim.h holds the prototypes of the three functions in tim.c.

Day 17X: Power Management.

  • watchdog.c starts the independent watchdog with a 4-second timeout and reloads it each time the blue user button is pressed, so the STM32C031C6 resets whenever 4 seconds pass without a press.
Two more files, ES28.h and sysinit.c, come with the Library folder you copy during setup (Appendixย D) rather than on a particular day: ES28.h includes the register definitions and declares delay_ms() and milliseconds(), and sysinit.c contains the code for both.