26#include <interfaces/arch_registers.h>
33#include "arch/common/drivers/serial.h"
35#ifndef USE_MOCK_PERIPHERALS
43#define N_USART_PORTS 8
45#define N_USART_PORTS 7
47#define N_USART_PORTS 6
49#define N_USART_PORTS 5
51#define N_USART_PORTS 4
53#define N_USART_PORTS 3
55#define N_USART_PORTS 2
57#define N_USART_PORTS 1
59#error "Your architecture doesn't support UART"
92 void* buffer,
size_t nBytes,
93 std::chrono::nanoseconds timeout = std::chrono::nanoseconds::zero())
96 return readImpl(buffer, nBytes, temp,
true, timeout);
110 void* buffer,
size_t nBytes,
size_t& nBytesRead,
111 std::chrono::nanoseconds timeout = std::chrono::nanoseconds::zero())
113 return readImpl(buffer, nBytes, nBytesRead,
true, timeout);
121 virtual void write(
const void* buf,
size_t nBytes) = 0;
147 virtual bool readImpl(
void* buffer,
size_t nBytes,
size_t& nBytesRead,
149 std::chrono::nanoseconds timeout) = 0;
210 unsigned int queueLen = INTERNAL_QUEUE_LENGTH);
234 [[nodiscard]]
bool read(
void* buffer,
size_t nBytes)
237 auto timeout = std::chrono::nanoseconds::zero();
238 return readImpl(buffer, nBytes, temp,
false, timeout);
251 [[nodiscard]]
bool read(
void* buffer,
size_t nBytes,
size_t& nBytesRead)
253 auto timeout = std::chrono::nanoseconds::zero();
254 return readImpl(buffer, nBytes, nBytesRead,
false, timeout);
262 void write(
const void* buf,
size_t nBytes);
276 bool writeFile(
const std::string& fileName);
334 [[nodiscard]]
bool readImpl(
void* buffer,
size_t nBytes,
size_t& nBytesRead,
336 std::chrono::nanoseconds timeout)
override;
338 miosix::FastMutex rxMutex;
339 miosix::FastMutex txMutex;
341 miosix::Thread* rxWaiter =
344 miosix::DynUnsyncQueue<char> rxQueue;
353 static constexpr unsigned int INTERNAL_QUEUE_LENGTH = 256;
405 void write(
const void* buf,
size_t nBytes);
426 [[nodiscard]]
bool readImpl(
void* buffer,
size_t nBytes,
size_t& nBytesRead,
428 std::chrono::nanoseconds timeout)
override;
434 bool serialCommSetup();
436 miosix::STM32Serial* serial;
static PrintLogger getLogger(const string &name)
Wrapper for the STM32Serial driver in miosix.
void write(const void *buf, size_t nBytes)
Blocking write operation.
STM32SerialWrapper & operator=(STM32SerialWrapper &&)=delete
STM32SerialWrapper(STM32SerialWrapper &&)=delete
STM32SerialWrapper(USARTType *usart, int baudrate)
Initializes the serialPortName and initializes the default pins, which are:
~STM32SerialWrapper()
Removes the device from the list of the devices and closes the file of the device.
STM32SerialWrapper & operator=(const STM32SerialWrapper &)=delete
STM32SerialWrapper(const STM32SerialWrapper &)=delete
void writeString(const char *buffer)
Write a string to the serial, comprising the '\0' character.
Driver for STM32F4 low level USART/UART peripheral.
void setParity(ParityBit pb)
Set the presence of the parity in the data sent.
void IRQhandleInterrupt()
Interrupt handler that deals with receive and idle interrupts.
void setWordLength(WordLength wl)
Set the length of the word to 8 or to 9.
void writeString(const char *buffer)
Write a string to the serial, comprising the '\0' character.
void clearQueue()
Clears the rxQueue.
bool read(void *buffer, size_t nBytes)
Non-blocking read operation to read nBytes or till the data transfer is complete.
USART(const USART &)=delete
bool writeFile(const std::string &fileName)
Given a filename, uses the USART interface to stream the file in 1KB chunks.
USART(USARTType *usart, int baudrate, unsigned int queueLen=INTERNAL_QUEUE_LENGTH)
Automatically enables the peripheral and timer peripheral clock.
USART & operator=(const USART &)=delete
void write(const void *buf, size_t nBytes)
Blocking write operation.
void setStopBits(int stopBits)
Set the number of stop bits.
void setOversampling(bool oversampling)
Sets the Over8 bit.
void setBaudrate(int baudrate)
Set the baudrate in the BRR register.
USART & operator=(USART &&)=delete
~USART() override
Disables the flags for the generation of the interrupts, the IRQ from the NVIC, the peripheral and re...
bool read(void *buffer, size_t nBytes, size_t &nBytesRead)
Non-blocking read operation to read nBytes or till the data transfer is complete.
Abstract class that implements the interface for the USART/UART serial communication.
int id
Can be from 1 to 8, -1 is invalid.
virtual bool readBlocking(void *buffer, size_t nBytes, std::chrono::nanoseconds timeout=std::chrono::nanoseconds::zero())
Blocking read operation to read nBytes until the data transfer is complete or the timeout is reached.
virtual void writeString(const char *buffer)=0
Write a string to the serial, comprising the '\0' character.
USARTInterface(USARTType *usart, int baudrate)
Constructor of the USART in order to assign usart and baudrate.
int getId()
Returns the id of the serial.
IRQn_Type irqn
IRQ number.
virtual bool readImpl(void *buffer, size_t nBytes, size_t &nBytesRead, const bool blocking, std::chrono::nanoseconds timeout)=0
Read method implementation that supports both blocking and non-blocking mode and the return of the nu...
virtual ~USARTInterface()=0
std::string serialPortName
virtual void write(const void *buf, size_t nBytes)=0
Blocking write operation.
virtual bool readBlocking(void *buffer, size_t nBytes, size_t &nBytesRead, std::chrono::nanoseconds timeout=std::chrono::nanoseconds::zero())
Blocking read operation to read nBytes until the data transfer is complete or the timeout is reached.
This file includes all the types the logdecoder script will decode.