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_PWMOUT_H
mega64 146:03e976389d16 17 #define MBED_PWMOUT_H
mega64 146:03e976389d16 18
mega64 146:03e976389d16 19 #include "platform/platform.h"
mega64 146:03e976389d16 20
mega64 146:03e976389d16 21 #if DEVICE_PWMOUT
mega64 146:03e976389d16 22 #include "hal/pwmout_api.h"
mega64 146:03e976389d16 23 #include "platform/mbed_critical.h"
mega64 146:03e976389d16 24
mega64 146:03e976389d16 25 namespace mbed {
mega64 146:03e976389d16 26 /** \addtogroup drivers */
mega64 146:03e976389d16 27 /** @{*/
mega64 146:03e976389d16 28
mega64 146:03e976389d16 29 /** A pulse-width modulation digital output
mega64 146:03e976389d16 30 *
mega64 146:03e976389d16 31 * @Note Synchronization level: Interrupt safe
mega64 146:03e976389d16 32 *
mega64 146:03e976389d16 33 * Example
mega64 146:03e976389d16 34 * @code
mega64 146:03e976389d16 35 * // Fade a led on.
mega64 146:03e976389d16 36 * #include "mbed.h"
mega64 146:03e976389d16 37 *
mega64 146:03e976389d16 38 * PwmOut led(LED1);
mega64 146:03e976389d16 39 *
mega64 146:03e976389d16 40 * int main() {
mega64 146:03e976389d16 41 * while(1) {
mega64 146:03e976389d16 42 * led = led + 0.01;
mega64 146:03e976389d16 43 * wait(0.2);
mega64 146:03e976389d16 44 * if(led == 1.0) {
mega64 146:03e976389d16 45 * led = 0;
mega64 146:03e976389d16 46 * }
mega64 146:03e976389d16 47 * }
mega64 146:03e976389d16 48 * }
mega64 146:03e976389d16 49 * @endcode
mega64 146:03e976389d16 50 *
mega64 146:03e976389d16 51 * @note
mega64 146:03e976389d16 52 * On the LPC1768 and LPC2368, the PWMs all share the same
mega64 146:03e976389d16 53 * period - if you change the period for one, you change it for all.
mega64 146:03e976389d16 54 * Although routines that change the period maintain the duty cycle
mega64 146:03e976389d16 55 * for its PWM, all other PWMs will require their duty cycle to be
mega64 146:03e976389d16 56 * refreshed.
mega64 146:03e976389d16 57 */
mega64 146:03e976389d16 58 class PwmOut {
mega64 146:03e976389d16 59
mega64 146:03e976389d16 60 public:
mega64 146:03e976389d16 61
mega64 146:03e976389d16 62 /** Create a PwmOut connected to the specified pin
mega64 146:03e976389d16 63 *
mega64 146:03e976389d16 64 * @param pin PwmOut pin to connect to
mega64 146:03e976389d16 65 */
mega64 146:03e976389d16 66 PwmOut(PinName pin) {
mega64 146:03e976389d16 67 core_util_critical_section_enter();
mega64 146:03e976389d16 68 pwmout_init(&_pwm, pin);
mega64 146:03e976389d16 69 core_util_critical_section_exit();
mega64 146:03e976389d16 70 }
mega64 146:03e976389d16 71
mega64 146:03e976389d16 72 /** Set the ouput duty-cycle, specified as a percentage (float)
mega64 146:03e976389d16 73 *
mega64 146:03e976389d16 74 * @param value A floating-point value representing the output duty-cycle,
mega64 146:03e976389d16 75 * specified as a percentage. The value should lie between
mega64 146:03e976389d16 76 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
mega64 146:03e976389d16 77 * Values outside this range will be saturated to 0.0f or 1.0f.
mega64 146:03e976389d16 78 */
mega64 146:03e976389d16 79 void write(float value) {
mega64 146:03e976389d16 80 core_util_critical_section_enter();
mega64 146:03e976389d16 81 pwmout_write(&_pwm, value);
mega64 146:03e976389d16 82 core_util_critical_section_exit();
mega64 146:03e976389d16 83 }
mega64 146:03e976389d16 84
mega64 146:03e976389d16 85 /** Return the current output duty-cycle setting, measured as a percentage (float)
mega64 146:03e976389d16 86 *
mega64 146:03e976389d16 87 * @returns
mega64 146:03e976389d16 88 * A floating-point value representing the current duty-cycle being output on the pin,
mega64 146:03e976389d16 89 * measured as a percentage. The returned value will lie between
mega64 146:03e976389d16 90 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
mega64 146:03e976389d16 91 *
mega64 146:03e976389d16 92 * @note
mega64 146:03e976389d16 93 * This value may not match exactly the value set by a previous <write>.
mega64 146:03e976389d16 94 */
mega64 146:03e976389d16 95 float read() {
mega64 146:03e976389d16 96 core_util_critical_section_enter();
mega64 146:03e976389d16 97 float val = pwmout_read(&_pwm);
mega64 146:03e976389d16 98 core_util_critical_section_exit();
mega64 146:03e976389d16 99 return val;
mega64 146:03e976389d16 100 }
mega64 146:03e976389d16 101
mega64 146:03e976389d16 102 /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
mega64 146:03e976389d16 103 *
mega64 146:03e976389d16 104 * @note
mega64 146:03e976389d16 105 * The resolution is currently in microseconds; periods smaller than this
mega64 146:03e976389d16 106 * will be set to zero.
mega64 146:03e976389d16 107 */
mega64 146:03e976389d16 108 void period(float seconds) {
mega64 146:03e976389d16 109 core_util_critical_section_enter();
mega64 146:03e976389d16 110 pwmout_period(&_pwm, seconds);
mega64 146:03e976389d16 111 core_util_critical_section_exit();
mega64 146:03e976389d16 112 }
mega64 146:03e976389d16 113
mega64 146:03e976389d16 114 /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
mega64 146:03e976389d16 115 */
mega64 146:03e976389d16 116 void period_ms(int ms) {
mega64 146:03e976389d16 117 core_util_critical_section_enter();
mega64 146:03e976389d16 118 pwmout_period_ms(&_pwm, ms);
mega64 146:03e976389d16 119 core_util_critical_section_exit();
mega64 146:03e976389d16 120 }
mega64 146:03e976389d16 121
mega64 146:03e976389d16 122 /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
mega64 146:03e976389d16 123 */
mega64 146:03e976389d16 124 void period_us(int us) {
mega64 146:03e976389d16 125 core_util_critical_section_enter();
mega64 146:03e976389d16 126 pwmout_period_us(&_pwm, us);
mega64 146:03e976389d16 127 core_util_critical_section_exit();
mega64 146:03e976389d16 128 }
mega64 146:03e976389d16 129
mega64 146:03e976389d16 130 /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
mega64 146:03e976389d16 131 */
mega64 146:03e976389d16 132 void pulsewidth(float seconds) {
mega64 146:03e976389d16 133 core_util_critical_section_enter();
mega64 146:03e976389d16 134 pwmout_pulsewidth(&_pwm, seconds);
mega64 146:03e976389d16 135 core_util_critical_section_exit();
mega64 146:03e976389d16 136 }
mega64 146:03e976389d16 137
mega64 146:03e976389d16 138 /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
mega64 146:03e976389d16 139 */
mega64 146:03e976389d16 140 void pulsewidth_ms(int ms) {
mega64 146:03e976389d16 141 core_util_critical_section_enter();
mega64 146:03e976389d16 142 pwmout_pulsewidth_ms(&_pwm, ms);
mega64 146:03e976389d16 143 core_util_critical_section_exit();
mega64 146:03e976389d16 144 }
mega64 146:03e976389d16 145
mega64 146:03e976389d16 146 /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
mega64 146:03e976389d16 147 */
mega64 146:03e976389d16 148 void pulsewidth_us(int us) {
mega64 146:03e976389d16 149 core_util_critical_section_enter();
mega64 146:03e976389d16 150 pwmout_pulsewidth_us(&_pwm, us);
mega64 146:03e976389d16 151 core_util_critical_section_exit();
mega64 146:03e976389d16 152 }
mega64 146:03e976389d16 153
mega64 146:03e976389d16 154 /** A operator shorthand for write()
mega64 146:03e976389d16 155 */
mega64 146:03e976389d16 156 PwmOut& operator= (float value) {
mega64 146:03e976389d16 157 // Underlying call is thread safe
mega64 146:03e976389d16 158 write(value);
mega64 146:03e976389d16 159 return *this;
mega64 146:03e976389d16 160 }
mega64 146:03e976389d16 161
mega64 146:03e976389d16 162 PwmOut& operator= (PwmOut& rhs) {
mega64 146:03e976389d16 163 // Underlying call is thread safe
mega64 146:03e976389d16 164 write(rhs.read());
mega64 146:03e976389d16 165 return *this;
mega64 146:03e976389d16 166 }
mega64 146:03e976389d16 167
mega64 146:03e976389d16 168 /** An operator shorthand for read()
mega64 146:03e976389d16 169 */
mega64 146:03e976389d16 170 operator float() {
mega64 146:03e976389d16 171 // Underlying call is thread safe
mega64 146:03e976389d16 172 return read();
mega64 146:03e976389d16 173 }
mega64 146:03e976389d16 174
mega64 146:03e976389d16 175 protected:
mega64 146:03e976389d16 176 pwmout_t _pwm;
mega64 146:03e976389d16 177 };
mega64 146:03e976389d16 178
mega64 146:03e976389d16 179 } // namespace mbed
mega64 146:03e976389d16 180
mega64 146:03e976389d16 181 #endif
mega64 146:03e976389d16 182
mega64 146:03e976389d16 183 #endif
mega64 146:03e976389d16 184
mega64 146:03e976389d16 185 /** @}*/