Mistake on this page?
Report an issue in GitHub or email us
RawSerial.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2013 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef MBED_RAW_SERIAL_H
18 #define MBED_RAW_SERIAL_H
19 
20 #include "platform/platform.h"
21 
22 #if DEVICE_SERIAL || defined(DOXYGEN_ONLY)
23 
24 #include "mbed_toolchain.h"
25 #include "drivers/SerialBase.h"
26 #include "hal/serial_api.h"
27 #include "platform/NonCopyable.h"
28 #include <cstdarg>
29 
30 namespace mbed {
31 /** \addtogroup drivers */
32 
33 /** A serial port (UART) for communication with other serial devices
34  * This is a variation of the Serial class that doesn't use streams,
35  * thus making it safe to use in interrupt handlers with the RTOS.
36  *
37  * Can be used for Full Duplex communication, or Simplex by specifying
38  * one pin as NC (Not Connected)
39  *
40  * @note Synchronization level: Not protected
41  *
42  * Example:
43  * @code
44  * // Send a char to the PC
45  *
46  * #include "mbed.h"
47  *
48  * RawSerial pc(USBTX, USBRX);
49  *
50  * int main() {
51  * pc.putc('A');
52  * }
53  * @endcode
54  * @ingroup drivers
55  */
56 class RawSerial: public SerialBase, private NonCopyable<RawSerial> {
57 
58 public:
59  /** Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud.
60  *
61  * @param tx Transmit pin
62  * @param rx Receive pin
63  * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
64  *
65  * @note
66  * Either tx or rx may be specified as NC if unused
67  */
68  RawSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
69 
70  /** Write a char to the serial port
71  *
72  * @param c The char to write
73  *
74  * @returns The written char or -1 if an error occurred
75  */
76  int putc(int c);
77 
78  /** Read a char from the serial port
79  *
80  * @returns The char read from the serial port
81  */
82  int getc();
83 
84  /** Write a string to the serial port
85  *
86  * @param str The string to write
87  *
88  * @returns 0 if the write succeeds, EOF for error
89  */
90  int puts(const char *str);
91 
92  int printf(const char *format, ...) MBED_PRINTF_METHOD(1, 2);
93  int vprintf(const char *format, std::va_list arg);
94 
95 #if !(DOXYGEN_ONLY)
96 protected:
97 
98  /* Acquire exclusive access to this serial port
99  */
100  virtual void lock(void);
101 
102  /* Release exclusive access to this serial port
103  */
104  virtual void unlock(void);
105 #endif
106 };
107 
108 } // namespace mbed
109 
110 #endif
111 
112 #endif
void baud(int baudrate)
Set the baud rate of the serial port.
A serial port (UART) for communication with other serial devices This is a variation of the Serial cl...
Definition: RawSerial.h:56
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:168
int getc()
Read a char from the serial port.
RawSerial(PinName tx, PinName rx, int baud=MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
Create a RawSerial port, connected to the specified transmit and receive pins, with the specified bau...
int putc(int c)
Write a char to the serial port.
A base class for serial port implementations Can&#39;t be instantiated directly (use Serial or RawSerial)...
Definition: SerialBase.h:43
void format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1)
Set the transmission format used by the serial port.
int puts(const char *str)
Write a string to the serial port.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.