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 Mar 16 06:15:53 2017 +0000
Revision:
146:03e976389d16
fully rebuild, now based on mbed-dev v160

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mega64 146:03e976389d16 1 /**************************************************************************//**
mega64 146:03e976389d16 2 * @file core_cmSecureAccess.h
mega64 146:03e976389d16 3 * @brief CMSIS Cortex-M Core Secure Access Header File
mega64 146:03e976389d16 4 * @version XXX
mega64 146:03e976389d16 5 * @date 10. June 2016
mega64 146:03e976389d16 6 *
mega64 146:03e976389d16 7 * @note
mega64 146:03e976389d16 8 *
mega64 146:03e976389d16 9 ******************************************************************************/
mega64 146:03e976389d16 10 /* Copyright (c) 2016 ARM LIMITED
mega64 146:03e976389d16 11
mega64 146:03e976389d16 12 All rights reserved.
mega64 146:03e976389d16 13 Redistribution and use in source and binary forms, with or without
mega64 146:03e976389d16 14 modification, are permitted provided that the following conditions are met:
mega64 146:03e976389d16 15 - Redistributions of source code must retain the above copyright
mega64 146:03e976389d16 16 notice, this list of conditions and the following disclaimer.
mega64 146:03e976389d16 17 - Redistributions in binary form must reproduce the above copyright
mega64 146:03e976389d16 18 notice, this list of conditions and the following disclaimer in the
mega64 146:03e976389d16 19 documentation and/or other materials provided with the distribution.
mega64 146:03e976389d16 20 - Neither the name of ARM nor the names of its contributors may be used
mega64 146:03e976389d16 21 to endorse or promote products derived from this software without
mega64 146:03e976389d16 22 specific prior written permission.
mega64 146:03e976389d16 23 *
mega64 146:03e976389d16 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mega64 146:03e976389d16 25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mega64 146:03e976389d16 26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
mega64 146:03e976389d16 27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
mega64 146:03e976389d16 28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
mega64 146:03e976389d16 29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
mega64 146:03e976389d16 30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mega64 146:03e976389d16 31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mega64 146:03e976389d16 32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
mega64 146:03e976389d16 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mega64 146:03e976389d16 34 POSSIBILITY OF SUCH DAMAGE.
mega64 146:03e976389d16 35 ---------------------------------------------------------------------------*/
mega64 146:03e976389d16 36
mega64 146:03e976389d16 37
mega64 146:03e976389d16 38 #ifndef __CORE_CM_SECURE_ACCESS_H
mega64 146:03e976389d16 39 #define __CORE_CM_SECURE_ACCESS_H
mega64 146:03e976389d16 40
mega64 146:03e976389d16 41
mega64 146:03e976389d16 42 /* ########################### Core Secure Access ########################### */
mega64 146:03e976389d16 43
mega64 146:03e976389d16 44 #ifdef FEATURE_UVISOR
mega64 146:03e976389d16 45 #include "uvisor-lib/uvisor-lib.h"
mega64 146:03e976389d16 46
mega64 146:03e976389d16 47 /* Secure uVisor implementation. */
mega64 146:03e976389d16 48
mega64 146:03e976389d16 49 /** Set the value at the target address.
mega64 146:03e976389d16 50 *
mega64 146:03e976389d16 51 * Equivalent to: `*address = value`.
mega64 146:03e976389d16 52 * @param address[in] Target address
mega64 146:03e976389d16 53 * @param value[in] Value to write at the address location.
mega64 146:03e976389d16 54 */
mega64 146:03e976389d16 55 #define SECURE_WRITE(address, value) \
mega64 146:03e976389d16 56 uvisor_write(public_box, UVISOR_RGW_SHARED, address, value, UVISOR_RGW_OP_WRITE, 0xFFFFFFFFUL)
mega64 146:03e976389d16 57
mega64 146:03e976389d16 58 /** Get the value at the target address.
mega64 146:03e976389d16 59 *
mega64 146:03e976389d16 60 * @param address[in] Target address
mega64 146:03e976389d16 61 * @returns The value `*address`.
mega64 146:03e976389d16 62 */
mega64 146:03e976389d16 63 #define SECURE_READ(address) \
mega64 146:03e976389d16 64 uvisor_read(public_box, UVISOR_RGW_SHARED, address, UVISOR_RGW_OP_READ, 0xFFFFFFFFUL)
mega64 146:03e976389d16 65
mega64 146:03e976389d16 66 /** Get the selected bits at the target address.
mega64 146:03e976389d16 67 *
mega64 146:03e976389d16 68 * @param address[in] Target address
mega64 146:03e976389d16 69 * @param mask[in] Bits to select out of the target address
mega64 146:03e976389d16 70 * @returns The value `*address & mask`.
mega64 146:03e976389d16 71 */
mega64 146:03e976389d16 72 #define SECURE_BITS_GET(address, mask) \
mega64 146:03e976389d16 73 UVISOR_BITS_GET(public_box, UVISOR_RGW_SHARED, address, mask)
mega64 146:03e976389d16 74
mega64 146:03e976389d16 75 /** Check the selected bits at the target address.
mega64 146:03e976389d16 76 *
mega64 146:03e976389d16 77 * @param address[in] Address at which to check the bits
mega64 146:03e976389d16 78 * @param mask[in] Bits to select out of the target address
mega64 146:03e976389d16 79 * @returns The value `((*address & mask) == mask)`.
mega64 146:03e976389d16 80 */
mega64 146:03e976389d16 81 #define SECURE_BITS_CHECK(address, mask) \
mega64 146:03e976389d16 82 UVISOR_BITS_CHECK(public_box, UVISOR_RGW_SHARED, address, mask)
mega64 146:03e976389d16 83
mega64 146:03e976389d16 84 /** Set the selected bits to 1 at the target address.
mega64 146:03e976389d16 85 *
mega64 146:03e976389d16 86 * Equivalent to: `*address |= mask`.
mega64 146:03e976389d16 87 * @param address[in] Target address
mega64 146:03e976389d16 88 * @param mask[in] Bits to select out of the target address
mega64 146:03e976389d16 89 */
mega64 146:03e976389d16 90 #define SECURE_BITS_SET(address, mask) \
mega64 146:03e976389d16 91 UVISOR_BITS_SET(public_box, UVISOR_RGW_SHARED, address, mask)
mega64 146:03e976389d16 92
mega64 146:03e976389d16 93 /** Clear the selected bits at the target address.
mega64 146:03e976389d16 94 *
mega64 146:03e976389d16 95 * Equivalent to: `*address &= ~mask`.
mega64 146:03e976389d16 96 * @param address[in] Target address
mega64 146:03e976389d16 97 * @param mask[in] Bits to select out of the target address
mega64 146:03e976389d16 98 */
mega64 146:03e976389d16 99 #define SECURE_BITS_CLEAR(address, mask) \
mega64 146:03e976389d16 100 UVISOR_BITS_CLEAR(public_box, UVISOR_RGW_SHARED, address, mask)
mega64 146:03e976389d16 101
mega64 146:03e976389d16 102 /** Set the selected bits at the target address to the given value.
mega64 146:03e976389d16 103 *
mega64 146:03e976389d16 104 * Equivalent to: `*address = (*address & ~mask) | (value & mask)`.
mega64 146:03e976389d16 105 * @param address[in] Target address
mega64 146:03e976389d16 106 * @param mask[in] Bits to select out of the target address
mega64 146:03e976389d16 107 * @param value[in] Value to write at the address location. Note: The value
mega64 146:03e976389d16 108 * must be already shifted to the correct bit position
mega64 146:03e976389d16 109 */
mega64 146:03e976389d16 110 #define SECURE_BITS_SET_VALUE(address, mask, value) \
mega64 146:03e976389d16 111 UVISOR_BITS_SET_VALUE(public_box, UVISOR_RGW_SHARED, address, mask, value)
mega64 146:03e976389d16 112
mega64 146:03e976389d16 113 /** Toggle the selected bits at the target address.
mega64 146:03e976389d16 114 *
mega64 146:03e976389d16 115 * Equivalent to: `*address ^= mask`.
mega64 146:03e976389d16 116 * @param address[in] Target address
mega64 146:03e976389d16 117 * @param mask[in] Bits to select out of the target address
mega64 146:03e976389d16 118 */
mega64 146:03e976389d16 119 #define SECURE_BITS_TOGGLE(address, mask) \
mega64 146:03e976389d16 120 UVISOR_BITS_TOGGLE(public_box, UVISOR_RGW_SHARED, address, mask)
mega64 146:03e976389d16 121
mega64 146:03e976389d16 122 #else
mega64 146:03e976389d16 123
mega64 146:03e976389d16 124 /* Insecure fallback implementation. */
mega64 146:03e976389d16 125
mega64 146:03e976389d16 126 /** Set the value at the target address.
mega64 146:03e976389d16 127 *
mega64 146:03e976389d16 128 * Equivalent to: `*address = value`.
mega64 146:03e976389d16 129 * @param address[in] Target address
mega64 146:03e976389d16 130 * @param value[in] Value to write at the address location.
mega64 146:03e976389d16 131 */
mega64 146:03e976389d16 132 #define SECURE_WRITE(address, value) \
mega64 146:03e976389d16 133 *(address) = (value)
mega64 146:03e976389d16 134
mega64 146:03e976389d16 135 /** Get the value at the target address.
mega64 146:03e976389d16 136 *
mega64 146:03e976389d16 137 * @param address[in] Target address
mega64 146:03e976389d16 138 * @returns The value `*address`.
mega64 146:03e976389d16 139 */
mega64 146:03e976389d16 140 #define SECURE_READ(address) \
mega64 146:03e976389d16 141 (*(address))
mega64 146:03e976389d16 142
mega64 146:03e976389d16 143 /** Get the selected bits at the target address.
mega64 146:03e976389d16 144 *
mega64 146:03e976389d16 145 * @param address[in] Target address
mega64 146:03e976389d16 146 * @param mask[in] Bits to select out of the target address
mega64 146:03e976389d16 147 * @returns The value `*address & mask`.
mega64 146:03e976389d16 148 */
mega64 146:03e976389d16 149 #define SECURE_BITS_GET(address, mask) \
mega64 146:03e976389d16 150 (*(address) & (mask))
mega64 146:03e976389d16 151
mega64 146:03e976389d16 152 /** Check the selected bits at the target address.
mega64 146:03e976389d16 153 *
mega64 146:03e976389d16 154 * @param address[in] Address at which to check the bits
mega64 146:03e976389d16 155 * @param mask[in] Bits to select out of the target address
mega64 146:03e976389d16 156 * @returns The value `((*address & mask) == mask)`.
mega64 146:03e976389d16 157 */
mega64 146:03e976389d16 158 #define SECURE_BITS_CHECK(address, mask) \
mega64 146:03e976389d16 159 ((*(address) & (mask)) == (mask))
mega64 146:03e976389d16 160
mega64 146:03e976389d16 161 /** Set the selected bits to 1 at the target address.
mega64 146:03e976389d16 162 *
mega64 146:03e976389d16 163 * Equivalent to: `*address |= mask`.
mega64 146:03e976389d16 164 * @param address[in] Target address
mega64 146:03e976389d16 165 * @param mask[in] Bits to select out of the target address
mega64 146:03e976389d16 166 */
mega64 146:03e976389d16 167 #define SECURE_BITS_SET(address, mask) \
mega64 146:03e976389d16 168 *(address) |= (mask)
mega64 146:03e976389d16 169
mega64 146:03e976389d16 170 /** Clear the selected bits at the target address.
mega64 146:03e976389d16 171 *
mega64 146:03e976389d16 172 * Equivalent to: `*address &= ~mask`.
mega64 146:03e976389d16 173 * @param address[in] Target address
mega64 146:03e976389d16 174 * @param mask[in] Bits to select out of the target address
mega64 146:03e976389d16 175 */
mega64 146:03e976389d16 176 #define SECURE_BITS_CLEAR(address, mask) \
mega64 146:03e976389d16 177 *(address) &= ~(mask)
mega64 146:03e976389d16 178
mega64 146:03e976389d16 179 /** Set the selected bits at the target address to the given value.
mega64 146:03e976389d16 180 *
mega64 146:03e976389d16 181 * Equivalent to: `*address = (*address & ~mask) | (value & mask)`.
mega64 146:03e976389d16 182 * @param address[in] Target address
mega64 146:03e976389d16 183 * @param mask[in] Bits to select out of the target address
mega64 146:03e976389d16 184 * @param value[in] Value to write at the address location. Note: The value
mega64 146:03e976389d16 185 * must be already shifted to the correct bit position
mega64 146:03e976389d16 186 */
mega64 146:03e976389d16 187 #define SECURE_BITS_SET_VALUE(address, mask, value) \
mega64 146:03e976389d16 188 *(address) = (*(address) & ~(mask)) | ((value) & (mask))
mega64 146:03e976389d16 189
mega64 146:03e976389d16 190 /** Toggle the selected bits at the target address.
mega64 146:03e976389d16 191 *
mega64 146:03e976389d16 192 * Equivalent to: `*address ^= mask`.
mega64 146:03e976389d16 193 * @param address[in] Target address
mega64 146:03e976389d16 194 * @param mask[in] Bits to select out of the target address
mega64 146:03e976389d16 195 */
mega64 146:03e976389d16 196 #define SECURE_BITS_TOGGLE(address, mask) \
mega64 146:03e976389d16 197 *(address) ^= (mask)
mega64 146:03e976389d16 198
mega64 146:03e976389d16 199 #endif
mega64 146:03e976389d16 200
mega64 146:03e976389d16 201 #endif /* __CORE_CM_SECURE_ACCESS_H */