Skip to main content

Appendix B Key STM32C031C6 Registers Reference

This appendix lists every peripheral register that the course code writes or reads, or that an exercise asks you to set, grouped by peripheral in the order in which we first use them. Each table gives the register’s name as it appears in the reference manual, RM0490, its address offset from the peripheral’s base address, the C expression the course code uses for it, and the part of the book in which it is explained. In a C expression, GPIOx stands for GPIOA, GPIOB or GPIOC, and TIMx for TIM14 or TIM16. The register’s address is the base address plus the offset: GPIOA->ODR, for example, is at 0x5000 0000 + 0x14 = 0x5000 0014. The electrical characteristics and the pinout of the chip itself are in the STM32C031C6 datasheet.
Table B.0.1. RCC (reset and clock control), base address 0x4002 1000
Register Offset C expression Purpose Taught in
RCC_IOPENR 0x34 RCC->IOPENR Enables the clocks of GPIO ports A, B and C Subsection 1.2.3
RCC_APBENR1 0x3C RCC->APBENR1 Enables the clocks of USART2, I2C1 and PWR Subsection 3.3.2
RCC_APBENR2 0x40 RCC->APBENR2 Enables the clocks of the ADC, TIM14 and TIM16 Subsection 6.2.4
Table B.0.2. GPIO ports A, B and C, base address GPIOA 0x5000 0000, GPIOB 0x5000 0400, GPIOC 0x5000 0800
Register Offset C expression Purpose Taught in
GPIOx_MODER 0x00 GPIOx->MODER Two bits per pin select input, output, alternate function or analog mode Subsection 1.2.3
GPIOx_OTYPER 0x04 GPIOx->OTYPER One bit per pin selects push-pull (0) or open-drain (1) output Subsection 10.3.6
GPIOx_PUPDR 0x0C GPIOx->PUPDR Two bits per pin select no pull resistor, pull-up or pull-down Subsection 2.1.2
GPIOx_IDR 0x10 GPIOx->IDR Read-only; one bit per pin gives the logic level on the pin Subsection 2.1.1
GPIOx_ODR 0x14 GPIOx->ODR One bit per pin sets the output level Subsection 1.1.3
GPIOx_BSRR 0x18 GPIOx->BSRR Write-only; a 1 in bits 15:0 sets a pin and a 1 in bits 31:16 clears it, with no read-modify-write Subsection 9.2.8
GPIOx_AFRL 0x20 GPIOx->AFR[0] Four bits per pin select the alternate function of pins 0 to 7 Subsection 3.3.1
GPIOx_AFRH 0x24 GPIOx->AFR[1] Four bits per pin select the alternate function of pins 8 to 15 Subsection 10.3.6
Table B.0.3. USART2, base address 0x4000 4400
Register Offset C expression Purpose Taught in
USART_CR1 0x00 USART2->CR1 UE enables the USART, TE its transmitter and RE its receiver Subsection 3.3.4
USART_BRR 0x0C USART2->BRR Divisor that sets the baud rate from the peripheral clock Subsection 3.3.3
USART_ISR 0x1C USART2->ISR Status flags, including TXE (ready for the next byte) and RXNE (a byte has arrived) Subsection 3.3.5
USART_RDR 0x24 USART2->RDR Holds the byte just received Subsection 3.3.5
USART_TDR 0x28 USART2->TDR Takes the byte to transmit Subsection 3.3.5
Table B.0.4. ADC1 (analog-to-digital converter), base address 0x4001 2400
Register Offset C expression Purpose Taught in
ADC_ISR 0x00 ADC1->ISR Status flags, including ADRDY (ready after enable) and EOC (conversion complete) Subsection 6.2.4
ADC_CR 0x08 ADC1->CR ADEN enables the ADC; ADSTART starts a conversion Subsection 6.2.4
ADC_CFGR1 0x0C ADC1->CFGR1 RES selects 12-, 10-, 8- or 6-bit resolution; writable only while ADEN is 0 Subsection 6.2.8
ADC_CHSELR 0x28 ADC1->CHSELR One bit per channel selects the input to convert Subsection 6.2.2
ADC_DR 0x40 ADC1->DR The conversion result; reading it clears EOC Subsection 6.2.4
Table B.0.5. Timers TIM14 and TIM16, base address TIM14 0x4000 2000, TIM16 0x4001 4400
Register Offset C expression Purpose Taught in
TIMx_CR1 0x00 TIMx->CR1 CEN starts and stops the counter Subsection 8.2.3
TIMx_DIER 0x0C TIMx->DIER UIE lets an update event request an interrupt Subsection 8.2.6
TIMx_SR 0x10 TIMx->SR UIF is set on each update event and cleared by writing 0 Subsection 8.2.5
TIMx_EGR 0x14 TIMx->EGR UG forces an update event, which loads the prescaler before the timer starts Subsection 11.3.4
TIMx_CCMR1 0x18 TIMx->CCMR1 CC1S makes channel 1 an output; OC1M selects the PWM mode Subsection 11.3.4
TIMx_CCER 0x20 TIMx->CCER CC1E connects the output of channel 1 to its pin Subsection 11.3.3
TIMx_CNT 0x24 TIMx->CNT The current count Subsection 8.1.2
TIMx_PSC 0x28 TIMx->PSC Divides the timer clock by PSC + 1 Subsection 8.1.2
TIMx_ARR 0x2C TIMx->ARR The count at which the counter wraps to 0 and signals an update event Subsection 8.1.2
TIMx_CCR1 0x34 TIMx->CCR1 The value the count is compared against; in PWM mode it sets the duty cycle Subsection 11.3.2
Table B.0.6. EXTI (extended interrupt and event controller), base address 0x4002 1800
Register Offset C expression Purpose Taught in
EXTI_FTSR1 0x04 EXTI->FTSR1 One bit per line enables falling-edge detection Subsection 9.2.5
EXTI_FPR1 0x10 EXTI->FPR1 One bit per line records a falling edge; cleared by writing 1 Subsection 9.2.5
EXTI_EXTICR1 to EXTI_EXTICR4 0x60 to 0x6C EXTI->EXTICR[0] to EXTI->EXTICR[3] Eight bits per line select which port drives that EXTI line Subsection 9.2.4
EXTI_IMR1 0x80 EXTI->IMR1 One bit per line lets a detected edge request an interrupt Subsection 9.2.5
Table B.0.7. I2C1 (inter-integrated circuit), base address 0x4000 5400
Register Offset C expression Purpose Taught in
I2C_CR1 0x00 I2C1->CR1 PE enables the peripheral; it is cleared while TIMINGR is written Subsection 10.3.6
I2C_CR2 0x04 I2C1->CR2 Describes one transfer: target address, direction, byte count, AUTOEND and START Subsection 10.3.8
I2C_TIMINGR 0x10 I2C1->TIMINGR Sets the SCL timing: PRESC, SCLL, SCLH, SDADEL and SCLDEL Subsection 10.4.6
I2C_ISR 0x18 I2C1->ISR Status flags, including TXIS, RXNE, NACKF, TC and STOPF Subsection 10.3.8
I2C_ICR 0x1C I2C1->ICR Clears status flags by writing 1: NACKCF and STOPCF Subsection 10.3.8
I2C_RXDR 0x24 I2C1->RXDR The byte received Subsection 10.3.8
I2C_TXDR 0x28 I2C1->TXDR The byte to transmit Subsection 10.3.8
Table B.0.8. PWR (power control) and IWDG (independent watchdog), base address PWR 0x4000 7000, IWDG 0x4000 3000
Register Offset C expression Purpose Taught in
PWR_CR1 0x00 PWR->CR1 LPMS selects the low-power mode that deep sleep enters Subsection 16.1.2
IWDG_KR 0x00 IWDG->KR Key register: 0xCCCC starts the watchdog, 0x5555 unlocks PR and RLR, 0xAAAA reloads the counter Subsection 16.1.3
IWDG_PR 0x04 IWDG->PR Prescaler on the watchdog clock Subsection 16.1.3
IWDG_RLR 0x08 IWDG->RLR Reload value, which sets the timeout Subsection 16.1.3
IWDG_SR 0x0C IWDG->SR PVU and RVU are set while a new PR or RLR value is being loaded Subsection 16.1.3
Four of the registers the course code uses belong to the Arm Cortex-M0+ processor core rather than to a peripheral, so RM0490 does not describe them; they are defined in the CMSIS (Common Microcontroller Software Interface Standard) core header core_cm0plus.h. The course code enables an interrupt line in the NVIC (nested vectored interrupt controller) with the CMSIS function NVIC_EnableIRQ() rather than writing NVIC->ISER directly. Because the core registers are not offsets from a peripheral base address, their table gives each register’s absolute address.
Table B.0.9. Cortex-M0+ core registers
Register Address C expression Purpose Taught in
NVIC_ISER 0xE000 E100 NVIC_EnableIRQ() One bit per interrupt line lets that request reach the processor Subsection 8.2.6
SYST_CSR 0xE000 E010 SysTick->CTRL ENABLE, TICKINT and CLKSOURCE start the tick and its interrupt Subsection 11.5.4
SYST_RVR 0xE000 E014 SysTick->LOAD Reload value; 12000 − 1 gives a 1 ms tick at 12 MHz Subsection 11.5.4
SCB_SCR 0xE000 ED10 SCB->SCR SLEEPDEEP makes WFI enter deep sleep instead of Sleep mode Subsection 16.1.2