Prusa MINI Firmware overview
HardwareSerial Class Reference

#include <HardwareSerial.h>

Inheritance diagram for HardwareSerial:
Collaboration diagram for HardwareSerial:

Public Member Functions

 HardwareSerial (void *peripheral)
 
void begin (unsigned long baud)
 
void begin (unsigned long, uint8_t)
 
virtual int available (void)
 
virtual int peek (void)
 
virtual int read (void)
 
virtual void flush (void)
 
virtual size_t write (uint8_t)
 
 operator bool ()
 
- Public Member Functions inherited from Stream
 Stream ()
 
void setTimeout (unsigned long timeout)
 
unsigned long getTimeout (void)
 
bool find (const char *target)
 
bool find (const uint8_t *target)
 
bool find (const char *target, size_t length)
 
bool find (const uint8_t *target, size_t length)
 
bool find (char target)
 
bool findUntil (const char *target, const char *terminator)
 
bool findUntil (const uint8_t *target, const char *terminator)
 
bool findUntil (const char *target, size_t targetLen, const char *terminate, size_t termLen)
 
bool findUntil (const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
 
long parseInt (LookaheadMode lookahead=SKIP_ALL, char ignore=NO_IGNORE_CHAR)
 
float parseFloat (LookaheadMode lookahead=SKIP_ALL, char ignore=NO_IGNORE_CHAR)
 
virtual size_t readBytes (char *buffer, size_t length)
 
size_t readBytes (uint8_t *buffer, size_t length)
 
virtual size_t readBytesUntil (char terminator, char *buffer, size_t length)
 
size_t readBytesUntil (char terminator, uint8_t *buffer, size_t length)
 
String readString ()
 
String readStringUntil (char terminator)
 
- Public Member Functions inherited from Print
 Print ()
 
int getWriteError ()
 
void clearWriteError ()
 
size_t write (const char *str)
 
virtual size_t write (const uint8_t *buffer, size_t size)
 
size_t write (const char *buffer, size_t size)
 
size_t print (const __FlashStringHelper *)
 
size_t print (const String &)
 
size_t print (const char[])
 
size_t print (char)
 
size_t print (unsigned char, int=DEC)
 
size_t print (int, int=DEC)
 
size_t print (unsigned int, int=DEC)
 
size_t print (long, int=DEC)
 
size_t print (unsigned long, int=DEC)
 
size_t print (double, int=2)
 
size_t print (const Printable &)
 
size_t println (const __FlashStringHelper *)
 
size_t println (const String &s)
 
size_t println (const char[])
 
size_t println (char)
 
size_t println (unsigned char, int=DEC)
 
size_t println (int, int=DEC)
 
size_t println (unsigned int, int=DEC)
 
size_t println (long, int=DEC)
 
size_t println (unsigned long, int=DEC)
 
size_t println (double, int=2)
 
size_t println (const Printable &)
 
size_t println (void)
 
void println (int64_t, uint8_t=DEC)
 
void print (int64_t, uint8_t=DEC)
 
void println (uint64_t, uint8_t=DEC)
 
void print (uint64_t, uint8_t=DEC)
 

Additional Inherited Members

- Protected Member Functions inherited from Stream
int timedRead ()
 
int timedPeek ()
 
int peekNextDigit (LookaheadMode lookahead, bool detectDecimal)
 
long parseInt (char ignore)
 
float parseFloat (char ignore)
 
int findMulti (struct MultiTarget *targets, int tCount)
 
- Protected Member Functions inherited from Print
void setWriteError (int err=1)
 
- Protected Attributes inherited from Stream
unsigned long _timeout
 
unsigned long _startMillis
 

Constructor & Destructor Documentation

◆ HardwareSerial()

HardwareSerial::HardwareSerial ( void peripheral)
24  {
25 }

Member Function Documentation

◆ begin() [1/2]

void HardwareSerial::begin ( unsigned long  baud)
27  {
28 }

◆ begin() [2/2]

void HardwareSerial::begin ( unsigned long  baud,
uint8_t  config 
)
30  {
31 }

◆ available()

int HardwareSerial::available ( void  )
virtual

Implements Stream.

33  {
34  return rbufc;
35 }

◆ peek()

int HardwareSerial::peek ( void  )
virtual

Implements Stream.

37  {
38  return -1;
39 }

◆ read()

int HardwareSerial::read ( void  )
virtual

Implements Stream.

41  {
42  int ch = -1;
43  if (rbufc) {
44  ch = rbuff[rbufi++];
45  rbufc--;
46  }
47  if (ch == -1)
48  DBG(" rx -1");
49  else
50  DBG(" rx %02hhx %d", (uint8_t)ch, rbufc);
51  return ch;
52 }

◆ flush()

void HardwareSerial::flush ( void  )
virtual

Implements Stream.

54  {
55 }

◆ write()

size_t HardwareSerial::write ( uint8_t  c)
virtual

Implements Print.

57  {
58  static int cnt = 0;
59  static uint8_t buf[10];
60  uint8_t buf2[20] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
61  int len = 4;
62  buf[cnt++] = c;
63  if ((cnt > 2) && (buf[2] & 0x80))
64  len = 8;
65  if (cnt >= len) {
66  int retry = 3;
67  while (retry--) {
68  if (len == 4)
69  HAL_UART_Receive_DMA(&huart2, buf2, 12);
70  else if (len == 8)
71  HAL_UART_Receive_DMA(&huart2, buf2, 4);
73  if (len == 4) //
74  {
75  DBG("tx %02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3]);
76  osEvent ose;
77  if ((ose = osSignalWait(4, 100)).status == osEventSignal) {
78  DBG("signal, received %d", 12);
79  DBG("rx %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", buf2[0], buf2[1], buf2[2], buf2[3], buf2[4], buf2[5], buf2[6], buf2[7], buf2[8], buf2[9], buf2[10], buf2[11]);
80  memcpy(rbuff, buf2 + 4, 8);
81  rbufi = 0;
82  rbufc = 8;
83  retry = 0;
84  } else if (ose.status == osEventTimeout) {
85  DBG("timeout, received %d", hdma_usart2_rx.Instance->NDTR);
87  }
88  } else if (len == 8) //
89  {
90  DBG("tx %02x %02x %02x %02x %02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
91  osEvent ose;
92  if ((ose = osSignalWait(4, 100)).status == osEventSignal) {
93  DBG("signal, received %d", 4);
94  DBG("rx %02x %02x %02x %02x", buf2[0], buf2[1], buf2[2], buf2[3]);
95  memcpy(rbuff, buf2, 8);
96  rbufi = 0;
97  rbufc = 4;
98  retry = 0;
99  } else if (ose.status == osEventTimeout) {
100  DBG("timeout, received %d", hdma_usart2_rx.Instance->NDTR);
102  }
103  } else {
104  DBG("error - (len!=4) && (len!=8)");
106  }
107  }
108  cnt = 0;
109  }
110  return 1;
111 }
Here is the call graph for this function:

◆ operator bool()

HardwareSerial::operator bool ( )
113  {
114  return true;
115 }
pbuf::len
u16_t len
Definition: pbuf.h:159
__DMA_HandleTypeDef::Instance
DMA_Stream_TypeDef * Instance
Definition: stm32f4xx_hal_dma.h:157
HAL_UART_Receive_DMA
HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
hdma_usart2_rx
DMA_HandleTypeDef hdma_usart2_rx
Definition: main.c:94
huart2
UART_HandleTypeDef huart2
Definition: main.c:91
osEventTimeout
function completed; timeout occurred.
Definition: cmsis_os.h:239
osEvent::status
osStatus status
status code: event or error information
Definition: cmsis_os.h:396
osEvent
Definition: cmsis_os.h:395
rbufc
unsigned int rbufc
Definition: HardwareSerial.cpp:20
osSignalWait
osEvent osSignalWait(int32_t signals, uint32_t millisec)
Wait for one or more Signal Flags to become signaled for the current RUNNING thread.
Definition: cmsis_os.c:586
rbufi
unsigned int rbufi
Definition: HardwareSerial.cpp:21
HAL_UART_AbortReceive
HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart)
uint8_t
const uint8_t[]
Definition: 404_html.c:3
osEventSignal
function completed; signal event occurred.
Definition: cmsis_os.h:236
rbuff
uint8_t rbuff[10]
Definition: HardwareSerial.cpp:19
status
static status_t status
Definition: filament_sensor.c:37
HAL_MAX_DELAY
#define HAL_MAX_DELAY
Definition: stm32f4xx_hal_def.h:76
DBG
#define DBG(...)
Definition: HardwareSerial.cpp:12
HAL_UART_Transmit
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)