mbed-dev library fork for STM32F100R6 microcontroller (LQFP64, 24MHz, 32kB flash, 4kB ram, 2-channel DAC, HDMI CEC, very cheap) . Use in online compiler (instead mbed library) with selected platform Nucleo F103RB.

Fork of mbed-dev by mbed official




Tested and working:

  • blink
  • system frequency 24Mhz (with external xtal 8Mhz)
  • stdio uart on pins PA_2-PA_3
  • Serial on pins PA_9-PA_10
  • AnalogOut on pins PA_4, PA_5 (DAC)
  • AnalogIn on pins PA_0, PA_1, PA_2, PA_3, PA_4, PA_5, PA_6, PA_7, PB_0, PB_1, PC_0, PC_1, PC_2, PC_3, PC_5, PC_5


    Notes:
  • TIM2 is used for mbed needs (eq Timer, Ticker, wait etc. )




    Simple test program:

    Import programtestF100R6

    simple tests for STM32F100R6 microcontroller with dedicated library

Committer:
mega64
Date:
Sun Mar 19 23:16:34 2017 +0000
Revision:
51:25d18ad142c8
Parent:
50:d2a4a5ee894a
fixed incompatibility with the modified mbed environment Ch.n+1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 0:9b334a45a8ff 1 /* mbed Microcontroller Library
bogdanm 0:9b334a45a8ff 2 * Copyright (c) 2006-2013 ARM Limited
bogdanm 0:9b334a45a8ff 3 *
bogdanm 0:9b334a45a8ff 4 * Licensed under the Apache License, Version 2.0 (the "License");
bogdanm 0:9b334a45a8ff 5 * you may not use this file except in compliance with the License.
bogdanm 0:9b334a45a8ff 6 * You may obtain a copy of the License at
bogdanm 0:9b334a45a8ff 7 *
bogdanm 0:9b334a45a8ff 8 * http://www.apache.org/licenses/LICENSE-2.0
bogdanm 0:9b334a45a8ff 9 *
bogdanm 0:9b334a45a8ff 10 * Unless required by applicable law or agreed to in writing, software
bogdanm 0:9b334a45a8ff 11 * distributed under the License is distributed on an "AS IS" BASIS,
bogdanm 0:9b334a45a8ff 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
bogdanm 0:9b334a45a8ff 13 * See the License for the specific language governing permissions and
bogdanm 0:9b334a45a8ff 14 * limitations under the License.
bogdanm 0:9b334a45a8ff 15 */
bogdanm 0:9b334a45a8ff 16 #ifndef MBED_SERIALBASE_H
bogdanm 0:9b334a45a8ff 17 #define MBED_SERIALBASE_H
bogdanm 0:9b334a45a8ff 18
bogdanm 0:9b334a45a8ff 19 #include "platform.h"
bogdanm 0:9b334a45a8ff 20
mega64 50:d2a4a5ee894a 21 // for 100F6 not implemented (N.S.)
mega64 50:d2a4a5ee894a 22 #undef DEVICE_SERIAL_ASYNCH
mega64 50:d2a4a5ee894a 23
mega64 50:d2a4a5ee894a 24 // for 100F6 not implemented (N.S.)
mega64 50:d2a4a5ee894a 25 #undef DEVICE_SERIAL_FC
mega64 50:d2a4a5ee894a 26
mega64 50:d2a4a5ee894a 27
mega64 50:d2a4a5ee894a 28
bogdanm 0:9b334a45a8ff 29 #if DEVICE_SERIAL
bogdanm 0:9b334a45a8ff 30
bogdanm 0:9b334a45a8ff 31 #include "Stream.h"
bogdanm 0:9b334a45a8ff 32 #include "FunctionPointer.h"
bogdanm 0:9b334a45a8ff 33 #include "serial_api.h"
bogdanm 0:9b334a45a8ff 34
bogdanm 0:9b334a45a8ff 35 #if DEVICE_SERIAL_ASYNCH
bogdanm 0:9b334a45a8ff 36 #include "CThunk.h"
bogdanm 0:9b334a45a8ff 37 #include "dma_api.h"
bogdanm 0:9b334a45a8ff 38 #endif
bogdanm 0:9b334a45a8ff 39
bogdanm 0:9b334a45a8ff 40 namespace mbed {
bogdanm 0:9b334a45a8ff 41
bogdanm 0:9b334a45a8ff 42 /** A base class for serial port implementations
bogdanm 0:9b334a45a8ff 43 * Can't be instantiated directly (use Serial or RawSerial)
bogdanm 0:9b334a45a8ff 44 */
bogdanm 0:9b334a45a8ff 45 class SerialBase {
bogdanm 0:9b334a45a8ff 46
bogdanm 0:9b334a45a8ff 47 public:
bogdanm 0:9b334a45a8ff 48 /** Set the baud rate of the serial port
bogdanm 0:9b334a45a8ff 49 *
bogdanm 0:9b334a45a8ff 50 * @param baudrate The baudrate of the serial port (default = 9600).
bogdanm 0:9b334a45a8ff 51 */
bogdanm 0:9b334a45a8ff 52 void baud(int baudrate);
bogdanm 0:9b334a45a8ff 53
bogdanm 0:9b334a45a8ff 54 enum Parity {
bogdanm 0:9b334a45a8ff 55 None = 0,
bogdanm 0:9b334a45a8ff 56 Odd,
bogdanm 0:9b334a45a8ff 57 Even,
bogdanm 0:9b334a45a8ff 58 Forced1,
bogdanm 0:9b334a45a8ff 59 Forced0
bogdanm 0:9b334a45a8ff 60 };
bogdanm 0:9b334a45a8ff 61
bogdanm 0:9b334a45a8ff 62 enum IrqType {
bogdanm 0:9b334a45a8ff 63 RxIrq = 0,
bogdanm 0:9b334a45a8ff 64 TxIrq
bogdanm 0:9b334a45a8ff 65 };
bogdanm 0:9b334a45a8ff 66
bogdanm 0:9b334a45a8ff 67 enum Flow {
bogdanm 0:9b334a45a8ff 68 Disabled = 0,
bogdanm 0:9b334a45a8ff 69 RTS,
bogdanm 0:9b334a45a8ff 70 CTS,
bogdanm 0:9b334a45a8ff 71 RTSCTS
bogdanm 0:9b334a45a8ff 72 };
bogdanm 0:9b334a45a8ff 73
bogdanm 0:9b334a45a8ff 74 /** Set the transmission format used by the serial port
bogdanm 0:9b334a45a8ff 75 *
bogdanm 0:9b334a45a8ff 76 * @param bits The number of bits in a word (5-8; default = 8)
bogdanm 0:9b334a45a8ff 77 * @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
bogdanm 0:9b334a45a8ff 78 * @param stop The number of stop bits (1 or 2; default = 1)
bogdanm 0:9b334a45a8ff 79 */
bogdanm 0:9b334a45a8ff 80 void format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1);
bogdanm 0:9b334a45a8ff 81
bogdanm 0:9b334a45a8ff 82 /** Determine if there is a character available to read
bogdanm 0:9b334a45a8ff 83 *
bogdanm 0:9b334a45a8ff 84 * @returns
bogdanm 0:9b334a45a8ff 85 * 1 if there is a character available to read,
bogdanm 0:9b334a45a8ff 86 * 0 otherwise
bogdanm 0:9b334a45a8ff 87 */
bogdanm 0:9b334a45a8ff 88 int readable();
bogdanm 0:9b334a45a8ff 89
bogdanm 0:9b334a45a8ff 90 /** Determine if there is space available to write a character
bogdanm 0:9b334a45a8ff 91 *
bogdanm 0:9b334a45a8ff 92 * @returns
bogdanm 0:9b334a45a8ff 93 * 1 if there is space to write a character,
bogdanm 0:9b334a45a8ff 94 * 0 otherwise
bogdanm 0:9b334a45a8ff 95 */
bogdanm 0:9b334a45a8ff 96 int writeable();
bogdanm 0:9b334a45a8ff 97
bogdanm 0:9b334a45a8ff 98 /** Attach a function to call whenever a serial interrupt is generated
bogdanm 0:9b334a45a8ff 99 *
bogdanm 0:9b334a45a8ff 100 * @param fptr A pointer to a void function, or 0 to set as none
bogdanm 0:9b334a45a8ff 101 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
bogdanm 0:9b334a45a8ff 102 */
bogdanm 0:9b334a45a8ff 103 void attach(void (*fptr)(void), IrqType type=RxIrq);
bogdanm 0:9b334a45a8ff 104
bogdanm 0:9b334a45a8ff 105 /** Attach a member function to call whenever a serial interrupt is generated
bogdanm 0:9b334a45a8ff 106 *
bogdanm 0:9b334a45a8ff 107 * @param tptr pointer to the object to call the member function on
bogdanm 0:9b334a45a8ff 108 * @param mptr pointer to the member function to be called
bogdanm 0:9b334a45a8ff 109 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
bogdanm 0:9b334a45a8ff 110 */
bogdanm 0:9b334a45a8ff 111 template<typename T>
bogdanm 0:9b334a45a8ff 112 void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
bogdanm 0:9b334a45a8ff 113 if((mptr != NULL) && (tptr != NULL)) {
bogdanm 0:9b334a45a8ff 114 _irq[type].attach(tptr, mptr);
bogdanm 0:9b334a45a8ff 115 serial_irq_set(&_serial, (SerialIrq)type, 1);
bogdanm 0:9b334a45a8ff 116 } else {
bogdanm 0:9b334a45a8ff 117 serial_irq_set(&_serial, (SerialIrq)type, 0);
bogdanm 0:9b334a45a8ff 118 }
bogdanm 0:9b334a45a8ff 119 }
bogdanm 0:9b334a45a8ff 120
bogdanm 0:9b334a45a8ff 121 /** Generate a break condition on the serial line
bogdanm 0:9b334a45a8ff 122 */
bogdanm 0:9b334a45a8ff 123 void send_break();
bogdanm 0:9b334a45a8ff 124
bogdanm 0:9b334a45a8ff 125 #if DEVICE_SERIAL_FC
bogdanm 0:9b334a45a8ff 126 /** Set the flow control type on the serial port
bogdanm 0:9b334a45a8ff 127 *
bogdanm 0:9b334a45a8ff 128 * @param type the flow control type (Disabled, RTS, CTS, RTSCTS)
bogdanm 0:9b334a45a8ff 129 * @param flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
bogdanm 0:9b334a45a8ff 130 * @param flow2 the second flow control pin (CTS for RTSCTS)
bogdanm 0:9b334a45a8ff 131 */
bogdanm 0:9b334a45a8ff 132 void set_flow_control(Flow type, PinName flow1=NC, PinName flow2=NC);
bogdanm 0:9b334a45a8ff 133 #endif
bogdanm 0:9b334a45a8ff 134
bogdanm 0:9b334a45a8ff 135 static void _irq_handler(uint32_t id, SerialIrq irq_type);
bogdanm 0:9b334a45a8ff 136
bogdanm 0:9b334a45a8ff 137 #if DEVICE_SERIAL_ASYNCH
bogdanm 0:9b334a45a8ff 138
bogdanm 0:9b334a45a8ff 139 /** Begin asynchronous write using 8bit buffer. The completition invokes registered TX event callback
bogdanm 0:9b334a45a8ff 140 *
bogdanm 0:9b334a45a8ff 141 * @param buffer The buffer where received data will be stored
bogdanm 0:9b334a45a8ff 142 * @param length The buffer length in bytes
bogdanm 0:9b334a45a8ff 143 * @param callback The event callback function
bogdanm 0:9b334a45a8ff 144 * @param event The logical OR of TX events
bogdanm 0:9b334a45a8ff 145 */
bogdanm 0:9b334a45a8ff 146 int write(const uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
bogdanm 0:9b334a45a8ff 147
bogdanm 0:9b334a45a8ff 148 /** Begin asynchronous write using 16bit buffer. The completition invokes registered TX event callback
bogdanm 0:9b334a45a8ff 149 *
bogdanm 0:9b334a45a8ff 150 * @param buffer The buffer where received data will be stored
bogdanm 0:9b334a45a8ff 151 * @param length The buffer length in bytes
bogdanm 0:9b334a45a8ff 152 * @param callback The event callback function
bogdanm 0:9b334a45a8ff 153 * @param event The logical OR of TX events
bogdanm 0:9b334a45a8ff 154 */
bogdanm 0:9b334a45a8ff 155 int write(const uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
bogdanm 0:9b334a45a8ff 156
bogdanm 0:9b334a45a8ff 157 /** Abort the on-going write transfer
bogdanm 0:9b334a45a8ff 158 */
bogdanm 0:9b334a45a8ff 159 void abort_write();
bogdanm 0:9b334a45a8ff 160
bogdanm 0:9b334a45a8ff 161 /** Begin asynchronous reading using 8bit buffer. The completition invokes registred RX event callback.
bogdanm 0:9b334a45a8ff 162 *
bogdanm 0:9b334a45a8ff 163 * @param buffer The buffer where received data will be stored
bogdanm 0:9b334a45a8ff 164 * @param length The buffer length in bytes
bogdanm 0:9b334a45a8ff 165 * @param callback The event callback function
bogdanm 0:9b334a45a8ff 166 * @param event The logical OR of RX events
bogdanm 0:9b334a45a8ff 167 * @param char_match The matching character
bogdanm 0:9b334a45a8ff 168 */
bogdanm 0:9b334a45a8ff 169 int read(uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_RX_COMPLETE, unsigned char char_match = SERIAL_RESERVED_CHAR_MATCH);
bogdanm 0:9b334a45a8ff 170
bogdanm 0:9b334a45a8ff 171 /** Begin asynchronous reading using 16bit buffer. The completition invokes registred RX event callback.
bogdanm 0:9b334a45a8ff 172 *
bogdanm 0:9b334a45a8ff 173 * @param buffer The buffer where received data will be stored
bogdanm 0:9b334a45a8ff 174 * @param length The buffer length in bytes
bogdanm 0:9b334a45a8ff 175 * @param callback The event callback function
bogdanm 0:9b334a45a8ff 176 * @param event The logical OR of RX events
bogdanm 0:9b334a45a8ff 177 * @param char_match The matching character
bogdanm 0:9b334a45a8ff 178 */
bogdanm 0:9b334a45a8ff 179 int read(uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_RX_COMPLETE, unsigned char char_match = SERIAL_RESERVED_CHAR_MATCH);
bogdanm 0:9b334a45a8ff 180
bogdanm 0:9b334a45a8ff 181 /** Abort the on-going read transfer
bogdanm 0:9b334a45a8ff 182 */
bogdanm 0:9b334a45a8ff 183 void abort_read();
bogdanm 0:9b334a45a8ff 184
bogdanm 0:9b334a45a8ff 185 /** Configure DMA usage suggestion for non-blocking TX transfers
bogdanm 0:9b334a45a8ff 186 *
bogdanm 0:9b334a45a8ff 187 * @param usage The usage DMA hint for peripheral
bogdanm 0:9b334a45a8ff 188 * @return Zero if the usage was set, -1 if a transaction is on-going
bogdanm 0:9b334a45a8ff 189 */
bogdanm 0:9b334a45a8ff 190 int set_dma_usage_tx(DMAUsage usage);
bogdanm 0:9b334a45a8ff 191
bogdanm 0:9b334a45a8ff 192 /** Configure DMA usage suggestion for non-blocking RX transfers
bogdanm 0:9b334a45a8ff 193 *
bogdanm 0:9b334a45a8ff 194 * @param usage The usage DMA hint for peripheral
bogdanm 0:9b334a45a8ff 195 * @return Zero if the usage was set, -1 if a transaction is on-going
bogdanm 0:9b334a45a8ff 196 */
bogdanm 0:9b334a45a8ff 197 int set_dma_usage_rx(DMAUsage usage);
bogdanm 0:9b334a45a8ff 198
bogdanm 0:9b334a45a8ff 199 protected:
bogdanm 0:9b334a45a8ff 200 void start_read(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event, unsigned char char_match);
bogdanm 0:9b334a45a8ff 201 void start_write(const void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event);
bogdanm 0:9b334a45a8ff 202 void interrupt_handler_asynch(void);
bogdanm 0:9b334a45a8ff 203 #endif
bogdanm 0:9b334a45a8ff 204
bogdanm 0:9b334a45a8ff 205 protected:
bogdanm 0:9b334a45a8ff 206 SerialBase(PinName tx, PinName rx);
bogdanm 0:9b334a45a8ff 207 virtual ~SerialBase() {
bogdanm 0:9b334a45a8ff 208 }
bogdanm 0:9b334a45a8ff 209
bogdanm 0:9b334a45a8ff 210 int _base_getc();
bogdanm 0:9b334a45a8ff 211 int _base_putc(int c);
bogdanm 0:9b334a45a8ff 212
bogdanm 0:9b334a45a8ff 213 #if DEVICE_SERIAL_ASYNCH
bogdanm 0:9b334a45a8ff 214 CThunk<SerialBase> _thunk_irq;
bogdanm 0:9b334a45a8ff 215 event_callback_t _tx_callback;
bogdanm 0:9b334a45a8ff 216 event_callback_t _rx_callback;
bogdanm 0:9b334a45a8ff 217 DMAUsage _tx_usage;
bogdanm 0:9b334a45a8ff 218 DMAUsage _rx_usage;
bogdanm 0:9b334a45a8ff 219 #endif
bogdanm 0:9b334a45a8ff 220
bogdanm 0:9b334a45a8ff 221 serial_t _serial;
bogdanm 0:9b334a45a8ff 222 FunctionPointer _irq[2];
bogdanm 0:9b334a45a8ff 223 int _baud;
bogdanm 0:9b334a45a8ff 224
bogdanm 0:9b334a45a8ff 225 };
bogdanm 0:9b334a45a8ff 226
bogdanm 0:9b334a45a8ff 227 } // namespace mbed
bogdanm 0:9b334a45a8ff 228
bogdanm 0:9b334a45a8ff 229 #endif
bogdanm 0:9b334a45a8ff 230
bogdanm 0:9b334a45a8ff 231 #endif