Skip to content

Blink Morse Code Onto LED and Communicate via UART Module. DMA Functionality is Implemented for Real Time Communication with User.

Notifications You must be signed in to change notification settings

Dipto9999/STM32-Morse_Translator

Repository files navigation

STM32 : Morse Code Translator

Contents

Overview

This was originally designed as part of a UBC Orbit Command and Data Handling (CDH) subsystem assignment. However, it has been recently redesigned to further explore embedded software development practices on the STM32 Nucleo Board.

Features

A project is implemented to blink the LD2 LED pin on the STM32L476RG and communicate with the computer terminal via UART Serial Communication. This involved sending an ASCII phrase of a specified length to a serial COM port. The morse translation of the phrase is output onto the LED.

Project Structure

STM32CubeMX

The project files were generated using the STM32CubeMX Graphical Tool Software. The project configuration can be viewed and modified in the (Morse_Translator.ioc) file.

We selected the Makefile toolchain to work with individually installed tools on the VSCode Editor.

Source Code

The (main.c) source file is modified to perform the translation and output onto the STM32 LED.

The respective header file (main.h) is modified as well to include relevant include statements, preprocessor directives, private function prototypes and constants.

Serial Communication

The UART peripheral which communicates with the user is set in blocking mode. After the user has entered an input to the intended buffer, the UART peripheral is set to echo the input to the terminal.

The user may only enter capital letters and arabic numerals to the terminal. Otherwise the void Error_Handler(); function is called to send an ERROR message and perform a software reset on the STM32 system.

The PuTTY SSH client is used to establish a terminal connection with the STM32 device as shown below. Note that the terminal clearing functionality implemented in the void newPhrase(); function is designed for the PuTTY client.

DMA Controller

Direct Memory Access (i.e. DMA) is used to receive and transmit data directly between the UART peripheral and the memory. This speeds up the operations involving the input of the phrase and the subsequent echoing of the input to the terminal. Polling (i.e. blocking) operations are implemented for UART transmissions in the setup and error handling as we intend for these to be sequential with the code execution.

The void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size); callback function for the USART2 global interrupt was implemented in the (main.c) source file. This is called when the line is idle momentarily or the data transfer is complete.

Note : STM32CubeMX initialized code was slightly modified to initialize the DMA prior to the UART peripheral. Otherwise the data would not be received in the intended buffer.

Build Tools

VSCode Editor

This project build and debug settings are specified in the (.vscode) directory. The (launch.json) and (c_cpp_properties.json) were modified to integrate the debug functionality into VSCode.

The Cortex-Debug Extension made it easier to look at variables and register contents during runtime.

Importing the System View Description from the (STM32L4x6.svd) file in the launch settings gave the ability to view the peripheral register values during runtime as well.

Flash Executable

Flashing the (Morse_Translator.elf) executable onto the STM32 Nucleo Board required the ARM GCC C Compiler, Make Automation Tool, and the Open On-Chip Debugger (OpenOCD) Debugger for Embedded Devices.

These tools were added to the System Path on the Windows OS.

The (Makefile) is modified to include the make flash command.

#######################################
# flash
#######################################
flash: all
	openocd -f interface/stlink.cfg -f target/stm32l4x.cfg -c "program $(BUILD_DIR)/$(TARGET).elf verify reset exit"

Demonstration

The videos in the Demonstration directory show the input via keyboard as well as the output on the STM32 Nucleo Board. I have embedded a low resolution compressed version below.

Compressed_Flash_Program.mp4

The following image shows the UART Communication to the terminal for the output shown in the video.

Images are sourced from STM32 Datasheets.

Credit

This project was recently modified following a UART-DMA tutorial from the Controllers Tech Youtube Channel.

About

Blink Morse Code Onto LED and Communicate via UART Module. DMA Functionality is Implemented for Real Time Communication with User.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages