mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Fri Sep 11 09:30:09 2015 +0100
Revision:
621:9c82b0f79f3d
Parent:
508:4f5903e025e6
Synchronized with git revision 6c1d63e069ab9bd86de92e8296ca783681257538

Full URL: https://github.com/mbedmicro/mbed/commit/6c1d63e069ab9bd86de92e8296ca783681257538/

ignore target files not supported by the yotta module

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 508:4f5903e025e6 1 /* mbed Microcontroller Library
mbed_official 508:4f5903e025e6 2 *******************************************************************************
mbed_official 508:4f5903e025e6 3 * Copyright (c) 2014, STMicroelectronics
mbed_official 508:4f5903e025e6 4 * All rights reserved.
mbed_official 508:4f5903e025e6 5 *
mbed_official 508:4f5903e025e6 6 * Redistribution and use in source and binary forms, with or without
mbed_official 508:4f5903e025e6 7 * modification, are permitted provided that the following conditions are met:
mbed_official 508:4f5903e025e6 8 *
mbed_official 508:4f5903e025e6 9 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 508:4f5903e025e6 10 * this list of conditions and the following disclaimer.
mbed_official 508:4f5903e025e6 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 508:4f5903e025e6 12 * this list of conditions and the following disclaimer in the documentation
mbed_official 508:4f5903e025e6 13 * and/or other materials provided with the distribution.
mbed_official 508:4f5903e025e6 14 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 508:4f5903e025e6 15 * may be used to endorse or promote products derived from this software
mbed_official 508:4f5903e025e6 16 * without specific prior written permission.
mbed_official 508:4f5903e025e6 17 *
mbed_official 508:4f5903e025e6 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 508:4f5903e025e6 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 508:4f5903e025e6 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 508:4f5903e025e6 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 508:4f5903e025e6 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 508:4f5903e025e6 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 508:4f5903e025e6 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 508:4f5903e025e6 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 508:4f5903e025e6 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 508:4f5903e025e6 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 508:4f5903e025e6 28 *******************************************************************************
mbed_official 508:4f5903e025e6 29 */
mbed_official 508:4f5903e025e6 30 #include "mbed_assert.h"
mbed_official 508:4f5903e025e6 31 #include "pinmap.h"
mbed_official 508:4f5903e025e6 32 #include "PortNames.h"
mbed_official 508:4f5903e025e6 33 #include "mbed_error.h"
mbed_official 508:4f5903e025e6 34
mbed_official 508:4f5903e025e6 35 // GPIO mode look-up table
mbed_official 508:4f5903e025e6 36 // Warning: the elements order must be the same as the one defined in PinNames.h
mbed_official 508:4f5903e025e6 37 static const uint32_t gpio_mode[13] = {
mbed_official 508:4f5903e025e6 38 GPIO_MODE_INPUT, // 0 = STM_MODE_INPUT
mbed_official 508:4f5903e025e6 39 GPIO_MODE_OUTPUT_PP, // 1 = STM_MODE_OUTPUT_PP
mbed_official 508:4f5903e025e6 40 GPIO_MODE_OUTPUT_OD, // 2 = STM_MODE_OUTPUT_OD
mbed_official 508:4f5903e025e6 41 GPIO_MODE_AF_PP, // 3 = STM_MODE_AF_PP
mbed_official 508:4f5903e025e6 42 GPIO_MODE_AF_OD, // 4 = STM_MODE_AF_OD
mbed_official 508:4f5903e025e6 43 GPIO_MODE_ANALOG, // 5 = STM_MODE_ANALOG
mbed_official 508:4f5903e025e6 44 GPIO_MODE_IT_RISING, // 6 = STM_MODE_IT_RISING
mbed_official 508:4f5903e025e6 45 GPIO_MODE_IT_FALLING, // 7 = STM_MODE_IT_FALLING
mbed_official 508:4f5903e025e6 46 GPIO_MODE_IT_RISING_FALLING, // 8 = STM_MODE_IT_RISING_FALLING
mbed_official 508:4f5903e025e6 47 GPIO_MODE_EVT_RISING, // 9 = STM_MODE_EVT_RISING
mbed_official 508:4f5903e025e6 48 GPIO_MODE_EVT_FALLING, // 10 = STM_MODE_EVT_FALLING
mbed_official 508:4f5903e025e6 49 GPIO_MODE_EVT_RISING_FALLING, // 11 = STM_MODE_EVT_RISING_FALLING
mbed_official 508:4f5903e025e6 50 0x10000000 // 12 = STM_MODE_IT_EVT_RESET (not in STM32Cube HAL)
mbed_official 508:4f5903e025e6 51 };
mbed_official 508:4f5903e025e6 52
mbed_official 508:4f5903e025e6 53 // Enable GPIO clock and return GPIO base address
mbed_official 508:4f5903e025e6 54 uint32_t Set_GPIO_Clock(uint32_t port_idx)
mbed_official 508:4f5903e025e6 55 {
mbed_official 508:4f5903e025e6 56 uint32_t gpio_add = 0;
mbed_official 508:4f5903e025e6 57 switch (port_idx) {
mbed_official 508:4f5903e025e6 58 case PortA:
mbed_official 508:4f5903e025e6 59 gpio_add = GPIOA_BASE;
mbed_official 508:4f5903e025e6 60 __GPIOA_CLK_ENABLE();
mbed_official 508:4f5903e025e6 61 break;
mbed_official 508:4f5903e025e6 62 case PortB:
mbed_official 508:4f5903e025e6 63 gpio_add = GPIOB_BASE;
mbed_official 508:4f5903e025e6 64 __GPIOB_CLK_ENABLE();
mbed_official 508:4f5903e025e6 65 break;
mbed_official 508:4f5903e025e6 66 case PortC:
mbed_official 508:4f5903e025e6 67 gpio_add = GPIOC_BASE;
mbed_official 508:4f5903e025e6 68 __GPIOC_CLK_ENABLE();
mbed_official 508:4f5903e025e6 69 break;
mbed_official 508:4f5903e025e6 70 case PortD:
mbed_official 508:4f5903e025e6 71 gpio_add = GPIOD_BASE;
mbed_official 508:4f5903e025e6 72 __GPIOD_CLK_ENABLE();
mbed_official 508:4f5903e025e6 73 break;
mbed_official 508:4f5903e025e6 74 #if defined(GPIOE_BASE)
mbed_official 508:4f5903e025e6 75 case PortE:
mbed_official 508:4f5903e025e6 76 gpio_add = GPIOE_BASE;
mbed_official 508:4f5903e025e6 77 __GPIOE_CLK_ENABLE();
mbed_official 508:4f5903e025e6 78 break;
mbed_official 508:4f5903e025e6 79 #endif
mbed_official 508:4f5903e025e6 80 case PortF:
mbed_official 508:4f5903e025e6 81 gpio_add = GPIOF_BASE;
mbed_official 508:4f5903e025e6 82 __GPIOF_CLK_ENABLE();
mbed_official 508:4f5903e025e6 83 break;
mbed_official 508:4f5903e025e6 84 default:
mbed_official 508:4f5903e025e6 85 error("Pinmap error: wrong port number.");
mbed_official 508:4f5903e025e6 86 break;
mbed_official 508:4f5903e025e6 87 }
mbed_official 508:4f5903e025e6 88 return gpio_add;
mbed_official 508:4f5903e025e6 89 }
mbed_official 508:4f5903e025e6 90
mbed_official 508:4f5903e025e6 91 /**
mbed_official 508:4f5903e025e6 92 * Configure pin (mode, speed, output type and pull-up/pull-down)
mbed_official 508:4f5903e025e6 93 */
mbed_official 508:4f5903e025e6 94 void pin_function(PinName pin, int data)
mbed_official 508:4f5903e025e6 95 {
mbed_official 508:4f5903e025e6 96 MBED_ASSERT(pin != (PinName)NC);
mbed_official 508:4f5903e025e6 97 // Get the pin informations
mbed_official 508:4f5903e025e6 98 uint32_t mode = STM_PIN_MODE(data);
mbed_official 508:4f5903e025e6 99 uint32_t pupd = STM_PIN_PUPD(data);
mbed_official 508:4f5903e025e6 100 uint32_t afnum = STM_PIN_AFNUM(data);
mbed_official 508:4f5903e025e6 101
mbed_official 508:4f5903e025e6 102 uint32_t port_index = STM_PORT(pin);
mbed_official 508:4f5903e025e6 103 uint32_t pin_index = STM_PIN(pin);
mbed_official 508:4f5903e025e6 104
mbed_official 508:4f5903e025e6 105 // Enable GPIO clock
mbed_official 508:4f5903e025e6 106 uint32_t gpio_add = Set_GPIO_Clock(port_index);
mbed_official 508:4f5903e025e6 107 GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
mbed_official 508:4f5903e025e6 108
mbed_official 508:4f5903e025e6 109 // Configure GPIO
mbed_official 508:4f5903e025e6 110 GPIO_InitTypeDef GPIO_InitStructure;
mbed_official 508:4f5903e025e6 111 GPIO_InitStructure.Pin = (uint32_t)(1 << pin_index);
mbed_official 508:4f5903e025e6 112 GPIO_InitStructure.Mode = gpio_mode[mode];
mbed_official 508:4f5903e025e6 113 GPIO_InitStructure.Pull = pupd;
mbed_official 508:4f5903e025e6 114 GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
mbed_official 508:4f5903e025e6 115 GPIO_InitStructure.Alternate = afnum;
mbed_official 508:4f5903e025e6 116 HAL_GPIO_Init(gpio, &GPIO_InitStructure);
mbed_official 508:4f5903e025e6 117
mbed_official 508:4f5903e025e6 118 // [TODO] Disconnect JTAG-DP + SW-DP signals.
mbed_official 508:4f5903e025e6 119 // Warning: Need to reconnect under reset
mbed_official 508:4f5903e025e6 120 //if ((pin == PA_13) || (pin == PA_14)) {
mbed_official 508:4f5903e025e6 121 //
mbed_official 508:4f5903e025e6 122 //}
mbed_official 508:4f5903e025e6 123 }
mbed_official 508:4f5903e025e6 124
mbed_official 508:4f5903e025e6 125 /**
mbed_official 508:4f5903e025e6 126 * Configure pin pull-up/pull-down
mbed_official 508:4f5903e025e6 127 */
mbed_official 508:4f5903e025e6 128 void pin_mode(PinName pin, PinMode mode)
mbed_official 508:4f5903e025e6 129 {
mbed_official 508:4f5903e025e6 130 MBED_ASSERT(pin != (PinName)NC);
mbed_official 508:4f5903e025e6 131 uint32_t port_index = STM_PORT(pin);
mbed_official 508:4f5903e025e6 132 uint32_t pin_index = STM_PIN(pin);
mbed_official 508:4f5903e025e6 133
mbed_official 508:4f5903e025e6 134 // Enable GPIO clock
mbed_official 508:4f5903e025e6 135 uint32_t gpio_add = Set_GPIO_Clock(port_index);
mbed_official 508:4f5903e025e6 136 GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
mbed_official 508:4f5903e025e6 137
mbed_official 508:4f5903e025e6 138 // Configure pull-up/pull-down resistors
mbed_official 508:4f5903e025e6 139 uint32_t pupd = (uint32_t)mode;
mbed_official 508:4f5903e025e6 140 if (pupd > 2) {
mbed_official 508:4f5903e025e6 141 pupd = 0; // Open-drain = No pull-up/No pull-down
mbed_official 508:4f5903e025e6 142 }
mbed_official 508:4f5903e025e6 143 gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
mbed_official 508:4f5903e025e6 144 gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
mbed_official 508:4f5903e025e6 145 }