Skip to content

Commit da261d5

Browse files
GregwarMarti Bolivar
authored and
Marti Bolivar
committed
Adding support for NUCLEO-F103RB
Signed-off-by: Grégoire Passault <[email protected]>
1 parent 4ec8efc commit da261d5

File tree

3 files changed

+261
-0
lines changed

3 files changed

+261
-0
lines changed

support/make/board-includes/nucleo.mk

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
MCU := STM32F103RB
2+
PRODUCT_ID := 0003
3+
ERROR_LED_PORT := GPIOA
4+
ERROR_LED_PIN := 5
5+
MCU_SERIES := stm32f1
6+
MCU_F1_LINE := performance
7+
# This crap is due to ld-script limitations. If you know of a better
8+
# way to go about this (like some magic ld switches to specify MEMORY
9+
# at the command line), please tell us!
10+
LD_MEM_DIR := sram_20k_flash_128k

wirish/boards/nucleo/board.cpp

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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+
};
+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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/maple/include/board/board.h
29+
* @author Marti Bolivar <[email protected]>
30+
* @brief Maple board header.
31+
*/
32+
33+
#ifndef _BOARD_MAPLE_H_
34+
#define _BOARD_MAPLE_H_
35+
36+
/**
37+
* If you solder an external oscillator, you may run the board at 72mhz,
38+
* else, we keep it at 36mhz for simplicity and stability
39+
*/
40+
#define CYCLES_PER_MICROSECOND 36
41+
42+
/* Pin number for the built-in button. */
43+
#define BOARD_BUTTON_PIN 27
44+
45+
/* Pin number for the built-in LED. */
46+
#define BOARD_LED_PIN 13
47+
48+
/* Number of USARTs/UARTs whose pins are broken out to headers. */
49+
#define BOARD_NR_USARTS 3
50+
51+
/* USART pin numbers. */
52+
#define BOARD_USART1_TX_PIN 7
53+
#define BOARD_USART1_RX_PIN 8
54+
#define BOARD_USART2_TX_PIN 1
55+
#define BOARD_USART2_RX_PIN 0
56+
#define BOARD_USART3_TX_PIN 29
57+
#define BOARD_USART3_RX_PIN 30
58+
59+
/* Number of SPI ports broken out to headers. */
60+
#define BOARD_NR_SPI 2
61+
62+
/* SPI pin numbers. */
63+
#define BOARD_SPI1_NSS_PIN 10
64+
#define BOARD_SPI1_MOSI_PIN 11
65+
#define BOARD_SPI1_MISO_PIN 12
66+
#define BOARD_SPI1_SCK_PIN 13
67+
#define BOARD_SPI2_NSS_PIN 31
68+
#define BOARD_SPI2_MOSI_PIN 34
69+
#define BOARD_SPI2_MISO_PIN 33
70+
#define BOARD_SPI2_SCK_PIN 32
71+
72+
/* Total number of GPIO pins that are broken out to headers and
73+
* intended for use. This includes pins like the LED, button, and
74+
* debug port (JTAG/SWD) pins. */
75+
#define BOARD_NR_GPIO_PINS 44
76+
77+
/* Number of pins capable of PWM output. */
78+
#define BOARD_NR_PWM_PINS 8
79+
80+
/* Number of pins capable of ADC conversion. */
81+
#define BOARD_NR_ADC_PINS 6
82+
83+
/* Number of pins already connected to external hardware. For Maple,
84+
* these are just BOARD_LED_PIN, BOARD_BUTTON_PIN, and the debug port
85+
* pins (see below). */
86+
#define BOARD_NR_USED_PINS 2
87+
88+
/**
89+
* Note: there is no USB in this board.
90+
*/
91+
92+
/* Pin aliases: these give the GPIO port/bit for each pin as an
93+
* enum. These are optional, but recommended. They make it easier to
94+
* write code using low-level GPIO functionality. */
95+
enum {
96+
PA3, PA2, PA0, PA1, PB5, PB6, PA8, PA9, PA10, PB7, PA4, PA7, PA6, PA5, PB8,
97+
PC0, PC1, PC2, PC3, PC4, PC5, PC13, PC14, PC15, PB9, PD2, PC10, PB0, PB1,
98+
PB10, PB11, PB12, PB13, PB14, PB15, PC6, PC7, PC8, PC9, PA13, PA14, PA15,
99+
PB3, PB4
100+
};
101+
102+
#endif

0 commit comments

Comments
 (0)