Modification of Mbed-dev library for LQFP48 package microcontrollers: STM32F103C8 (STM32F103C8T6) and STM32F103CB (STM32F103CBT6) (Bluepill boards, Maple mini etc. )

Fork of mbed-STM32F103C8_org by Nothing Special

Library for STM32F103C8 (Bluepill boards etc.).
Use this instead of mbed library.
This library allows the size of the code in the FLASH up to 128kB. Therefore, code also runs on microcontrollers STM32F103CB (eg. Maple mini).
But in the case of STM32F103C8, check the size of the resulting code would not exceed 64kB.

To compile a program with this library, use NUCLEO-F103RB as the target name. !

Changes:

  • Corrected initialization of the HSE + crystal clock (mbed permanent bug), allowing the use of on-board xtal (8MHz).(1)
  • Additionally, it also set USB clock (48Mhz).(2)
  • Definitions of pins and peripherals adjusted to LQFP48 case.
  • Board led LED1 is now PC_13 (3)
  • USER_BUTTON is now PC_14 (4)

    Now the library is complete rebuilt based on mbed-dev v160 (and not yet fully tested).

notes
(1) - In case 8MHz xtal on board, CPU frequency is 72MHz. Without xtal is 64MHz.
(2) - Using the USB interface is only possible if STM32 is clocking by on-board 8MHz xtal or external clock signal 8MHz on the OSC_IN pin.
(3) - On Bluepill board led operation is reversed, i.e. 0 - led on, 1 - led off.
(4) - Bluepill board has no real user button

Information

After export to SW4STM (AC6):

  • add line #include "mbed_config.h" in files Serial.h and RawSerial.h
  • in project properties change Optimisation Level to Optimise for size (-Os)
Committer:
mega64
Date:
Thu Apr 27 23:56:38 2017 +0000
Revision:
148:8b0b02bf146f
Parent:
146:03e976389d16
Remove unnecessary folders

Who changed what in which revision?

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