uart working but fix send char
This commit is contained in:
112
SHAL/Include/Peripheral/UART/Reg/SHAL_UART_REG_H753ZI.h
Normal file
112
SHAL/Include/Peripheral/UART/Reg/SHAL_UART_REG_H753ZI.h
Normal file
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// Created by Luca on 9/7/2025.
|
||||
//
|
||||
|
||||
#ifndef SHAL_UART_REG_F072XB_H
|
||||
#define SHAL_UART_REG_F072XB_H
|
||||
|
||||
#include <stm32h753xx.h>
|
||||
#include <cassert>
|
||||
|
||||
#include "SHAL_UART_TYPES.h"
|
||||
|
||||
#define NUM_USART_LINES 4
|
||||
|
||||
#define SHAL_UART1 UART(1)
|
||||
#define SHAL_UART2 UART(2)
|
||||
#define SHAL_UART3 UART(3)
|
||||
#define SHAL_UART4 UART(4)
|
||||
|
||||
//Valid usart Tx and Rx pairings for STM32F072
|
||||
enum class UART_Pair_Key : uint8_t{
|
||||
//UART2
|
||||
Tx2A2_Rx2A3,
|
||||
Tx3D8_Rx3D9,
|
||||
|
||||
NUM_PAIRS,
|
||||
INVALID
|
||||
};
|
||||
|
||||
static SHAL_UART_Pair getUARTPair(const UART_Pair_Key pair){
|
||||
switch(pair){
|
||||
case UART_Pair_Key::Tx2A2_Rx2A3:
|
||||
return {USART2, GPIO_Key::A2, GPIO_Key::A3, GPIO_Alternate_Function::AF7, GPIO_Alternate_Function::AF7};
|
||||
case UART_Pair_Key::Tx3D8_Rx3D9:
|
||||
return {USART3, GPIO_Key::D8, GPIO_Key::D9, GPIO_Alternate_Function::AF7, GPIO_Alternate_Function::AF7};
|
||||
case UART_Pair_Key::NUM_PAIRS:
|
||||
case UART_Pair_Key::INVALID:
|
||||
assert(false);
|
||||
return {nullptr, GPIO_Key::INVALID, GPIO_Key::INVALID, GPIO_Alternate_Function::AF0, GPIO_Alternate_Function::AF0};
|
||||
default:
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
constexpr SHAL_UART_Enable_Register getUARTEnableReg(const UART_Pair_Key pair){
|
||||
switch(pair){
|
||||
case UART_Pair_Key::Tx2A2_Rx2A3:
|
||||
return {&RCC->APB1LENR,RCC_APB1LENR_USART2EN};
|
||||
case UART_Pair_Key::Tx3D8_Rx3D9:
|
||||
return {&RCC->APB1LENR,RCC_APB1LENR_USART3EN};
|
||||
case UART_Pair_Key::NUM_PAIRS:
|
||||
case UART_Pair_Key::INVALID:
|
||||
assert(false);
|
||||
return {nullptr, 0};
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
static SHAL_UART_Control_Register_1 getUARTControlRegister1(const UART_Pair_Key key) {
|
||||
SHAL_UART_Control_Register_1 res = {
|
||||
nullptr,
|
||||
USART_CR1_UE,
|
||||
USART_CR1_TE,
|
||||
USART_CR1_RE,
|
||||
USART_CR1_M0,
|
||||
USART_CR1_M1
|
||||
};
|
||||
|
||||
res.reg = &getUARTPair(key).USARTReg->CR1;
|
||||
return res;
|
||||
};
|
||||
|
||||
static SHAL_UART_Baud_Rate_Generation_Register getUARTBaudRateRegister(const UART_Pair_Key key) {
|
||||
SHAL_UART_Baud_Rate_Generation_Register res = {nullptr};
|
||||
|
||||
res.reg = &getUARTPair(key).USARTReg->BRR;
|
||||
return res;
|
||||
}
|
||||
|
||||
static SHAL_UART_ISR getUARTISR(const UART_Pair_Key key) { //TODO Support for multiple alternates for FIFO
|
||||
SHAL_UART_ISR res = {
|
||||
nullptr,
|
||||
USART_ISR_TXE_TXFNF,
|
||||
USART_ISR_TC,
|
||||
USART_ISR_BUSY
|
||||
};
|
||||
|
||||
res.reg = &getUARTPair(key).USARTReg->ISR;
|
||||
return res;
|
||||
}
|
||||
|
||||
static SHAL_UART_Transmit_Data_Register getUARTTransmitDataRegister(const UART_Pair_Key key) {
|
||||
return {&getUARTPair(key).USARTReg->CR1};
|
||||
}
|
||||
|
||||
static
|
||||
|
||||
constexpr uint32_t getAFMask(const GPIO_Alternate_Function mask){
|
||||
switch(mask){
|
||||
case GPIO_Alternate_Function::AF0: return 0x00;
|
||||
case GPIO_Alternate_Function::AF1: return 0x01;
|
||||
case GPIO_Alternate_Function::AF2: return 0x02;
|
||||
case GPIO_Alternate_Function::AF3: return 0x03;
|
||||
case GPIO_Alternate_Function::AF4: return 0x04;
|
||||
case GPIO_Alternate_Function::AF5: return 0x05;
|
||||
case GPIO_Alternate_Function::AF6: return 0x06;
|
||||
case GPIO_Alternate_Function::AF7: return 0x07;
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
#endif //SHMINGO_HAL_SHAL_UART_REG_F072XB_H
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
void init(UART_Pair_Key pair);
|
||||
|
||||
//begins Tx and Usart TODO either modify this function or add a new one that supports Rx
|
||||
void begin(uint32_t baudRate) volatile;
|
||||
void begin(uint32_t baudRate, SHAL_USART_Word_Length wordLength) const volatile;
|
||||
|
||||
//Sends a string
|
||||
void sendString(const char* s) volatile;
|
||||
|
||||
@@ -89,7 +89,52 @@
|
||||
#elif defined(STM32L4S7xx)
|
||||
#include "stm32l4s7xx.h"
|
||||
#elif defined(STM32L4S9xx)
|
||||
#elif defined(STM32H743xx)
|
||||
#include "stm32h743xx.h"
|
||||
#elif defined(STM32H753xx)
|
||||
#include "SHAL_UART_REG_H753ZI.h"
|
||||
#elif defined(STM32H750xx)
|
||||
#include "stm32h750xx.h"
|
||||
#elif defined(STM32H742xx)
|
||||
#include "stm32h742xx.h"
|
||||
#elif defined(STM32H745xx)
|
||||
#include "stm32h745xx.h"
|
||||
#elif defined(STM32H745xG)
|
||||
#include "stm32h745xg.h"
|
||||
#elif defined(STM32H755xx)
|
||||
#include "stm32h755xx.h"
|
||||
#elif defined(STM32H747xx)
|
||||
#include "stm32h747xx.h"
|
||||
#elif defined(STM32H747xG)
|
||||
#include "stm32h747xg.h"
|
||||
#elif defined(STM32H757xx)
|
||||
#include "stm32h757xx.h"
|
||||
#elif defined(STM32H7B0xx)
|
||||
#include "stm32h7b0xx.h"
|
||||
#elif defined(STM32H7B0xxQ)
|
||||
#include "stm32h7b0xxq.h"
|
||||
#elif defined(STM32H7A3xx)
|
||||
#include "stm32h7a3xx.h"
|
||||
#elif defined(STM32H7B3xx)
|
||||
#include "stm32h7b3xx.h"
|
||||
#elif defined(STM32H7A3xxQ)
|
||||
#include "stm32h7a3xxq.h"
|
||||
#elif defined(STM32H7B3xxQ)
|
||||
#include "stm32h7b3xxq.h"
|
||||
#elif defined(STM32H735xx)
|
||||
#include "stm32h735xx.h"
|
||||
#elif defined(STM32H733xx)
|
||||
#include "stm32h733xx.h"
|
||||
#elif defined(STM32H730xx)
|
||||
#include "stm32h730xx.h"
|
||||
#elif defined(STM32H730xxQ)
|
||||
#include "stm32h730xxq.h"
|
||||
#elif defined(STM32H725xx)
|
||||
#include "stm32h725xx.h"
|
||||
#elif defined(STM32H723xx)
|
||||
#include "stm32h723xx.h"
|
||||
#else
|
||||
|
||||
#error "Please select first the target STM32F0xx device used in your application (in stm32f0xx.h file)"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -27,21 +27,32 @@ struct SHAL_UART_Control_Register_1 {
|
||||
uint32_t usart_enable_mask;
|
||||
uint32_t transmit_enable_mask;
|
||||
uint32_t receive_enable_mask;
|
||||
uint32_t m0_mask;
|
||||
uint32_t m1_mask;
|
||||
};
|
||||
|
||||
struct SHAL_UART_Baud_Rate_Generation_Register {
|
||||
volatile uint32_t* reg;
|
||||
};
|
||||
|
||||
struct SHAL_UART_Transmit_Data_Register {
|
||||
volatile uint16_t* reg;
|
||||
};
|
||||
|
||||
struct SHAL_UART_ISR_FIFO_Disabled {
|
||||
struct SHAL_UART_ISR {
|
||||
volatile uint32_t* reg;
|
||||
uint32_t transmit_data_register_empty_mask;
|
||||
uint32_t transmission_complete_mask;
|
||||
uint32_t busy_mask;
|
||||
};
|
||||
|
||||
struct SHAL_UART_Transmit_Data_Register {
|
||||
volatile uint32_t* reg;
|
||||
};
|
||||
|
||||
enum class SHAL_USART_Word_Length : uint32_t { //See M bits for USART
|
||||
Bits_7 = 1 << 28,
|
||||
Bits_8 = 0,
|
||||
Bits_9 = 1 << 12 //Universal M bit implementation
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //SHMINGO_HAL_SHAL_UART_TYPES_H
|
||||
|
||||
Reference in New Issue
Block a user