Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UART Device Driver (RFD900) #20

Merged
merged 5 commits into from
Sep 27, 2023
Merged

UART Device Driver (RFD900) #20

merged 5 commits into from
Sep 27, 2023

Conversation

StanleyTang17
Copy link
Contributor

@StanleyTang17 StanleyTang17 commented Jul 10, 2023

Description

What was completed, changed, or updated?

Added a generic UART device driver for communication with RFD900 and other UART devices.

  • Receive UART data in DMA mode and save them in an internal circular buffer that the user can read from.
  • Transmit data in polling mode instead of DMA mode to avoid taking up too many DMA channels.

Why was this done (if applicable)?

This driver is mainly used to receive UART data reliably without dropping any bytes, which is achieved with the DMA RX + internal buffer combo. Since STM32 HAL does not have an internal buffer aside from DMA, there is a risk of dropping data if we don't call HAL receive in time. Using this driver, we can automatically store the data we receive in our own internal buffer for later. As long as we read from our internal buffer fast enough, we shouldn't be droppping any bytes.


Testing

What manual tests were used to validate the code?

  1. Wire up two uart channels together and verify that they can transmit to and receive from each other.
void ping_pong_test()
{
	const uint16_t buf_size = UARTDevice::BUFFER_SIZE;
	uint8_t buf[buf_size];
	uint16_t data_size = 0;

	const uint8_t max_test_iterations = 5;

	const char* ping_msg = "Ping";
	const char* pong_msg = "Pong";

	for (uint8_t test_iterations = 0; test_iterations < max_test_iterations; test_iterations++) {
		myprintf("Test Iteration #%d\r\n", test_iterations + 1);

		// Send ping
		p_uart_dev1->transmit((uint8_t*)ping_msg, strlen(ping_msg));
		myprintf("UART Device 1: ping sent.\r\n");

		// Receive ping
		data_size = 0;
		while (data_size == 0) {
			data_size = p_uart_dev2->getAvailDataSize();
			osDelay(10);
		}

		memset(buf, 0, buf_size);
		p_uart_dev2->read(buf, data_size);
		if (strcmp((char*)buf, ping_msg) == 0) {
			myprintf("UART Device 2: ping received.\r\n");
		} else {
			myprintf("UART Device 2: invalid message received.\r\n");
			break;
		}

		// Send pong
		p_uart_dev2->transmit((uint8_t*)pong_msg, strlen(pong_msg));
		myprintf("UART Device 2: pong sent.\r\n");

		// Receive pong 
		data_size = 0;
		while (data_size == 0) {
			data_size = p_uart_dev1->getAvailDataSize();
			osDelay(10);
		}

		memset(buf, 0, buf_size);
		p_uart_dev1->read(buf, data_size);
		if (strcmp((char*)buf, pong_msg) == 0) {
			myprintf("UART Device 1: pong received.\r\n");
		} else {
			myprintf("UART Device 1: invalid message received.\r\n");
			break;
		}
	}
}

Test results:
image
2. The previous test but done in ZP3.5 to make sure it's properly integrated in ZP3.5.
3. Verify that it can receive data from an actual RFD900. (Optional?).


What unit tests were used to validate the code?

Circular buffer unit tests to verify functionality.
Screenshot from 2023-09-23 14-30-07


Documentation

Milestone number and name: Fixed Wing Milestone 2

Link to Asana task: https://app.asana.com/0/1203458353737758/board

Link to Confluence documentation: https://uwarg-docs.atlassian.net/wiki/spaces/ZP/pages/2251980914/RDF+900


Reminders

  • Integration testing

  • Update confluence documentation

  • Add reviewers to the PR

  • Mention the PR in the appropriate discord channel

@StanleyTang17 StanleyTang17 marked this pull request as draft July 10, 2023 22:49
@StanleyTang17 StanleyTang17 marked this pull request as ready for review September 19, 2023 18:39
@Chrisc110
Copy link
Contributor

Looks good to me, before I approve can you just also attach a screenshot of the successful unit tests?

@StanleyTang17
Copy link
Contributor Author

Looks good to me, before I approve can you just also attach a screenshot of the successful unit tests?

Done

Copy link

@SnackkOverflowError SnackkOverflowError left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@StanleyTang17 StanleyTang17 merged commit ac757c7 into main Sep 27, 2023
2 checks passed
@DerekTang04 DerekTang04 deleted the feature/driver/uart branch May 6, 2024 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants