mbed library sources. Supersedes mbed-src. Fixed broken STM32F1xx RTC on rtc_api.c

Dependents:   Nucleo_F103RB_RTC_battery_bkup_pwr_off_okay

Fork of mbed-dev by mbed official

Committer:
maxxir
Date:
Tue Nov 07 16:46:29 2017 +0000
Revision:
177:619788de047e
Parent:
149:156823d33999
To fix broken RTC on Nucleo_F103RB / STM32F103 BluePill etc..;  Used direct RTC register manipulation for STM32F1xx;  rtc_read() && rtc_write()  (native rtc_init() - works good);  also added stub for non-working on STM32F1xx rtc_read_subseconds().

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /* mbed Microcontroller Library
<> 144:ef7eb2e8f9f7 2 * Copyright (c) 2015-2016 Nuvoton
<> 144:ef7eb2e8f9f7 3 *
<> 144:ef7eb2e8f9f7 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 144:ef7eb2e8f9f7 5 * you may not use this file except in compliance with the License.
<> 144:ef7eb2e8f9f7 6 * You may obtain a copy of the License at
<> 144:ef7eb2e8f9f7 7 *
<> 144:ef7eb2e8f9f7 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 144:ef7eb2e8f9f7 9 *
<> 144:ef7eb2e8f9f7 10 * Unless required by applicable law or agreed to in writing, software
<> 144:ef7eb2e8f9f7 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 144:ef7eb2e8f9f7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 144:ef7eb2e8f9f7 13 * See the License for the specific language governing permissions and
<> 144:ef7eb2e8f9f7 14 * limitations under the License.
<> 144:ef7eb2e8f9f7 15 */
<> 144:ef7eb2e8f9f7 16
<> 144:ef7eb2e8f9f7 17 #include "gpio_api.h"
<> 144:ef7eb2e8f9f7 18 #include "mbed_assert.h"
<> 144:ef7eb2e8f9f7 19 #include "pinmap.h"
<> 144:ef7eb2e8f9f7 20 #include "mbed_error.h"
<> 144:ef7eb2e8f9f7 21 #include "PeripheralPins.h"
<> 144:ef7eb2e8f9f7 22
<> 144:ef7eb2e8f9f7 23 uint32_t gpio_set(PinName pin)
<> 144:ef7eb2e8f9f7 24 {
<> 144:ef7eb2e8f9f7 25 if (pin == (PinName) NC) {
<> 144:ef7eb2e8f9f7 26 return 0;
<> 144:ef7eb2e8f9f7 27 }
<> 144:ef7eb2e8f9f7 28
<> 144:ef7eb2e8f9f7 29 uint32_t pin_index = NU_PINNAME_TO_PIN(pin);
<> 144:ef7eb2e8f9f7 30
<> 144:ef7eb2e8f9f7 31 #if 1
<> 144:ef7eb2e8f9f7 32 pin_function(pin, 0 << NU_MFP_POS(pin_index));
<> 144:ef7eb2e8f9f7 33 #else
<> 144:ef7eb2e8f9f7 34 pinmap_pinout(pin, PinMap_GPIO);
<> 144:ef7eb2e8f9f7 35 #endif
<> 144:ef7eb2e8f9f7 36
<> 144:ef7eb2e8f9f7 37 return (uint32_t)(1 << pin_index); // Return the pin mask
<> 144:ef7eb2e8f9f7 38 }
<> 144:ef7eb2e8f9f7 39
<> 144:ef7eb2e8f9f7 40 void gpio_init(gpio_t *obj, PinName pin)
<> 144:ef7eb2e8f9f7 41 {
<> 144:ef7eb2e8f9f7 42 obj->pin = pin;
<> 144:ef7eb2e8f9f7 43
<> 144:ef7eb2e8f9f7 44 if (obj->pin == (PinName) NC) {
<> 144:ef7eb2e8f9f7 45 return;
<> 144:ef7eb2e8f9f7 46 }
<> 144:ef7eb2e8f9f7 47
<> 144:ef7eb2e8f9f7 48 obj->mask = gpio_set(pin);
<> 144:ef7eb2e8f9f7 49 }
<> 144:ef7eb2e8f9f7 50
<> 144:ef7eb2e8f9f7 51 void gpio_mode(gpio_t *obj, PinMode mode)
<> 144:ef7eb2e8f9f7 52 {
<> 144:ef7eb2e8f9f7 53 if (obj->pin == (PinName) NC) {
<> 144:ef7eb2e8f9f7 54 return;
<> 144:ef7eb2e8f9f7 55 }
<> 144:ef7eb2e8f9f7 56
<> 144:ef7eb2e8f9f7 57 pin_mode(obj->pin, mode);
<> 144:ef7eb2e8f9f7 58 }
<> 144:ef7eb2e8f9f7 59
<> 144:ef7eb2e8f9f7 60 void gpio_dir(gpio_t *obj, PinDirection direction)
<> 144:ef7eb2e8f9f7 61 {
<> 144:ef7eb2e8f9f7 62 if (obj->pin == (PinName) NC) {
<> 144:ef7eb2e8f9f7 63 return;
<> 144:ef7eb2e8f9f7 64 }
<> 144:ef7eb2e8f9f7 65
<> 144:ef7eb2e8f9f7 66 uint32_t pin_index = NU_PINNAME_TO_PIN(obj->pin);
<> 144:ef7eb2e8f9f7 67 uint32_t port_index = NU_PINNAME_TO_PORT(obj->pin);
<> 144:ef7eb2e8f9f7 68 GPIO_T *gpio_base = NU_PORT_BASE(port_index);
<> 144:ef7eb2e8f9f7 69
<> 144:ef7eb2e8f9f7 70 uint32_t mode_intern = GPIO_MODE_INPUT;
<> 144:ef7eb2e8f9f7 71
<> 144:ef7eb2e8f9f7 72 switch (direction) {
<> 144:ef7eb2e8f9f7 73 case PIN_INPUT:
<> 144:ef7eb2e8f9f7 74 mode_intern = GPIO_MODE_INPUT;
<> 144:ef7eb2e8f9f7 75 break;
<> 144:ef7eb2e8f9f7 76
<> 144:ef7eb2e8f9f7 77 case PIN_OUTPUT:
<> 144:ef7eb2e8f9f7 78 mode_intern = GPIO_MODE_OUTPUT;
<> 144:ef7eb2e8f9f7 79 break;
<> 144:ef7eb2e8f9f7 80
<> 144:ef7eb2e8f9f7 81 default:
<> 144:ef7eb2e8f9f7 82 return;
<> 144:ef7eb2e8f9f7 83 }
<> 144:ef7eb2e8f9f7 84
<> 144:ef7eb2e8f9f7 85 GPIO_SetMode(gpio_base, 1 << pin_index, mode_intern);
<> 144:ef7eb2e8f9f7 86 }