mbed.h library with any bug fixes AV finds.
Dependents: micromouse4_encoder_testing PID_Test Lab1_Test WorkingPID ... more
targets/hal/TARGET_STM/TARGET_STM32F3XX/pinmap.c@1:ebce2ad32f95, 2015-11-02 (annotated)
- Committer:
- aravindsv
- Date:
- Mon Nov 02 03:07:12 2015 +0000
- Revision:
- 1:ebce2ad32f95
- Parent:
- 0:ba7650f404af
Changed the RCC timeout value to 500 ms, so total code startup time before program starts running is ~1s. Hopefully no side-effects from lower startup timeouts
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aravindsv | 0:ba7650f404af | 1 | /* mbed Microcontroller Library |
aravindsv | 0:ba7650f404af | 2 | ******************************************************************************* |
aravindsv | 0:ba7650f404af | 3 | * Copyright (c) 2014, STMicroelectronics |
aravindsv | 0:ba7650f404af | 4 | * All rights reserved. |
aravindsv | 0:ba7650f404af | 5 | * |
aravindsv | 0:ba7650f404af | 6 | * Redistribution and use in source and binary forms, with or without |
aravindsv | 0:ba7650f404af | 7 | * modification, are permitted provided that the following conditions are met: |
aravindsv | 0:ba7650f404af | 8 | * |
aravindsv | 0:ba7650f404af | 9 | * 1. Redistributions of source code must retain the above copyright notice, |
aravindsv | 0:ba7650f404af | 10 | * this list of conditions and the following disclaimer. |
aravindsv | 0:ba7650f404af | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
aravindsv | 0:ba7650f404af | 12 | * this list of conditions and the following disclaimer in the documentation |
aravindsv | 0:ba7650f404af | 13 | * and/or other materials provided with the distribution. |
aravindsv | 0:ba7650f404af | 14 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
aravindsv | 0:ba7650f404af | 15 | * may be used to endorse or promote products derived from this software |
aravindsv | 0:ba7650f404af | 16 | * without specific prior written permission. |
aravindsv | 0:ba7650f404af | 17 | * |
aravindsv | 0:ba7650f404af | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
aravindsv | 0:ba7650f404af | 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
aravindsv | 0:ba7650f404af | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
aravindsv | 0:ba7650f404af | 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
aravindsv | 0:ba7650f404af | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
aravindsv | 0:ba7650f404af | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
aravindsv | 0:ba7650f404af | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
aravindsv | 0:ba7650f404af | 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
aravindsv | 0:ba7650f404af | 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
aravindsv | 0:ba7650f404af | 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
aravindsv | 0:ba7650f404af | 28 | ******************************************************************************* |
aravindsv | 0:ba7650f404af | 29 | */ |
aravindsv | 0:ba7650f404af | 30 | #include "mbed_assert.h" |
aravindsv | 0:ba7650f404af | 31 | #include "pinmap.h" |
aravindsv | 0:ba7650f404af | 32 | #include "PortNames.h" |
aravindsv | 0:ba7650f404af | 33 | #include "mbed_error.h" |
aravindsv | 0:ba7650f404af | 34 | |
aravindsv | 0:ba7650f404af | 35 | // Enable GPIO clock and return GPIO base address |
aravindsv | 0:ba7650f404af | 36 | uint32_t Set_GPIO_Clock(uint32_t port_idx) { |
aravindsv | 0:ba7650f404af | 37 | uint32_t gpio_add; |
aravindsv | 0:ba7650f404af | 38 | switch (port_idx) { |
aravindsv | 0:ba7650f404af | 39 | case PortA: |
aravindsv | 0:ba7650f404af | 40 | gpio_add = GPIOA_BASE; |
aravindsv | 0:ba7650f404af | 41 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); |
aravindsv | 0:ba7650f404af | 42 | break; |
aravindsv | 0:ba7650f404af | 43 | case PortB: |
aravindsv | 0:ba7650f404af | 44 | gpio_add = GPIOB_BASE; |
aravindsv | 0:ba7650f404af | 45 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); |
aravindsv | 0:ba7650f404af | 46 | break; |
aravindsv | 0:ba7650f404af | 47 | case PortC: |
aravindsv | 0:ba7650f404af | 48 | gpio_add = GPIOC_BASE; |
aravindsv | 0:ba7650f404af | 49 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); |
aravindsv | 0:ba7650f404af | 50 | break; |
aravindsv | 0:ba7650f404af | 51 | case PortD: |
aravindsv | 0:ba7650f404af | 52 | gpio_add = GPIOD_BASE; |
aravindsv | 0:ba7650f404af | 53 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE); |
aravindsv | 0:ba7650f404af | 54 | break; |
aravindsv | 0:ba7650f404af | 55 | case PortE: |
aravindsv | 0:ba7650f404af | 56 | gpio_add = GPIOE_BASE; |
aravindsv | 0:ba7650f404af | 57 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE); |
aravindsv | 0:ba7650f404af | 58 | break; |
aravindsv | 0:ba7650f404af | 59 | case PortF: |
aravindsv | 0:ba7650f404af | 60 | gpio_add = GPIOF_BASE; |
aravindsv | 0:ba7650f404af | 61 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE); |
aravindsv | 0:ba7650f404af | 62 | break; |
aravindsv | 0:ba7650f404af | 63 | default: |
aravindsv | 0:ba7650f404af | 64 | gpio_add = 0; |
aravindsv | 0:ba7650f404af | 65 | error("Port number is not correct."); |
aravindsv | 0:ba7650f404af | 66 | break; |
aravindsv | 0:ba7650f404af | 67 | } |
aravindsv | 0:ba7650f404af | 68 | return gpio_add; |
aravindsv | 0:ba7650f404af | 69 | } |
aravindsv | 0:ba7650f404af | 70 | |
aravindsv | 0:ba7650f404af | 71 | /** |
aravindsv | 0:ba7650f404af | 72 | * Configure pin (mode, speed, output type and pull-up/pull-down) |
aravindsv | 0:ba7650f404af | 73 | */ |
aravindsv | 0:ba7650f404af | 74 | void pin_function(PinName pin, int data) { |
aravindsv | 0:ba7650f404af | 75 | MBED_ASSERT(pin != (PinName)NC); |
aravindsv | 0:ba7650f404af | 76 | |
aravindsv | 0:ba7650f404af | 77 | // Get the pin informations |
aravindsv | 0:ba7650f404af | 78 | uint32_t mode = STM_PIN_MODE(data); |
aravindsv | 0:ba7650f404af | 79 | uint32_t otype = STM_PIN_OTYPE(data); |
aravindsv | 0:ba7650f404af | 80 | uint32_t pupd = STM_PIN_PUPD(data); |
aravindsv | 0:ba7650f404af | 81 | uint32_t afnum = STM_PIN_AFNUM(data); |
aravindsv | 0:ba7650f404af | 82 | |
aravindsv | 0:ba7650f404af | 83 | uint32_t port_index = STM_PORT(pin); |
aravindsv | 0:ba7650f404af | 84 | uint32_t pin_index = STM_PIN(pin); |
aravindsv | 0:ba7650f404af | 85 | |
aravindsv | 0:ba7650f404af | 86 | // Enable GPIO clock |
aravindsv | 0:ba7650f404af | 87 | uint32_t gpio_add = Set_GPIO_Clock(port_index); |
aravindsv | 0:ba7650f404af | 88 | GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add; |
aravindsv | 0:ba7650f404af | 89 | |
aravindsv | 0:ba7650f404af | 90 | // Configure Alternate Function |
aravindsv | 0:ba7650f404af | 91 | // Warning: Must be done before the GPIO is initialized |
aravindsv | 0:ba7650f404af | 92 | if (afnum != 0xFF) { |
aravindsv | 0:ba7650f404af | 93 | GPIO_PinAFConfig(gpio, (uint16_t)pin_index, afnum); |
aravindsv | 0:ba7650f404af | 94 | } |
aravindsv | 0:ba7650f404af | 95 | |
aravindsv | 0:ba7650f404af | 96 | // Configure GPIO |
aravindsv | 0:ba7650f404af | 97 | GPIO_InitTypeDef GPIO_InitStructure; |
aravindsv | 0:ba7650f404af | 98 | GPIO_InitStructure.GPIO_Pin = (uint16_t)(1 << pin_index); |
aravindsv | 0:ba7650f404af | 99 | GPIO_InitStructure.GPIO_Mode = (GPIOMode_TypeDef)mode; |
aravindsv | 0:ba7650f404af | 100 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; |
aravindsv | 0:ba7650f404af | 101 | GPIO_InitStructure.GPIO_OType = (GPIOOType_TypeDef)otype; |
aravindsv | 0:ba7650f404af | 102 | GPIO_InitStructure.GPIO_PuPd = (GPIOPuPd_TypeDef)pupd; |
aravindsv | 0:ba7650f404af | 103 | GPIO_Init(gpio, &GPIO_InitStructure); |
aravindsv | 0:ba7650f404af | 104 | |
aravindsv | 0:ba7650f404af | 105 | // [TODO] Disconnect JTAG-DP + SW-DP signals. |
aravindsv | 0:ba7650f404af | 106 | // Warning: Need to reconnect under reset |
aravindsv | 0:ba7650f404af | 107 | //if ((pin == PA_13) || (pin == PA_14)) { |
aravindsv | 0:ba7650f404af | 108 | // |
aravindsv | 0:ba7650f404af | 109 | //} |
aravindsv | 0:ba7650f404af | 110 | //if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) { |
aravindsv | 0:ba7650f404af | 111 | // |
aravindsv | 0:ba7650f404af | 112 | //} |
aravindsv | 0:ba7650f404af | 113 | } |
aravindsv | 0:ba7650f404af | 114 | |
aravindsv | 0:ba7650f404af | 115 | /** |
aravindsv | 0:ba7650f404af | 116 | * Configure pin pull-up/pull-down |
aravindsv | 0:ba7650f404af | 117 | */ |
aravindsv | 0:ba7650f404af | 118 | void pin_mode(PinName pin, PinMode mode) { |
aravindsv | 0:ba7650f404af | 119 | MBED_ASSERT(pin != (PinName)NC); |
aravindsv | 0:ba7650f404af | 120 | |
aravindsv | 0:ba7650f404af | 121 | uint32_t port_index = STM_PORT(pin); |
aravindsv | 0:ba7650f404af | 122 | uint32_t pin_index = STM_PIN(pin); |
aravindsv | 0:ba7650f404af | 123 | |
aravindsv | 0:ba7650f404af | 124 | // Enable GPIO clock |
aravindsv | 0:ba7650f404af | 125 | uint32_t gpio_add = Set_GPIO_Clock(port_index); |
aravindsv | 0:ba7650f404af | 126 | GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add; |
aravindsv | 0:ba7650f404af | 127 | |
aravindsv | 0:ba7650f404af | 128 | // Configure pull-up/pull-down resistors |
aravindsv | 0:ba7650f404af | 129 | uint32_t pupd = (uint32_t)mode; |
aravindsv | 0:ba7650f404af | 130 | if (pupd > 2) |
aravindsv | 0:ba7650f404af | 131 | pupd = 0; // Open-drain = No pull-up/No pull-down |
aravindsv | 0:ba7650f404af | 132 | gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2))); |
aravindsv | 0:ba7650f404af | 133 | gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2)); |
aravindsv | 0:ba7650f404af | 134 | |
aravindsv | 0:ba7650f404af | 135 | } |