Skip to content

Hamo-creator/STM32_RX_Elrs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

STM32F4 CRSF Receiver with Servo Output and Failsafe

This project implements a Crossfire (CRSF) protocol receiver on an STM32F4 microcontroller using STM32CubeIDE. The receiver reads RC commands over UART and controls 4 PWM-based servos:

  • Throttle
  • Rudder
  • Elevator
  • Aileron

It also includes a failsafe mechanism to hold the last known valid RC signal in case of connection loss.


✨ Features

  • βœ… CRSF protocol parsing (OpenTX/EdgeTX compatible)
  • βœ… Maps 4 CRSF channels to servo PWM outputs
  • βœ… Uses TIM2 (CH2 & CH3) and TIM3 (CH1 & CH2) for servo control
  • βœ… Servo output in microseconds (1000–2000 Β΅s range)
  • βœ… Failsafe: holds last valid RC values after signal timeout
  • βœ… DMA-enabled UART reception for CRSF input
  • βœ… Built on STM32CubeIDE with HAL

🧠 System Overview

  • MCU: STM32F411 (or compatible STM32F4)
  • UART: UART1 @ 420000 baud (CRSF standard)
  • PWM Timers:
    • TIM2 Channel 2 β†’ Throttle
    • TIM2 Channel 3 β†’ Rudder
    • TIM3 Channel 1 β†’ Elevator
    • TIM3 Channel 2 β†’ Aileron

πŸ›  Build & Flash

  1. Clone this repository and open it with STM32CubeIDE.
  2. Connect your STM32F4 via ST-Link or compatible programmer.
  3. Build and flash the firmware using the IDE (Ctrl+B then F8).

βš™οΈ Configuration Notes

Timer Settings for PWM (1ms–2ms pulse range @ 50Hz):

  • Prescaler: 99
  • Counter Period: 19999

CRSF Input

CRSF packets are received over UART1, DMA-enabled, with idle-line detection for packet framing.


🧯 Failsafe Behavior

If no valid CRSF packet is received for a defined timeout (CRSF_PACKET_TIMEOUT_MS, default 100 ms), the system:

  • Sets failsafeActive = true
  • Maintains servo positions at their last valid state
  • Resumes normal operation upon next valid packet

πŸ“‚ File Overview

  • main.c – Initialization, loop, CRSF handling
  • crsf_serial.c/h – CRSF protocol parser
  • servo_control.c/h – PWM output control
  • tim.c – TIM2 & TIM3 setup (auto-generated by STM32CubeMX)

πŸ›©οΈ RC Channel Mapping

Channel Index Function
0 Throttle
1 Rudder
2 Elevator
3 Aileron

πŸ“Έ Demo / Video


πŸ“‹ License

MIT License


πŸ™‹β€β™‚οΈ Contact / Contributions

Issues and pull requests welcome! Feel free to fork and modify for your own aircraft or drone project.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages