-
Notifications
You must be signed in to change notification settings - Fork 1
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
Usart driver #64
Merged
Merged
Usart driver #64
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4dc40e9
start semaphore
Jchisholm204 326af00
usart semaphore + debug printf updates
Jchisholm204 90af477
Create launch.json
Jchisholm204 cfa1f19
wip
Jchisholm204 d951295
wip
Jchisholm204 a3e12cd
wip
Jchisholm204 d3127ed
works
Jchisholm204 58d2ace
structure
Jchisholm204 5df07a8
changing naming conventions + comments
Jchisholm204 5ea98a9
fix breaking commit
Jchisholm204 d1d1560
update returns
Jchisholm204 5af1a08
organization
Jchisholm204 bd9f983
fix last bug
Jchisholm204 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "ST-Flash", | ||
"type": "cppvsdbg", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/Tools/ST-LINK_CLI.exe", | ||
"args": [ | ||
"-P", | ||
"${workspaceFolder}/build/firmware.bin", | ||
"0x08000000", | ||
"-V", | ||
"-RST" | ||
], | ||
"stopAtEntry": false, | ||
"cwd": "${workspaceFolder}", | ||
"environment": [], | ||
"console": "integratedTerminal" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @file nvicConfig.h | ||
* @author Jacob Chisholm (Jchisholm204.github.io) | ||
* @brief | ||
* @version 0.1 | ||
* @date 2023-11-20 | ||
* | ||
* @copyright Copyright (c) 2023 | ||
* | ||
* This file exists because of some odd errors surrounding FreeRTOS and the NVIC. | ||
* | ||
* In order to avoid deadlocks within an interrupt: Do NOT exceed these parameters. | ||
* EX: | ||
* NVIC_SetPriority(USART2_IRQn, NVIC_Priority_MAX); | ||
* NVIC_SetPriority(USART2_IRQn, NVIC_Priority_MAX+5); | ||
* NVIC_SetPriority(USART2_IRQn, NVIC_Priority_MIN-10); | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
// Highest Priority that can be given to an NVIC Interrupt | ||
#define NVIC_Priority_MAX 21 | ||
// Lowest Priority that can be given to an NVIC Interrupt | ||
#define NVIC_Priority_MIN 79 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* @file interface_uart.h | ||
* @author Jacob Chisholm (Jchisholm204.github.io) | ||
* @brief uart FreeRTOS Interface with Semaphore Handler | ||
* @version 0.1 | ||
* @date 2023-11-15 | ||
* | ||
* @copyright Copyright (c) 2023 | ||
* | ||
*/ | ||
#include "hal/hal_uart.h" | ||
#include "FreeRTOS.h" | ||
#include "semphr.h" | ||
#include "stream_buffer.h" | ||
|
||
#define UART_WRITE_OK 0 | ||
#define UART_ERR_UNDEF 1 | ||
#define UART_ERR_ACC 2 | ||
|
||
|
||
/** | ||
* @brief UART port typedef | ||
* @param port The UART port (CMSIS UART typedef) | ||
* @param semaphore The semaphore controlling the UART port | ||
* @param rxbuffer The receive buffer loaded by the UART IRQ Handler | ||
* | ||
*/ | ||
typedef struct uart_t { | ||
USART_TypeDef *port; | ||
xSemaphoreHandle semaphore; | ||
StreamBufferHandle_t rxbuffer; | ||
} uart_t; | ||
|
||
// UART OS Handlers | ||
extern uart_t port_uart2; | ||
|
||
/** | ||
* @brief OS UART Setup handler | ||
* | ||
* This function should be called to initalized all onboard UART interfaces. | ||
* This function should not be called more than once. | ||
* All UART initialization should happen within this function | ||
* | ||
* Called in main | ||
* | ||
*/ | ||
extern void os_uart_setup(); | ||
|
||
|
||
/** | ||
* @brief Initialize a USART device and its Semaphore | ||
* | ||
* @param port The USART_t typedef handle | ||
* @param uart the USARTx define from CMSIS headers | ||
* @param baud USART Baud Rate | ||
*/ | ||
static void uart_send_init(uart_t *port, USART_TypeDef *uart, unsigned long baud){ | ||
port->semaphore = xSemaphoreCreateBinary(); | ||
if(port->semaphore == NULL) return; | ||
port->rxbuffer = xStreamBufferCreate(64, 1); | ||
if(port->rxbuffer == NULL) return; | ||
port->port = uart; | ||
if(port->port == NULL) return; | ||
hal_uart_init(port->port, baud); | ||
xSemaphoreGive(port->port); | ||
} | ||
|
||
|
||
// USART2 IQR Handler | ||
extern void USART2_IRQHandler(); | ||
|
||
/** | ||
* @brief Task Blocking command to send a byte over uart | ||
* | ||
* @param port The uart_t port to use (Must be initialized) | ||
* @param byte The Byte to transmit | ||
* @param timeout The amount of ticks to wait for the interface to become available | ||
*/ | ||
static inline int uart_send_blocking(uart_t *port, uint8_t byte, TickType_t timeout){ | ||
if(port == NULL) return UART_ERR_UNDEF; | ||
if(port->port == NULL) return UART_ERR_UNDEF; | ||
if(port->semaphore == NULL) return UART_ERR_UNDEF; | ||
if(xSemaphoreTake(port->semaphore, timeout) == pdTRUE){ | ||
hal_uart_write_byte(port->port, byte); | ||
xSemaphoreGive(port->semaphore); | ||
return UART_WRITE_OK; | ||
} | ||
return UART_ERR_ACC; | ||
} | ||
|
||
/** | ||
* @brief Task Blocking command to send a buffer over uart | ||
* | ||
* @param port The uart_t port to use (Must be initialized) | ||
* @param buf Data Buffer | ||
* @param len Length of Data Buffer | ||
* @param timeout The amount of ticks to wait for the interface to become available | ||
*/ | ||
static inline int uart_send_buf_blocking(uart_t *port, char* buf, size_t len, TickType_t timeout){ | ||
if(port == NULL) return UART_ERR_UNDEF; | ||
if(port->port == NULL) return UART_ERR_UNDEF; | ||
if(port->semaphore == NULL) return UART_ERR_UNDEF; | ||
if(xSemaphoreTake(port->semaphore, timeout) == pdTRUE){ | ||
hal_uart_write_buf(port->port, buf, len); | ||
xSemaphoreGive(port->semaphore); | ||
return UART_WRITE_OK; | ||
} | ||
return UART_ERR_ACC; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @file interrupts.h | ||
* @author Jacob Chisholm (https://jchisholm204.github.io/) | ||
* @brief Global definitions of all interrupt handler functions | ||
* @version 0.1 | ||
* @date 2023-11-22 | ||
* | ||
* @copyright Copyright (c) 2023 | ||
* | ||
* This file MUST be part of the main.h includes list | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
extern void TIM6_DAC_IRQHandler(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @file taskHandlers.h | ||
* @author Jacob Chisholm | ||
* @brief Global definitions of all task handlers defined in main.c | ||
* @version 0.1 | ||
* @date 2023-11-19 | ||
* | ||
* @copyright Copyright (c) 2023 | ||
* | ||
*/ | ||
|
||
#include "FreeRTOS.h" | ||
#include "FreeRTOSConfig.h" | ||
#include "task.h" | ||
|
||
// Test Task 1 | ||
extern TaskHandle_t tskh_Test1; | ||
// Blink LED example Task | ||
extern TaskHandle_t tskh_BlinkLED; | ||
// UART2 (debug) receive task handler | ||
extern TaskHandle_t tskh_USART2_Handler; | ||
|
||
extern void tsk_Test1(void *param); | ||
|
||
extern void tsk_BlinkLED(void *param); | ||
|
||
extern void tsk_USART2_Handler(void *param); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Could be replaced with an enum - not mandatory, more of a style preference. The biggest functional difference is scoping