A project to control LEDs connected to an STM32 microcontroller via a desktop GUI. The STM32 firmware communicates with the GUI using USB OTG, allowing users to turn LEDs on/off and set a specific toggle frequency for dynamic lighting effects.
The STM32 microcontroller is configured to:
- Enable GPIO pins for controlling LEDs.
- Activate USB-OTG in device mode using the
USB_OTG_FS
peripheral. - Use the Virtual COM Port (VCP) middleware to communicate with a host device (e.g., a PC) over USB.
- STM32 microcontroller with USB-OTG support (e.g., STM32F4 series).
- LEDs connected to GPIO pins.
- USB cable for connecting the STM32 to a host device (e.g., PC).
- STM32CubeMX for configuration and code generation.
- IDE for development (e.g., STM32CubeIDE, Keil, or VSCode).
- USB drivers for Virtual COM Port (usually installed automatically by the OS).
- Open STM32CubeMX and select your STM32 microcontroller.
- Navigate to the GPIO settings.
- Configure the GPIO pins connected to the LEDs as Output mode.
- In STM32CubeMX, go to the Connectivity section.
- Enable USB_OTG_FS in Device Only mode.
- Configure the USB settings (leave as default).
- In STM32CubeMX, go to the Middleware section.
- Enable USB_DEVICE and select Communication Device Class (Virtual COM Port).
- Click Project Manager and configure the toolchain/IDE settings (in this case, CMake is used for VSCode).
- Generate the code by clicking Generate Code.
Run the following command to generate the Makefile and create the build folder:
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=./cmake/gcc-arm-none-eabi.cmake -S./ -B./build/Debug -G "Unix Makefiles"
Build the project using the following command:
make
This will compile the code and generate the binary files in the build/debug
folder.
Flash the firmware to your STM32 board using:
make upload
This will flash the code from the build/debug
folder to your STM32 microcontroller.
Connect the STM32 to your PC via USB. Ensure that the Virtual COM Port driver is properly installed to enable communication.
- Open a terminal application on your PC (e.g., PuTTY, Tera Term).
- Connect to the Virtual COM Port assigned to the STM32.
- Send commands through the terminal to control the LEDs on the STM32 board.
- Ensure the USB cable supports data transfer (not just charging).
- Test the communication with a basic terminal command like "Hello World" to verify USB-OTG functionality.
- Use appropriate resistor values for LEDs to avoid damaging the GPIO pins.
This project is licensed under the MIT License. See the LICENSE file for details.