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

Fork of mbed-dev by mbed official

Warning!

This library is unable to work due to huge changes in the mbed toolchain. Do not use with mbed online!

New wersion:

Import librarymbed-STM32F103C8

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




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 clock (mbed 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)

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

Committer:
mega64
Date:
Mon Aug 29 01:00:12 2016 +0000
Revision:
145:54b3c5994df6
Parent:
0:9b334a45a8ff
Change peripherals and pins definitions from LQFP64 to LQFP48 case.;

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-2015 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_I2C_H
bogdanm 0:9b334a45a8ff 17 #define MBED_I2C_H
bogdanm 0:9b334a45a8ff 18
bogdanm 0:9b334a45a8ff 19 #include "platform.h"
bogdanm 0:9b334a45a8ff 20
bogdanm 0:9b334a45a8ff 21 #if DEVICE_I2C
bogdanm 0:9b334a45a8ff 22
bogdanm 0:9b334a45a8ff 23 #include "i2c_api.h"
bogdanm 0:9b334a45a8ff 24
bogdanm 0:9b334a45a8ff 25 #if DEVICE_I2C_ASYNCH
bogdanm 0:9b334a45a8ff 26 #include "CThunk.h"
bogdanm 0:9b334a45a8ff 27 #include "dma_api.h"
bogdanm 0:9b334a45a8ff 28 #include "FunctionPointer.h"
bogdanm 0:9b334a45a8ff 29 #endif
bogdanm 0:9b334a45a8ff 30
bogdanm 0:9b334a45a8ff 31 namespace mbed {
bogdanm 0:9b334a45a8ff 32
bogdanm 0:9b334a45a8ff 33 /** An I2C Master, used for communicating with I2C slave devices
bogdanm 0:9b334a45a8ff 34 *
bogdanm 0:9b334a45a8ff 35 * Example:
bogdanm 0:9b334a45a8ff 36 * @code
bogdanm 0:9b334a45a8ff 37 * // Read from I2C slave at address 0x62
bogdanm 0:9b334a45a8ff 38 *
bogdanm 0:9b334a45a8ff 39 * #include "mbed.h"
bogdanm 0:9b334a45a8ff 40 *
bogdanm 0:9b334a45a8ff 41 * I2C i2c(p28, p27);
bogdanm 0:9b334a45a8ff 42 *
bogdanm 0:9b334a45a8ff 43 * int main() {
bogdanm 0:9b334a45a8ff 44 * int address = 0x62;
bogdanm 0:9b334a45a8ff 45 * char data[2];
bogdanm 0:9b334a45a8ff 46 * i2c.read(address, data, 2);
bogdanm 0:9b334a45a8ff 47 * }
bogdanm 0:9b334a45a8ff 48 * @endcode
bogdanm 0:9b334a45a8ff 49 */
bogdanm 0:9b334a45a8ff 50 class I2C {
bogdanm 0:9b334a45a8ff 51
bogdanm 0:9b334a45a8ff 52 public:
bogdanm 0:9b334a45a8ff 53 enum RxStatus {
bogdanm 0:9b334a45a8ff 54 NoData,
bogdanm 0:9b334a45a8ff 55 MasterGeneralCall,
bogdanm 0:9b334a45a8ff 56 MasterWrite,
bogdanm 0:9b334a45a8ff 57 MasterRead
bogdanm 0:9b334a45a8ff 58 };
bogdanm 0:9b334a45a8ff 59
bogdanm 0:9b334a45a8ff 60 enum Acknowledge {
bogdanm 0:9b334a45a8ff 61 NoACK = 0,
bogdanm 0:9b334a45a8ff 62 ACK = 1
bogdanm 0:9b334a45a8ff 63 };
bogdanm 0:9b334a45a8ff 64
bogdanm 0:9b334a45a8ff 65 /** Create an I2C Master interface, connected to the specified pins
bogdanm 0:9b334a45a8ff 66 *
bogdanm 0:9b334a45a8ff 67 * @param sda I2C data line pin
bogdanm 0:9b334a45a8ff 68 * @param scl I2C clock line pin
bogdanm 0:9b334a45a8ff 69 */
bogdanm 0:9b334a45a8ff 70 I2C(PinName sda, PinName scl);
bogdanm 0:9b334a45a8ff 71
bogdanm 0:9b334a45a8ff 72 /** Set the frequency of the I2C interface
bogdanm 0:9b334a45a8ff 73 *
bogdanm 0:9b334a45a8ff 74 * @param hz The bus frequency in hertz
bogdanm 0:9b334a45a8ff 75 */
bogdanm 0:9b334a45a8ff 76 void frequency(int hz);
bogdanm 0:9b334a45a8ff 77
bogdanm 0:9b334a45a8ff 78 /** Read from an I2C slave
bogdanm 0:9b334a45a8ff 79 *
bogdanm 0:9b334a45a8ff 80 * Performs a complete read transaction. The bottom bit of
bogdanm 0:9b334a45a8ff 81 * the address is forced to 1 to indicate a read.
bogdanm 0:9b334a45a8ff 82 *
bogdanm 0:9b334a45a8ff 83 * @param address 8-bit I2C slave address [ addr | 1 ]
bogdanm 0:9b334a45a8ff 84 * @param data Pointer to the byte-array to read data in to
bogdanm 0:9b334a45a8ff 85 * @param length Number of bytes to read
bogdanm 0:9b334a45a8ff 86 * @param repeated Repeated start, true - don't send stop at end
bogdanm 0:9b334a45a8ff 87 *
bogdanm 0:9b334a45a8ff 88 * @returns
bogdanm 0:9b334a45a8ff 89 * 0 on success (ack),
bogdanm 0:9b334a45a8ff 90 * non-0 on failure (nack)
bogdanm 0:9b334a45a8ff 91 */
bogdanm 0:9b334a45a8ff 92 int read(int address, char *data, int length, bool repeated = false);
bogdanm 0:9b334a45a8ff 93
bogdanm 0:9b334a45a8ff 94 /** Read a single byte from the I2C bus
bogdanm 0:9b334a45a8ff 95 *
bogdanm 0:9b334a45a8ff 96 * @param ack indicates if the byte is to be acknowledged (1 = acknowledge)
bogdanm 0:9b334a45a8ff 97 *
bogdanm 0:9b334a45a8ff 98 * @returns
bogdanm 0:9b334a45a8ff 99 * the byte read
bogdanm 0:9b334a45a8ff 100 */
bogdanm 0:9b334a45a8ff 101 int read(int ack);
bogdanm 0:9b334a45a8ff 102
bogdanm 0:9b334a45a8ff 103 /** Write to an I2C slave
bogdanm 0:9b334a45a8ff 104 *
bogdanm 0:9b334a45a8ff 105 * Performs a complete write transaction. The bottom bit of
bogdanm 0:9b334a45a8ff 106 * the address is forced to 0 to indicate a write.
bogdanm 0:9b334a45a8ff 107 *
bogdanm 0:9b334a45a8ff 108 * @param address 8-bit I2C slave address [ addr | 0 ]
bogdanm 0:9b334a45a8ff 109 * @param data Pointer to the byte-array data to send
bogdanm 0:9b334a45a8ff 110 * @param length Number of bytes to send
bogdanm 0:9b334a45a8ff 111 * @param repeated Repeated start, true - do not send stop at end
bogdanm 0:9b334a45a8ff 112 *
bogdanm 0:9b334a45a8ff 113 * @returns
bogdanm 0:9b334a45a8ff 114 * 0 on success (ack),
bogdanm 0:9b334a45a8ff 115 * non-0 on failure (nack)
bogdanm 0:9b334a45a8ff 116 */
bogdanm 0:9b334a45a8ff 117 int write(int address, const char *data, int length, bool repeated = false);
bogdanm 0:9b334a45a8ff 118
bogdanm 0:9b334a45a8ff 119 /** Write single byte out on the I2C bus
bogdanm 0:9b334a45a8ff 120 *
bogdanm 0:9b334a45a8ff 121 * @param data data to write out on bus
bogdanm 0:9b334a45a8ff 122 *
bogdanm 0:9b334a45a8ff 123 * @returns
bogdanm 0:9b334a45a8ff 124 * '1' if an ACK was received,
bogdanm 0:9b334a45a8ff 125 * '0' otherwise
bogdanm 0:9b334a45a8ff 126 */
bogdanm 0:9b334a45a8ff 127 int write(int data);
bogdanm 0:9b334a45a8ff 128
bogdanm 0:9b334a45a8ff 129 /** Creates a start condition on the I2C bus
bogdanm 0:9b334a45a8ff 130 */
bogdanm 0:9b334a45a8ff 131
bogdanm 0:9b334a45a8ff 132 void start(void);
bogdanm 0:9b334a45a8ff 133
bogdanm 0:9b334a45a8ff 134 /** Creates a stop condition on the I2C bus
bogdanm 0:9b334a45a8ff 135 */
bogdanm 0:9b334a45a8ff 136 void stop(void);
bogdanm 0:9b334a45a8ff 137
bogdanm 0:9b334a45a8ff 138 #if DEVICE_I2C_ASYNCH
bogdanm 0:9b334a45a8ff 139
bogdanm 0:9b334a45a8ff 140 /** Start non-blocking I2C transfer.
bogdanm 0:9b334a45a8ff 141 *
bogdanm 0:9b334a45a8ff 142 * @param address 8/10 bit I2c slave address
bogdanm 0:9b334a45a8ff 143 * @param tx_buffer The TX buffer with data to be transfered
bogdanm 0:9b334a45a8ff 144 * @param tx_length The length of TX buffer in bytes
bogdanm 0:9b334a45a8ff 145 * @param rx_buffer The RX buffer which is used for received data
bogdanm 0:9b334a45a8ff 146 * @param rx_length The length of RX buffer in bytes
bogdanm 0:9b334a45a8ff 147 * @param event The logical OR of events to modify
bogdanm 0:9b334a45a8ff 148 * @param callback The event callback function
bogdanm 0:9b334a45a8ff 149 * @param repeated Repeated start, true - do not send stop at end
bogdanm 0:9b334a45a8ff 150 * @return Zero if the transfer has started, or -1 if I2C peripheral is busy
bogdanm 0:9b334a45a8ff 151 */
bogdanm 0:9b334a45a8ff 152 int transfer(int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t& callback, int event = I2C_EVENT_TRANSFER_COMPLETE, bool repeated = false);
bogdanm 0:9b334a45a8ff 153
bogdanm 0:9b334a45a8ff 154 /** Abort the on-going I2C transfer
bogdanm 0:9b334a45a8ff 155 */
bogdanm 0:9b334a45a8ff 156 void abort_transfer();
bogdanm 0:9b334a45a8ff 157 protected:
bogdanm 0:9b334a45a8ff 158 void irq_handler_asynch(void);
bogdanm 0:9b334a45a8ff 159 event_callback_t _callback;
bogdanm 0:9b334a45a8ff 160 CThunk<I2C> _irq;
bogdanm 0:9b334a45a8ff 161 DMAUsage _usage;
bogdanm 0:9b334a45a8ff 162 #endif
bogdanm 0:9b334a45a8ff 163
bogdanm 0:9b334a45a8ff 164 protected:
bogdanm 0:9b334a45a8ff 165 void aquire();
bogdanm 0:9b334a45a8ff 166
bogdanm 0:9b334a45a8ff 167 i2c_t _i2c;
bogdanm 0:9b334a45a8ff 168 static I2C *_owner;
bogdanm 0:9b334a45a8ff 169 int _hz;
bogdanm 0:9b334a45a8ff 170 };
bogdanm 0:9b334a45a8ff 171
bogdanm 0:9b334a45a8ff 172 } // namespace mbed
bogdanm 0:9b334a45a8ff 173
bogdanm 0:9b334a45a8ff 174 #endif
bogdanm 0:9b334a45a8ff 175
bogdanm 0:9b334a45a8ff 176 #endif