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.
-
blinky.cis the Blinky program that blinks the on-board LED on PA5, and it is also the known-good copy for a Blinky project that will not build (Chapterย 7).
Day 2: Lab 1.
-
template.cis the template for each C file of Lab 1, an emptymain()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.clights the on-board LED while the pushbutton on D5 (PB4), read through the internal pull-up, is pressed.
Day 5: UART.
Day 7: Analog-to-Digital Conversion.
-
ADCPot.cis the skeleton, withTODOblanks, of a program that reads a potentiometer on PA0 with the ADC and prints the result over the UART.
Day 8: Timers and Interrupts.
-
blinkyTimerPolled.cblinks the on-board LED by polling the TIM14 update flag, and it is complete. -
blinkyTimerInt.cis the skeleton, withTODOblanks, of the same blink driven by a TIM14 update interrupt.
Day 9: GPIO Interrupts.
-
counterResetButtonPolled.cis a counter printed over the UART whose reset button on D5 (PB4) is polled in the main loop. -
counterResetButtonInt.cis the skeleton, withTODOblanks, of the same counter with the reset button handled by an EXTI falling-edge interrupt.
Day 9X: I2C.
-
i2c.cis 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 inLibrary/mylib. -
helloDisplay.cputs four characters on the seven-segment display through the I2C library.
Day 10: The Displayโs Device Driver.
-
SevenSegPartial.cis the device driver for the HT16K33 display, with four functions whose signatures are given and whose bodies you complete. -
SevenSegPartial.his the driverโs header, with the displayโs I2C address, the HT16K33 command bytes and the prototypes of the driver functions. -
writeFirstDigit.cis the test program that puts one character on one digit of the display through the driver.
Day 11: DC Motors and PWM.
-
TTmotor_ramp.cramps 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.creads the LSM303AGRโsWHO_AM_Iregister to confirm that the I2C link to the accelerometer works. -
lsm303agr.his 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.
-
lsm303agr_partial.cis the accelerometerโs device driver, with functions for you to complete. -
accel_test.ccalls the driver functions and prints the raw acceleration readings, to test the completed driver.
Day 15: Servomotors.
-
Day15_servo_template.csets a servoโs position from a potentiometer through the ADC and a PWM pulse, and it is complete except for five#definevalues and the line that maps the potentiometer reading to a pulse width. -
tim.cis the timer driver, with a TIM16 interrupt every given number of milliseconds and TIM14 PWM on PA7. -
tim.hholds the prototypes of the three functions intim.c.
Day 17X: Power Management.
-
watchdog.cstarts 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.
