|
| 1 | +/****************************************************************************** |
| 2 | + * The MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2011 LeafLabs, LLC. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person |
| 7 | + * obtaining a copy of this software and associated documentation |
| 8 | + * files (the "Software"), to deal in the Software without |
| 9 | + * restriction, including without limitation the rights to use, copy, |
| 10 | + * modify, merge, publish, distribute, sublicense, and/or sell copies |
| 11 | + * of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be |
| 15 | + * included in all copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 21 | + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 22 | + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | + * SOFTWARE. |
| 25 | + *****************************************************************************/ |
| 26 | + |
| 27 | +/** |
| 28 | + * @file wirish/boards/nucleo/board.cpp |
| 29 | + * @author Grégoire Passault <[email protected]> |
| 30 | + * @brief Nucleo board file |
| 31 | + * |
| 32 | + * This mapping was done using the NUCLEO documentation and may be incomplete |
| 33 | + * or contains error |
| 34 | + * |
| 35 | + * If you want to use the PWM outputs, consider understanding all the remapping |
| 36 | + * process that can be involved. You may have to tweak this file regarding your goals. |
| 37 | + */ |
| 38 | + |
| 39 | +#include <board/board.h> // For this board's header file |
| 40 | + |
| 41 | +#include <wirish/wirish_types.h> // For stm32_pin_info and its contents |
| 42 | + // (these go into PIN_MAP). |
| 43 | + |
| 44 | +#include "boards_private.h" // For PMAP_ROW(), which makes |
| 45 | + // PIN_MAP easier to read. |
| 46 | + |
| 47 | +// boardInit(): NUCLEO rely on some remapping |
| 48 | +void boardInit(void) { |
| 49 | + afio_remap(AFIO_REMAP_TIM2_FULL); |
| 50 | + afio_remap(AFIO_REMAP_TIM3_PARTIAL); |
| 51 | +} |
| 52 | + |
| 53 | +namespace wirish { |
| 54 | +namespace priv { |
| 55 | +static stm32f1_rcc_pll_data pll_data = {RCC_PLLMUL_9}; |
| 56 | +rcc_clk w_board_pll_in_clk = RCC_CLK_HSI; |
| 57 | +rcc_pll_cfg w_board_pll_cfg = {RCC_PLLSRC_HSI_DIV_2, &pll_data}; |
| 58 | +} |
| 59 | +} |
| 60 | + |
| 61 | +// Pin map: this lets the basic I/O functions (digitalWrite(), |
| 62 | +// analogRead(), pwmWrite()) translate from pin numbers to STM32 |
| 63 | +// peripherals. |
| 64 | +// |
| 65 | +// PMAP_ROW() lets us specify a row (really a struct stm32_pin_info) |
| 66 | +// in the pin map. Its arguments are: |
| 67 | +// |
| 68 | +// - GPIO device for the pin (GPIOA, etc.) |
| 69 | +// - GPIO bit for the pin (0 through 15) |
| 70 | +// - Timer device, or NULL if none |
| 71 | +// - Timer channel (1 to 4, for PWM), or 0 if none |
| 72 | +// - ADC device, or NULL if none |
| 73 | +// - ADC channel, or ADCx if none |
| 74 | +extern const stm32_pin_info PIN_MAP[BOARD_NR_GPIO_PINS] = { |
| 75 | + |
| 76 | + /* Arduino-like header, right connectors */ |
| 77 | + |
| 78 | + PMAP_ROW(GPIOA, 3, NULL, 0, ADC1, 3), /* D0/PA3 */ |
| 79 | + PMAP_ROW(GPIOA, 2, NULL, 0, ADC1, 2), /* D1/PA2 */ |
| 80 | + PMAP_ROW(GPIOA, 10, NULL, 0, NULL, ADCx), /* D2/PA10 */ |
| 81 | + PMAP_ROW(GPIOB, 3, TIMER2, 2, NULL, ADCx), /* D3/PB3 REMAPPED */ |
| 82 | + PMAP_ROW(GPIOB, 5, NULL, 0, NULL, ADCx), /* D4/PB5 */ |
| 83 | + PMAP_ROW(GPIOB, 4, TIMER3, 1, NULL, ADCx), /* D5/PB4 REMAPPED */ |
| 84 | + PMAP_ROW(GPIOB, 10, TIMER2, 3, NULL, ADCx), /* D6/PB10 REMAPPED */ |
| 85 | + PMAP_ROW(GPIOA, 8, NULL, 0, NULL, ADCx), /* D7/PA8 */ |
| 86 | + |
| 87 | + PMAP_ROW(GPIOA, 9, NULL, 0, NULL, ADCx), /* D8/PA9 */ |
| 88 | + PMAP_ROW(GPIOC, 7, NULL, 0, NULL, ADCx), /* D9/PC7 */ |
| 89 | + PMAP_ROW(GPIOB, 6, TIMER4, 1, NULL, ADCx), /* D10/PB6 */ |
| 90 | + PMAP_ROW(GPIOA, 7, TIMER3, 2, ADC1, 7), /* D11/PA7 */ |
| 91 | + PMAP_ROW(GPIOA, 6, NULL, 0, ADC1, 6), /* D12/PA6 */ |
| 92 | + PMAP_ROW(GPIOA, 5, NULL, 0, ADC1, 5), /* D13/PA5 LED*/ |
| 93 | + PMAP_ROW(GPIOB, 9, NULL, 0, NULL, ADCx), /* D14/PB9 */ |
| 94 | + PMAP_ROW(GPIOB, 8, NULL, 0, NULL, ADCx), /* D15/PB8 */ |
| 95 | + |
| 96 | + /* Arduino-like header, left connectors */ |
| 97 | + |
| 98 | + PMAP_ROW(GPIOA, 0, TIMER2, 1, ADC1, 0), /* D16/A0/PA0 */ |
| 99 | + PMAP_ROW(GPIOA, 1, TIMER2, 2, ADC1, 1), /* D17/A1/PA1 */ |
| 100 | + PMAP_ROW(GPIOA, 4, NULL, 0, ADC1, 4), /* D18/A2/PA4 */ |
| 101 | + PMAP_ROW(GPIOB, 0, TIMER3, 3, ADC1, 8), /* D19/A3/PB0 */ |
| 102 | + PMAP_ROW(GPIOC, 1, NULL, 0, ADC1, 11), /* D20/A4/PC1 */ |
| 103 | + PMAP_ROW(GPIOC, 0, NULL, 0, ADC1, 10), /* D21/A5/PC0 */ |
| 104 | + |
| 105 | + /* Other pins */ |
| 106 | + |
| 107 | + PMAP_ROW(GPIOB, 7, NULL, 0, NULL, ADCx), /* D22/PB7 */ |
| 108 | + PMAP_ROW(GPIOC, 2, NULL, 0, ADC1, 12), /* D23/PC2 */ |
| 109 | + PMAP_ROW(GPIOC, 3, NULL, 0, ADC1, 13), /* D24/PC3 */ |
| 110 | + PMAP_ROW(GPIOC, 4, NULL, 0, ADC1, 14), /* D25/PC4 */ |
| 111 | + PMAP_ROW(GPIOC, 5, NULL, 0, ADC1, 15), /* D26/PC5 */ |
| 112 | + |
| 113 | + PMAP_ROW(GPIOC, 13, NULL, 0, NULL, ADCx), /* D27/PC13 USER BLUE BUTTON */ |
| 114 | + PMAP_ROW(GPIOC, 14, NULL, 0, NULL, ADCx), /* D28/PC14 */ |
| 115 | + PMAP_ROW(GPIOC, 15, NULL, 0, NULL, ADCx), /* D29/PC15 */ |
| 116 | + PMAP_ROW(GPIOD, 2, NULL, 0, NULL, ADCx), /* D30/PD2 */ |
| 117 | + PMAP_ROW(GPIOC, 10, NULL, 0, NULL, ADCx), /* D31/PC10 */ |
| 118 | + PMAP_ROW(GPIOB, 1, NULL, 0, ADC1, 9), /* D32/PB1 */ |
| 119 | + PMAP_ROW(GPIOB, 11, NULL, 0, NULL, ADCx), /* D33/PB11 */ |
| 120 | + PMAP_ROW(GPIOB, 12, NULL, 0, NULL, ADCx), /* D34/PB12 */ |
| 121 | + PMAP_ROW(GPIOB, 13, NULL, 0, NULL, ADCx), /* D35/PB13 */ |
| 122 | + PMAP_ROW(GPIOB, 14, NULL, 0, NULL, ADCx), /* D36/PB14 */ |
| 123 | + PMAP_ROW(GPIOB, 15, NULL, 0, NULL, ADCx), /* D37/PB15 */ |
| 124 | + PMAP_ROW(GPIOC, 6, NULL, 0, NULL, ADCx), /* D38/PC6 */ |
| 125 | + PMAP_ROW(GPIOC, 8, NULL, 0, NULL, ADCx), /* D39/PC8 */ |
| 126 | + PMAP_ROW(GPIOC, 9, NULL, 0, NULL, ADCx), /* D40/PC9 */ |
| 127 | + |
| 128 | + PMAP_ROW(GPIOA, 13, NULL, 0, NULL, ADCx), /* D41/PA13 */ |
| 129 | + PMAP_ROW(GPIOA, 14, NULL, 0, NULL, ADCx), /* D42/PA14 */ |
| 130 | + PMAP_ROW(GPIOA, 15, NULL, 0, NULL, ADCx), /* D43/PA15 */ |
| 131 | +}; |
| 132 | + |
| 133 | +// Array of pins you can use for pwmWrite(). Keep it in Flash because |
| 134 | +// it doesn't change, and so we don't waste RAM. |
| 135 | +extern const uint8 boardPWMPins[] __FLASH__ = { |
| 136 | + 3, 5, 6, 10, 11, 16, 17, 19 |
| 137 | +}; |
| 138 | + |
| 139 | +// Array of pins you can use for analogRead(). |
| 140 | +extern const uint8 boardADCPins[] __FLASH__ = { |
| 141 | + 16, 17, 18, 19, 20, 21 |
| 142 | +}; |
| 143 | + |
| 144 | +// Array of pins that the board uses for something special. Other than |
| 145 | +// the button and the LED, it's usually best to leave these pins alone |
| 146 | +// unless you know what you're doing. |
| 147 | +extern const uint8 boardUsedPins[] __FLASH__ = { |
| 148 | + BOARD_LED_PIN, BOARD_BUTTON_PIN |
| 149 | +}; |
0 commit comments