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

BSP UART Draft #72

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

BSP UART Draft #72

wants to merge 15 commits into from

Conversation

fangjim
Copy link

@fangjim fangjim commented Oct 7, 2024

image

Key considerations:
Data in UART should be tied with a Bus since UART doesn't use 'id's like other peripherals do.
Would also need to include error handling, e.g. dropped frames for UART RX

@fangjim fangjim added the question Further information is requested label Oct 7, 2024
@fangjim fangjim changed the title BSP UART functions _ BSP UART Draft Oct 7, 2024
@IshDeshpa IshDeshpa removed the question Further information is requested label Oct 7, 2024
@IshDeshpa IshDeshpa marked this pull request as draft October 7, 2024 13:52
@IshDeshpa
Copy link
Contributor

#17

@IshDeshpa IshDeshpa linked an issue Oct 7, 2024 that may be closed by this pull request
@IshDeshpa
Copy link
Contributor

IshDeshpa commented Oct 7, 2024

Make sure you know that the RX queue exists in the user code so that the user can allocate according to their needs and size of buffer. The RX queue will not be in the BSP layer itself (I know you may not have meant that by your diagram, just want to reiterate). I'd also make sure you know the specific UART interrupt handlers you will need to use. Otherwise block diagram looks good.

Copy link
Contributor

@IshDeshpa IshDeshpa left a comment

Choose a reason for hiding this comment

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

looks good other than the things I pointed out.

Comment on lines 7 to 13
#include "stm32f4xx.h"
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_def.h"
#include "stm32f4xx_hal_rcc.h"
#include "stm32f4xx_hal_gpio.h"
#include "stm32f4xx_hal_uart.h"
#include "stm32f4xx_hal_usart.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

the headers here should be system agnostic to support L4 and F4; i'd include <stm32xx_hal.h> (see how this is done in Tests/Test/blinky.c)

Copy link
Contributor

Choose a reason for hiding this comment

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

@IshDeshpa are you going for like
#ifdef STM32F4 <include F4 files> #else <include L4 files> #endif
I don't remember how your Makefile stuff was changing

Copy link
Contributor

Choose a reason for hiding this comment

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

That's what the stm32xx_hal.h does internally lol



#define TX_SIZE 60
#define RX_SIZE 60
Copy link
Contributor

Choose a reason for hiding this comment

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

RX size will be defined by the user since the RX queue will exist outside of the BSP

BSP/Inc/BSP_UART.h Outdated Show resolved Hide resolved

// Define static queues for TX and RX
static QueueHandle_t txQueue;
static QueueHandle_t rxQueue;
Copy link
Contributor

Choose a reason for hiding this comment

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

RX queue will be defined by the user.
Additionally, we need to use StaticQueue_t in order to avoid dynamically allocating the memory. See https://www.freertos.org/Documentation/02-Kernel/04-API-references/06-Queues/02-xQueueCreateStatic

@Lakshay983
Copy link
Contributor

can you check to see if the queue is full (for adding) or empty (for popping) before you do any queue accesses.

Copy link
Contributor

@IshDeshpa IshDeshpa left a comment

Choose a reason for hiding this comment

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

I'll leave a larger review after @NathanielDelgado but I've started thinking about our structure for these a bit more and honestly I'm a bit confused on it too.

Copy link
Contributor

Choose a reason for hiding this comment

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

If UART.c is the one we're using now you can delete this file.

BSP/Src/UART.c Outdated
Comment on lines 21 to 33
uart_status_t uart_init(UART_HandleTypeDef* handle, QueueHandle_t* rxQueue) {
if (handle->Instance != UART4) {
return UART_ERR;
}

// Create TX queue
tx_queue = xQueueCreateStatic(QUEUE_LENGTH,
QUEUE_ITEM_SIZE,
tx_queue_storage,
&tx_queue_buffer);

rx_queue = rxQueue;

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can just allocate the rx queues locally. See Nathaniel's CAN driver for reference, but he has the little macro that allows the user to define what addresses and size for each address that they require, and then it creates the rx queues in the preprocessor step. Not sure about it though, please provide your thoughts or questions.

BSP/Inc/UART.h Outdated
Comment on lines 1 to 2
#ifndef INC_UART_H_
#define INC_UART_H_
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick. Just have it as UART_H

BSP/Src/UART.c Outdated
#include "UART.h"


#define QUEUE_LENGTH 128
Copy link
Contributor

Choose a reason for hiding this comment

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

Allow this to be overwritten, like in the CAN driver

BSP/Src/UART.c Outdated
Comment on lines 7 to 19
static UART_HandleTypeDef huart4_ = {.Instance = UART4};
UART_HandleTypeDef* huart4 = &huart4_;

// Single TX queue
static StaticQueue_t tx_queue_buffer;
static uint8_t tx_queue_storage[QUEUE_LENGTH * QUEUE_ITEM_SIZE];
static QueueHandle_t tx_queue;

// RX queue (provided by user)
static QueueHandle_t* rx_queue;


static bool initialized = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Will need these for each UART interface initialized

BSP/Src/UART.c Outdated
Comment on lines 39 to 41
// Setup interrupts
HAL_NVIC_SetPriority(UART4_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(UART4_IRQn);
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to be in the MSP function

@IshDeshpa IshDeshpa marked this pull request as ready for review January 3, 2025 23:12
@IshDeshpa
Copy link
Contributor

IshDeshpa commented Jan 6, 2025

Can you clean this up by:

  • merging in main
  • removing unnecessary files
  • supporting USART
    thanks

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.

BSP_UART
6 participants