rc

Dependents:   WizFi250_AP_HelloWorld

Fork of mbed-src by DongEun Koak

Committer:
kaizen
Date:
Mon Aug 24 00:12:39 2015 +0000
Revision:
617:d1b257119699
Parent:
567:a97fd0eca828
Added UART_2 of WIZwiki_W7500 for test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 558:0880f51c4036 1 /* mbed Microcontroller Library
mbed_official 558:0880f51c4036 2 *******************************************************************************
mbed_official 558:0880f51c4036 3 * Copyright (c) 2015 WIZnet Co.,Ltd. All rights reserved.
mbed_official 558:0880f51c4036 4 * All rights reserved.
mbed_official 558:0880f51c4036 5 *
mbed_official 558:0880f51c4036 6 * Redistribution and use in source and binary forms, with or without
mbed_official 558:0880f51c4036 7 * modification, are permitted provided that the following conditions are met:
mbed_official 558:0880f51c4036 8 *
mbed_official 558:0880f51c4036 9 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 558:0880f51c4036 10 * this list of conditions and the following disclaimer.
mbed_official 558:0880f51c4036 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 558:0880f51c4036 12 * this list of conditions and the following disclaimer in the documentation
mbed_official 558:0880f51c4036 13 * and/or other materials provided with the distribution.
mbed_official 558:0880f51c4036 14 * 3. Neither the name of ARM Limited nor the names of its contributors
mbed_official 558:0880f51c4036 15 * may be used to endorse or promote products derived from this software
mbed_official 558:0880f51c4036 16 * without specific prior written permission.
mbed_official 558:0880f51c4036 17 *
mbed_official 558:0880f51c4036 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 558:0880f51c4036 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 558:0880f51c4036 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 558:0880f51c4036 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 558:0880f51c4036 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 558:0880f51c4036 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 558:0880f51c4036 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 558:0880f51c4036 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 558:0880f51c4036 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 558:0880f51c4036 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 558:0880f51c4036 28 *******************************************************************************
mbed_official 558:0880f51c4036 29 */
mbed_official 558:0880f51c4036 30
mbed_official 558:0880f51c4036 31 #include "mbed_assert.h"
mbed_official 558:0880f51c4036 32 #include "pinmap.h"
mbed_official 558:0880f51c4036 33 #include "PortNames.h"
mbed_official 567:a97fd0eca828 34 #include "mbed_error.h"
mbed_official 558:0880f51c4036 35
mbed_official 558:0880f51c4036 36
mbed_official 558:0880f51c4036 37 uint32_t Get_GPIO_BaseAddress(uint32_t port_idx)
mbed_official 558:0880f51c4036 38 {
mbed_official 558:0880f51c4036 39 uint32_t gpio_add = 0;
mbed_official 558:0880f51c4036 40 switch(port_idx) {
mbed_official 558:0880f51c4036 41 case PortA:
mbed_official 558:0880f51c4036 42 gpio_add = GPIOA_BASE;
mbed_official 558:0880f51c4036 43 break;
mbed_official 558:0880f51c4036 44 case PortB:
mbed_official 558:0880f51c4036 45 gpio_add = GPIOB_BASE;
mbed_official 558:0880f51c4036 46 break;
mbed_official 558:0880f51c4036 47 case PortC:
mbed_official 558:0880f51c4036 48 gpio_add = GPIOC_BASE;
mbed_official 558:0880f51c4036 49 break;
mbed_official 558:0880f51c4036 50 case PortD:
mbed_official 558:0880f51c4036 51 gpio_add = GPIOD_BASE;
mbed_official 558:0880f51c4036 52 break;
mbed_official 558:0880f51c4036 53 default:
mbed_official 558:0880f51c4036 54 error("Pinmap error: wrong port number.");
mbed_official 558:0880f51c4036 55 break;
mbed_official 558:0880f51c4036 56 }
mbed_official 558:0880f51c4036 57 return gpio_add;
mbed_official 558:0880f51c4036 58 }
mbed_official 558:0880f51c4036 59
mbed_official 558:0880f51c4036 60 /**
mbed_official 558:0880f51c4036 61 * Configure pin (input, output, alternate function or analog) + output speed + AF
mbed_official 558:0880f51c4036 62 */
mbed_official 558:0880f51c4036 63
mbed_official 558:0880f51c4036 64 void pin_function(PinName pin, int data) {
mbed_official 558:0880f51c4036 65 MBED_ASSERT(pin != (PinName)NC);
mbed_official 558:0880f51c4036 66 // Get the pin informations
mbed_official 558:0880f51c4036 67 uint32_t mode = WIZ_PIN_MODE(data);
mbed_official 558:0880f51c4036 68 uint32_t pupd = WIZ_PIN_PUPD(data);
mbed_official 567:a97fd0eca828 69 uint32_t afnum = WIZ_PIN_AFNUM(data);
mbed_official 567:a97fd0eca828 70
mbed_official 567:a97fd0eca828 71 uint32_t port_num = WIZ_PORT(pin);
mbed_official 567:a97fd0eca828 72 uint32_t pin_index = WIZ_PIN_INDEX(pin);
mbed_official 567:a97fd0eca828 73
mbed_official 567:a97fd0eca828 74 GPIO_TypeDef *gpio;
mbed_official 558:0880f51c4036 75
mbed_official 558:0880f51c4036 76 // Configure Alternate Function
mbed_official 558:0880f51c4036 77 // Warning: Must be done before the GPIO is initialized
mbed_official 558:0880f51c4036 78 switch (afnum) {
mbed_official 558:0880f51c4036 79 case 0:
mbed_official 567:a97fd0eca828 80 HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF0);
mbed_official 558:0880f51c4036 81 break;
mbed_official 558:0880f51c4036 82 case 1:
mbed_official 567:a97fd0eca828 83 HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF1);
mbed_official 558:0880f51c4036 84 break;
mbed_official 558:0880f51c4036 85 case 2:
mbed_official 567:a97fd0eca828 86 HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF2);
mbed_official 558:0880f51c4036 87 break;
mbed_official 558:0880f51c4036 88 case 3:
mbed_official 567:a97fd0eca828 89 HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF3);
mbed_official 558:0880f51c4036 90 break;
mbed_official 558:0880f51c4036 91 default:
mbed_official 558:0880f51c4036 92 break;
mbed_official 558:0880f51c4036 93 }
mbed_official 558:0880f51c4036 94
mbed_official 558:0880f51c4036 95 if(mode == WIZ_MODE_AF)
mbed_official 558:0880f51c4036 96 return;
mbed_official 558:0880f51c4036 97
mbed_official 558:0880f51c4036 98 // Configure GPIO
mbed_official 567:a97fd0eca828 99 gpio = (GPIO_TypeDef *)Get_GPIO_BaseAddress(port_num);
mbed_official 567:a97fd0eca828 100
mbed_official 558:0880f51c4036 101 GPIO_InitTypeDef GPIO_InitStructure;
mbed_official 567:a97fd0eca828 102 GPIO_InitStructure.GPIO_Pin = pin_index;
mbed_official 567:a97fd0eca828 103 GPIO_InitStructure.GPIO_Mode = (GPIOMode_TypeDef)mode;
mbed_official 567:a97fd0eca828 104 GPIO_InitStructure.GPIO_Pad = (GPIOPad_TypeDef)pupd;
mbed_official 558:0880f51c4036 105 HAL_GPIO_Init(gpio, &GPIO_InitStructure);
mbed_official 558:0880f51c4036 106 }
mbed_official 558:0880f51c4036 107
mbed_official 558:0880f51c4036 108 /**
mbed_official 558:0880f51c4036 109 * Configure pin pull-up/pull-down
mbed_official 558:0880f51c4036 110 */
mbed_official 558:0880f51c4036 111 void pin_mode(PinName pin, PinMode pupd)
mbed_official 558:0880f51c4036 112 {
mbed_official 558:0880f51c4036 113 MBED_ASSERT(pin != (PinName)NC);
mbed_official 567:a97fd0eca828 114
mbed_official 567:a97fd0eca828 115 uint32_t port_num = WIZ_PORT(pin);
mbed_official 567:a97fd0eca828 116 uint32_t pin_num = WIZ_PIN_NUM(pin);
mbed_official 558:0880f51c4036 117
mbed_official 567:a97fd0eca828 118 switch(port_num) {
mbed_official 558:0880f51c4036 119 case PortA:
mbed_official 567:a97fd0eca828 120 PA_PCR->Port[pin_num] |= pupd;
mbed_official 558:0880f51c4036 121 break;
mbed_official 558:0880f51c4036 122 case PortB:
mbed_official 567:a97fd0eca828 123 PB_PCR->Port[pin_num] |= pupd;
mbed_official 558:0880f51c4036 124 break;
mbed_official 558:0880f51c4036 125 case PortC:
mbed_official 567:a97fd0eca828 126 PC_PCR->Port[pin_num] |= pupd;
mbed_official 558:0880f51c4036 127 break;
mbed_official 558:0880f51c4036 128 case PortD:
mbed_official 567:a97fd0eca828 129 PD_PCR->Port[pin_num] |= pupd;
mbed_official 558:0880f51c4036 130 break;
mbed_official 558:0880f51c4036 131 default:
mbed_official 567:a97fd0eca828 132 error("Pinmap error: wrong port number.");
mbed_official 558:0880f51c4036 133 return;
mbed_official 558:0880f51c4036 134 }
mbed_official 558:0880f51c4036 135 }