Skip to content

Minimal C implementation for button debouncing on STM32C031C6. Uses CubeMX only for SWD/debug and clock initialization. All GPIO configuration and toggling is done via direct memory-mapped register access.

License

Notifications You must be signed in to change notification settings

G1lbermg/STM32_NUCLEO_C031C6_ButtonDebouncing_Baremetal

Repository files navigation

Button Debouncing

STM32 NUCLEO-C031C6 Bare Metal Implementation

Bare-metal C implementation for button debouncing on the STM32C031C6. The repository contains two versions: one uses the SysTick timer to debounce using blocking methods, and the other uses the MCU's Timer 3 to debounce with two simple non-blocking state machines. Both projects utilize USART to print the button state. Initialization for clocks and debug is done via CubeMX; all other configuration (GPIO, UART, and Timers) is handled via direct memory-mapped register access. A multi-tiered error handler, is also included in each project. The handler is integrated into all BSP's and enables the system to recover gracefully from common faults and protect itself from critical ones. Depending on the user's preference, the error handler can provide error logging using USART and/or indicate critical errors with an external led.

🛠️ STM32 Nucleo Setup

Category Details
Hardware NUCLEO-C031C6 (ARM Cortex-M0+)
Debugger ST-LINK V2-1 (SWD interface)
IDE STM32CubeIDE 2.0.0
Toolchain GNU Tools for STM32 (13.3.rel1)
Libraries STM32 LL, CMSIS STM32C0xx, CMSIS STM32C031xx

💡 Implementation Versions

Version 1: Systick Timer (Blocking)

User button toggles the onboard LED. Debouncing is performed by creating a blocking delay using the Systick timer.

  • Input: PC13 (B1 USER Button)
  • Output: PA5 (Onboard User LED4)
Nucleo Button Debouncing

Version 2: Timer 3 (Non-blocking)

User button toggles the onboard LED. Debouncing is performed using Timer 3 by creating two simple non-blocking state machines.

  • Input: PC13 (B1 USER Button)
  • Output: PA5 (Onboard User LED4)
Debouncing State Machine

🚀 How to Run

  1. Import: Debounce_SysTick_Blocking or Debounce_Timer_StateMachine sub folder as STM32CubeIde project
  2. Configure: (Optional) Adjust error logging and indicator settings in error_check_utilities.h.
  3. Build & Flash: Select Project > Build, then use the Run or Debug icons.
  4. Monitor:
    • Open serial terminal and set to 9600 Baud.
    • Press Button and observe the LED toggling and messages printed to the terminal.

About

Minimal C implementation for button debouncing on STM32C031C6. Uses CubeMX only for SWD/debug and clock initialization. All GPIO configuration and toggling is done via direct memory-mapped register access.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages