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) 2017 ARM Limited
mega64 146:03e976389d16 3 *
mega64 146:03e976389d16 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
mega64 146:03e976389d16 5 * of this software and associated documentation files (the "Software"), to deal
mega64 146:03e976389d16 6 * in the Software without restriction, including without limitation the rights
mega64 146:03e976389d16 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mega64 146:03e976389d16 8 * copies of the Software, and to permit persons to whom the Software is
mega64 146:03e976389d16 9 * furnished to do so, subject to the following conditions:
mega64 146:03e976389d16 10 *
mega64 146:03e976389d16 11 * The above copyright notice and this permission notice shall be included in
mega64 146:03e976389d16 12 * all copies or substantial portions of the Software.
mega64 146:03e976389d16 13 *
mega64 146:03e976389d16 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mega64 146:03e976389d16 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mega64 146:03e976389d16 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mega64 146:03e976389d16 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mega64 146:03e976389d16 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mega64 146:03e976389d16 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
mega64 146:03e976389d16 20 * SOFTWARE.
mega64 146:03e976389d16 21 */
mega64 146:03e976389d16 22 #ifndef MBED_FLASHIAP_H
mega64 146:03e976389d16 23 #define MBED_FLASHIAP_H
mega64 146:03e976389d16 24
mega64 146:03e976389d16 25 #ifdef DEVICE_FLASH
mega64 146:03e976389d16 26
mega64 146:03e976389d16 27 #include "flash_api.h"
mega64 146:03e976389d16 28 #include "platform/SingletonPtr.h"
mega64 146:03e976389d16 29 #include "platform/PlatformMutex.h"
mega64 146:03e976389d16 30
mega64 146:03e976389d16 31 namespace mbed {
mega64 146:03e976389d16 32
mega64 146:03e976389d16 33 /** \addtogroup drivers */
mega64 146:03e976389d16 34 /** @{*/
mega64 146:03e976389d16 35
mega64 146:03e976389d16 36 /** Flash IAP driver. It invokes flash HAL functions.
mega64 146:03e976389d16 37 *
mega64 146:03e976389d16 38 * Note Synchronization level: Thread safe
mega64 146:03e976389d16 39 */
mega64 146:03e976389d16 40 class FlashIAP {
mega64 146:03e976389d16 41 public:
mega64 146:03e976389d16 42 FlashIAP();
mega64 146:03e976389d16 43 ~FlashIAP();
mega64 146:03e976389d16 44
mega64 146:03e976389d16 45 /** Initialize a flash IAP device
mega64 146:03e976389d16 46 *
mega64 146:03e976389d16 47 * Should be called once per lifetime of the object.
mega64 146:03e976389d16 48 * @return 0 on success or a negative error code on failure
mega64 146:03e976389d16 49 */
mega64 146:03e976389d16 50 int init();
mega64 146:03e976389d16 51
mega64 146:03e976389d16 52 /** Deinitialize a flash IAP device
mega64 146:03e976389d16 53 *
mega64 146:03e976389d16 54 * @return 0 on success or a negative error code on failure
mega64 146:03e976389d16 55 */
mega64 146:03e976389d16 56 int deinit();
mega64 146:03e976389d16 57
mega64 146:03e976389d16 58 /** Read data from a flash device.
mega64 146:03e976389d16 59 *
mega64 146:03e976389d16 60 * This method invokes memcpy - reads number of bytes from the address
mega64 146:03e976389d16 61 *
mega64 146:03e976389d16 62 * @param buffer Buffer to write to
mega64 146:03e976389d16 63 * @param addr Flash address to begin reading from
mega64 146:03e976389d16 64 * @param size Size to read in bytes
mega64 146:03e976389d16 65 * @return 0 on success, negative error code on failure
mega64 146:03e976389d16 66 */
mega64 146:03e976389d16 67 int read(void *buffer, uint32_t addr, uint32_t size);
mega64 146:03e976389d16 68
mega64 146:03e976389d16 69 /** Program data to pages
mega64 146:03e976389d16 70 *
mega64 146:03e976389d16 71 * The sectors must have been erased prior to being programmed
mega64 146:03e976389d16 72 *
mega64 146:03e976389d16 73 * @param buffer Buffer of data to be written
mega64 146:03e976389d16 74 * @param addr Address of a page to begin writing to, must be a multiple of program and sector sizes
mega64 146:03e976389d16 75 * @param size Size to write in bytes, must be a multiple of program and sector sizes
mega64 146:03e976389d16 76 * @return 0 on success, negative error code on failure
mega64 146:03e976389d16 77 */
mega64 146:03e976389d16 78 int program(const void *buffer, uint32_t addr, uint32_t size);
mega64 146:03e976389d16 79
mega64 146:03e976389d16 80 /** Erase sectors
mega64 146:03e976389d16 81 *
mega64 146:03e976389d16 82 * The state of an erased sector is undefined until it has been programmed
mega64 146:03e976389d16 83 *
mega64 146:03e976389d16 84 * @param addr Address of a sector to begin erasing, must be a multiple of the sector size
mega64 146:03e976389d16 85 * @param size Size to erase in bytes, must be a multiple of the sector size
mega64 146:03e976389d16 86 * @return 0 on success, negative error code on failure
mega64 146:03e976389d16 87 */
mega64 146:03e976389d16 88 int erase(uint32_t addr, uint32_t size);
mega64 146:03e976389d16 89
mega64 146:03e976389d16 90 /** Get the sector size at the defined address
mega64 146:03e976389d16 91 *
mega64 146:03e976389d16 92 * Sector size might differ at address ranges.
mega64 146:03e976389d16 93 * An example <0-0x1000, sector size=1024; 0x10000-0x20000, size=2048>
mega64 146:03e976389d16 94 *
mega64 146:03e976389d16 95 * @param addr Address of or inside the sector to query
mega64 146:03e976389d16 96 * @return Size of a sector in bytes or MBED_FLASH_INVALID_SIZE if not mapped
mega64 146:03e976389d16 97 */
mega64 146:03e976389d16 98 uint32_t get_sector_size(uint32_t addr) const;
mega64 146:03e976389d16 99
mega64 146:03e976389d16 100 /** Get the flash start address
mega64 146:03e976389d16 101 *
mega64 146:03e976389d16 102 * @return Flash start address
mega64 146:03e976389d16 103 */
mega64 146:03e976389d16 104 uint32_t get_flash_start() const;
mega64 146:03e976389d16 105
mega64 146:03e976389d16 106 /** Get the flash size
mega64 146:03e976389d16 107 *
mega64 146:03e976389d16 108 * @return Flash size
mega64 146:03e976389d16 109 */
mega64 146:03e976389d16 110 uint32_t get_flash_size() const;
mega64 146:03e976389d16 111
mega64 146:03e976389d16 112 /** Get the program page size
mega64 146:03e976389d16 113 *
mega64 146:03e976389d16 114 * @return Size of a program page in bytes
mega64 146:03e976389d16 115 */
mega64 146:03e976389d16 116 uint32_t get_page_size() const;
mega64 146:03e976389d16 117
mega64 146:03e976389d16 118 private:
mega64 146:03e976389d16 119
mega64 146:03e976389d16 120 /** Check if address and size are aligned to a sector
mega64 146:03e976389d16 121 *
mega64 146:03e976389d16 122 * @param addr Address of block to check for alignment
mega64 146:03e976389d16 123 * @param size Size of block to check for alignment
mega64 146:03e976389d16 124 * @return true if the block is sector aligned, false otherwise
mega64 146:03e976389d16 125 */
mega64 146:03e976389d16 126 bool is_aligned_to_sector(uint32_t addr, uint32_t size);
mega64 146:03e976389d16 127
mega64 146:03e976389d16 128 flash_t _flash;
mega64 146:03e976389d16 129 static SingletonPtr<PlatformMutex> _mutex;
mega64 146:03e976389d16 130 };
mega64 146:03e976389d16 131
mega64 146:03e976389d16 132 } /* namespace mbed */
mega64 146:03e976389d16 133
mega64 146:03e976389d16 134 #endif /* DEVICE_FLASH */
mega64 146:03e976389d16 135
mega64 146:03e976389d16 136 #endif /* MBED_FLASHIAP_H */
mega64 146:03e976389d16 137
mega64 146:03e976389d16 138 /** @}*/