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