Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7fc2d3a

Browse files
MCUdudefpistm
authored andcommittedDec 19, 2019
Add generic F401Rx variant (#787)
This pinout style matches the physical pin style of the F401Rx family pretty well. It makes it easier when working with purposely designed hardware that is not based around a development board. This variant will first try to drive an external crystal. If not present, the MCU will automatically switch to its internal (but less accurate) oscillator instead. Resolves #784
1 parent 370ad02 commit 7fc2d3a

File tree

6 files changed

+887
-0
lines changed

6 files changed

+887
-0
lines changed
 

‎boards.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,42 @@ GenF4.menu.pnum.FEATHER_F405.build.board=FEATHER_F405
10251025
GenF4.menu.pnum.FEATHER_F405.build.product_line=STM32F405xx
10261026
GenF4.menu.pnum.FEATHER_F405.build.variant=FEATHER_F405
10271027

1028+
# Generic F401RE
1029+
GenF4.menu.pnum.Generic_F401RE=Generic F401RE
1030+
GenF4.menu.pnum.Generic_F401RE.upload.maximum_size=524288
1031+
GenF4.menu.pnum.Generic_F401RE.upload.maximum_data_size=98304
1032+
GenF4.menu.pnum.Generic_F401RE.build.board=GENERIC_F401RE
1033+
GenF4.menu.pnum.Generic_F401RE.build.product_line=STM32F401xE
1034+
GenF4.menu.pnum.Generic_F401RE.build.variant=Generic_F401Rx
1035+
GenF4.menu.pnum.Generic_F401RE.node=NODE_F401RE
1036+
1037+
# Generic F401RD
1038+
GenF4.menu.pnum.Generic_F401RD=Generic F401RD
1039+
GenF4.menu.pnum.Generic_F401RD.upload.maximum_size=393216
1040+
GenF4.menu.pnum.Generic_F401RD.upload.maximum_data_size=98304
1041+
GenF4.menu.pnum.Generic_F401RD.build.board=GENERIC_F401RD
1042+
GenF4.menu.pnum.Generic_F401RD.build.product_line=STM32F401xE
1043+
GenF4.menu.pnum.Generic_F401RD.build.variant=Generic_F401Rx
1044+
GenF4.menu.pnum.Generic_F401RD.node=NODE_F401RE
1045+
1046+
# Generic F401RC
1047+
GenF4.menu.pnum.Generic_F401RC=Generic F401RC
1048+
GenF4.menu.pnum.Generic_F401RC.upload.maximum_size=262144
1049+
GenF4.menu.pnum.Generic_F401RC.upload.maximum_data_size=65536
1050+
GenF4.menu.pnum.Generic_F401RC.build.board=GENERIC_F401RC
1051+
GenF4.menu.pnum.Generic_F401RC.build.product_line=STM32F401xC
1052+
GenF4.menu.pnum.Generic_F401RC.build.variant=Generic_F401Rx
1053+
GenF4.menu.pnum.Generic_F401RC.node=NODE_F401RE
1054+
1055+
# Generic F401RB
1056+
GenF4.menu.pnum.Generic_F401RB=Generic F401RB
1057+
GenF4.menu.pnum.Generic_F401RB.upload.maximum_size=131072
1058+
GenF4.menu.pnum.Generic_F401RB.upload.maximum_data_size=65536
1059+
GenF4.menu.pnum.Generic_F401RB.build.board=GENERIC_F401RB
1060+
GenF4.menu.pnum.Generic_F401RB.build.product_line=STM32F401xC
1061+
GenF4.menu.pnum.Generic_F401RB.build.variant=Generic_F401Rx
1062+
GenF4.menu.pnum.Generic_F401RB.node=NODE_F401RE
1063+
10281064
# Upload menu
10291065
GenF4.menu.upload_method.swdMethod=STM32CubeProgrammer (SWD)
10301066
GenF4.menu.upload_method.swdMethod.upload.protocol=0
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2019, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice,
10+
* this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
15+
* may be used to endorse or promote products derived from this software
16+
* without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*******************************************************************************
29+
* Automatically generated from STM32F401R(D-E)Tx.xml
30+
*/
31+
#include "Arduino.h"
32+
#include "PeripheralPins.h"
33+
34+
/* =====
35+
* Note: Commented lines are alternative possibilities which are not used per default.
36+
* If you change them, you will have to know what you do
37+
* =====
38+
*/
39+
40+
//*** ADC ***
41+
42+
#ifdef HAL_ADC_MODULE_ENABLED
43+
WEAK const PinMap PinMap_ADC[] = {
44+
{PA_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC1_IN0
45+
{PA_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1
46+
{PA_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2
47+
{PA_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3
48+
{PA_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4
49+
{PA_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5
50+
{PA_6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6
51+
{PA_7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7
52+
{PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8
53+
{PB_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9
54+
{PC_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10
55+
{PC_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11
56+
{PC_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12
57+
{PC_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13
58+
{PC_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14
59+
{PC_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15
60+
{NC, NP, 0}
61+
};
62+
#endif
63+
64+
//*** No DAC ***
65+
66+
//*** I2C ***
67+
68+
#ifdef HAL_I2C_MODULE_ENABLED
69+
WEAK const PinMap PinMap_I2C_SDA[] = {
70+
{PB_3, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF9_I2C2)},
71+
{PB_4, I2C3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF9_I2C3)},
72+
{PB_7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
73+
{PB_9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
74+
{PC_9, I2C3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)},
75+
{NC, NP, 0}
76+
};
77+
#endif
78+
79+
#ifdef HAL_I2C_MODULE_ENABLED
80+
WEAK const PinMap PinMap_I2C_SCL[] = {
81+
{PA_8, I2C3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)},
82+
{PB_6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
83+
{PB_8, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
84+
{PB_10, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},
85+
{NC, NP, 0}
86+
};
87+
#endif
88+
89+
//*** PWM ***
90+
91+
#ifdef HAL_TIM_MODULE_ENABLED
92+
WEAK const PinMap PinMap_PWM[] = {
93+
// {PA_0, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // A0 // TIM2_CH1
94+
{PA_0, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // A0 // TIM5_CH1
95+
// {PA_1, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // A1 // TIM2_CH2
96+
{PA_1, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 2, 0)}, // A1 // TIM5_CH2
97+
// {PA_2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // D1 // TIM2_CH3 - ST-Link
98+
{PA_2, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 3, 0)}, // D1 // TIM5_CH3 - ST-Link
99+
// {PA_2, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // D1 // TIM9_CH1 - ST-Link
100+
// {PA_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // D0 // TIM2_CH4 - ST-Link
101+
{PA_3, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 4, 0)}, // D0 // TIM5_CH4 - ST-Link
102+
// {PA_3, TIM9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // D0 // TIM9_CH2 - ST-Link
103+
{PA_5, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // D13 // TIM2_CH1 - SPI
104+
{PA_6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // D12 // TIM3_CH1 - SPI
105+
// {PA_7, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // D11 // TIM1_CH1N - SPI
106+
{PA_7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // D11 // TIM3_CH2
107+
{PA_8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 0)}, // D7 // TIM1_CH1
108+
{PA_9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 0)}, // D8 // TIM1_CH2
109+
{PA_10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 0)}, // D2 // TIM1_CH3
110+
{PA_11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 4, 0)}, // D37 // TIM1_CH4
111+
{PA_15, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // D21 // TIM2_CH1
112+
// {PB_0, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // A3 // TIM1_CH2N
113+
{PB_0, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // A3 // TIM3_CH3
114+
// {PB_1, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // D41 // TIM1_CH3N
115+
{PB_1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // D41 // TIM3_CH4
116+
{PB_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // D3 // TIM2_CH2
117+
{PB_4, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // D5 // TIM3_CH1
118+
{PB_5, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // D4 // TIM3_CH2
119+
{PB_6, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // D10 // TIM4_CH1
120+
{PB_7, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // D22 // TIM4_CH2
121+
{PB_8, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // D15 // TIM4_CH3 - SCL
122+
// {PB_8, TIM10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // D15 // TIM10_CH1 - SCL
123+
{PB_9, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // D14 // TIM4_CH4 - SDA
124+
// {PB_9, TIM11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // D14 // TIM11_CH1 - SDA
125+
{PB_10, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // D6 // TIM2_CH3
126+
{PB_13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // D44 // TIM1_CH1N
127+
{PB_14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // D43 // TIM1_CH2N
128+
{PB_15, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // D42 // TIM1_CH3N
129+
{PC_6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // D34 // TIM3_CH1
130+
{PC_7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // D9 // TIM3_CH2
131+
{PC_8, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // D33 // TIM3_CH3
132+
{PC_9, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // D32 // TIM3_CH4
133+
{NC, NP, 0}
134+
};
135+
#endif
136+
137+
//*** SERIAL ***
138+
139+
#ifdef HAL_UART_MODULE_ENABLED
140+
WEAK const PinMap PinMap_UART_TX[] = {
141+
{PA_2, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
142+
{PA_9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
143+
{PA_11, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)},
144+
{PB_6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
145+
{PC_6, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)},
146+
{NC, NP, 0}
147+
};
148+
#endif
149+
150+
#ifdef HAL_UART_MODULE_ENABLED
151+
WEAK const PinMap PinMap_UART_RX[] = {
152+
{PA_3, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
153+
{PA_10, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
154+
{PA_12, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)},
155+
{PB_7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
156+
{PC_7, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)},
157+
{NC, NP, 0}
158+
};
159+
#endif
160+
161+
#ifdef HAL_UART_MODULE_ENABLED
162+
WEAK const PinMap PinMap_UART_RTS[] = {
163+
{PA_1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
164+
{PA_12, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
165+
{NC, NP, 0}
166+
};
167+
#endif
168+
169+
#ifdef HAL_UART_MODULE_ENABLED
170+
WEAK const PinMap PinMap_UART_CTS[] = {
171+
{PA_0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
172+
{PA_11, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
173+
{NC, NP, 0}
174+
};
175+
#endif
176+
177+
//*** SPI ***
178+
179+
#ifdef HAL_SPI_MODULE_ENABLED
180+
WEAK const PinMap PinMap_SPI_MOSI[] = {
181+
{PA_7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
182+
{PB_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
183+
// {PB_5, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
184+
{PB_15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
185+
{PC_3, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
186+
{PC_12, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
187+
{NC, NP, 0}
188+
};
189+
#endif
190+
191+
#ifdef HAL_SPI_MODULE_ENABLED
192+
WEAK const PinMap PinMap_SPI_MISO[] = {
193+
{PA_6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
194+
{PB_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
195+
// {PB_4, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
196+
{PB_14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
197+
{PC_2, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
198+
{PC_11, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
199+
{NC, NP, 0}
200+
};
201+
#endif
202+
203+
#ifdef HAL_SPI_MODULE_ENABLED
204+
WEAK const PinMap PinMap_SPI_SCLK[] = {
205+
{PA_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
206+
{PB_3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
207+
// {PB_3, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
208+
{PB_10, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
209+
{PB_13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
210+
{PC_10, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
211+
{NC, NP, 0}
212+
};
213+
#endif
214+
215+
#ifdef HAL_SPI_MODULE_ENABLED
216+
WEAK const PinMap PinMap_SPI_SSEL[] = {
217+
{PA_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
218+
// {PA_4, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
219+
{PA_15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
220+
// {PA_15, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
221+
{PB_9, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
222+
{PB_12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
223+
{NC, NP, 0}
224+
};
225+
#endif
226+
227+
//*** No CAN ***
228+
229+
//*** No ETHERNET ***
230+
231+
//*** No QUADSPI ***
232+
233+
//*** USB ***
234+
235+
#ifdef HAL_PCD_MODULE_ENABLED
236+
WEAK const PinMap PinMap_USB_OTG_FS[] = {
237+
{PA_8, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_SOF
238+
{PA_9, USB_OTG_FS, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, GPIO_AF_NONE)}, // USB_OTG_FS_VBUS
239+
{PA_10, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_ID
240+
{PA_11, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_DM
241+
{PA_12, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_DP
242+
{NC, NP, 0}
243+
};
244+
#endif
245+
246+
//*** No USB_OTG_HS ***

‎variants/Generic_F401Rx/PinNamesVar.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* SYS_WKUP */
2+
#ifdef PWR_WAKEUP_PIN1
3+
SYS_WKUP1 = PA_0,
4+
#endif
5+
#ifdef PWR_WAKEUP_PIN2
6+
SYS_WKUP2 = NC,
7+
#endif
8+
#ifdef PWR_WAKEUP_PIN3
9+
SYS_WKUP3 = NC,
10+
#endif
11+
#ifdef PWR_WAKEUP_PIN4
12+
SYS_WKUP4 = NC,
13+
#endif
14+
#ifdef PWR_WAKEUP_PIN5
15+
SYS_WKUP5 = NC,
16+
#endif
17+
#ifdef PWR_WAKEUP_PIN6
18+
SYS_WKUP6 = NC,
19+
#endif
20+
#ifdef PWR_WAKEUP_PIN7
21+
SYS_WKUP7 = NC,
22+
#endif
23+
#ifdef PWR_WAKEUP_PIN8
24+
SYS_WKUP8 = NC,
25+
#endif
26+
/* USB */
27+
#ifdef USBCON
28+
USB_OTG_FS_SOF = PA_8,
29+
USB_OTG_FS_VBUS = PA_9,
30+
USB_OTG_FS_ID = PA_10,
31+
USB_OTG_FS_DM = PA_11,
32+
USB_OTG_FS_DP = PA_12,
33+
#endif

‎variants/Generic_F401Rx/ldscript.ld

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/*
2+
*****************************************************************************
3+
**
4+
5+
** File : LinkerScript.ld
6+
**
7+
** Abstract : Linker script for STM32F401RETx Device with
8+
** 512KByte FLASH, 96KByte RAM
9+
**
10+
** Set heap size, stack size and stack location according
11+
** to application requirements.
12+
**
13+
** Set memory bank area and size if external memory is used.
14+
**
15+
** Target : STMicroelectronics STM32
16+
**
17+
**
18+
** Distribution: The file is distributed as is, without any warranty
19+
** of any kind.
20+
**
21+
*****************************************************************************
22+
** @attention
23+
**
24+
** <h2><center>&copy; COPYRIGHT(c) 2014 Ac6</center></h2>
25+
**
26+
** Redistribution and use in source and binary forms, with or without modification,
27+
** are permitted provided that the following conditions are met:
28+
** 1. Redistributions of source code must retain the above copyright notice,
29+
** this list of conditions and the following disclaimer.
30+
** 2. Redistributions in binary form must reproduce the above copyright notice,
31+
** this list of conditions and the following disclaimer in the documentation
32+
** and/or other materials provided with the distribution.
33+
** 3. Neither the name of Ac6 nor the names of its contributors
34+
** may be used to endorse or promote products derived from this software
35+
** without specific prior written permission.
36+
**
37+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
38+
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39+
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40+
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
41+
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42+
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
43+
** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
44+
** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45+
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46+
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47+
**
48+
*****************************************************************************
49+
*/
50+
51+
/* Entry Point */
52+
ENTRY(Reset_Handler)
53+
54+
/* Highest address of the user mode stack */
55+
_estack = 0x20000000 + LD_MAX_DATA_SIZE; /* end of RAM */
56+
/* Generate a link error if heap and stack don't fit into RAM */
57+
_Min_Heap_Size = 0x200;; /* required amount of heap */
58+
_Min_Stack_Size = 0x400;; /* required amount of stack */
59+
60+
/* Specify the memory areas */
61+
MEMORY
62+
{
63+
FLASH (rx) : ORIGIN = 0x8000000 + LD_FLASH_OFFSET, LENGTH = LD_MAX_SIZE - LD_FLASH_OFFSET
64+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE
65+
}
66+
67+
/* Define output sections */
68+
SECTIONS
69+
{
70+
/* The startup code goes first into FLASH */
71+
.isr_vector :
72+
{
73+
. = ALIGN(4);
74+
KEEP(*(.isr_vector)) /* Startup code */
75+
. = ALIGN(4);
76+
} >FLASH
77+
78+
/* The program code and other data goes into FLASH */
79+
.text ALIGN(4):
80+
{
81+
. = ALIGN(4);
82+
*(.text) /* .text sections (code) */
83+
*(.text*) /* .text* sections (code) */
84+
*(.glue_7) /* glue arm to thumb code */
85+
*(.glue_7t) /* glue thumb to arm code */
86+
*(.eh_frame)
87+
88+
KEEP (*(.init))
89+
KEEP (*(.fini))
90+
91+
. = ALIGN(4);
92+
_etext = .; /* define a global symbols at end of code */
93+
} >FLASH
94+
95+
/* Constant data goes into FLASH */
96+
.rodata :
97+
{
98+
. = ALIGN(4);
99+
*(.rodata) /* .rodata sections (constants, strings, etc.) */
100+
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
101+
. = ALIGN(4);
102+
} >FLASH
103+
104+
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
105+
.ARM : {
106+
__exidx_start = .;
107+
*(.ARM.exidx*)
108+
__exidx_end = .;
109+
} >FLASH
110+
111+
.preinit_array :
112+
{
113+
PROVIDE_HIDDEN (__preinit_array_start = .);
114+
KEEP (*(.preinit_array*))
115+
PROVIDE_HIDDEN (__preinit_array_end = .);
116+
} >FLASH
117+
.init_array :
118+
{
119+
PROVIDE_HIDDEN (__init_array_start = .);
120+
KEEP (*(SORT(.init_array.*)))
121+
KEEP (*(.init_array*))
122+
PROVIDE_HIDDEN (__init_array_end = .);
123+
} >FLASH
124+
.fini_array :
125+
{
126+
PROVIDE_HIDDEN (__fini_array_start = .);
127+
KEEP (*(SORT(.fini_array.*)))
128+
KEEP (*(.fini_array*))
129+
PROVIDE_HIDDEN (__fini_array_end = .);
130+
} >FLASH
131+
132+
/* used by the startup to initialize data */
133+
_sidata = LOADADDR(.data);
134+
135+
/* Initialized data sections goes into RAM, load LMA copy after code */
136+
.data :
137+
{
138+
. = ALIGN(4);
139+
_sdata = .; /* create a global symbol at data start */
140+
*(.data) /* .data sections */
141+
*(.data*) /* .data* sections */
142+
143+
. = ALIGN(4);
144+
_edata = .; /* define a global symbol at data end */
145+
} >RAM AT> FLASH
146+
147+
148+
/* Uninitialized data section */
149+
. = ALIGN(4);
150+
.bss :
151+
{
152+
/* This is used by the startup in order to initialize the .bss secion */
153+
_sbss = .; /* define a global symbol at bss start */
154+
__bss_start__ = _sbss;
155+
*(.bss)
156+
*(.bss*)
157+
*(COMMON)
158+
159+
. = ALIGN(4);
160+
_ebss = .; /* define a global symbol at bss end */
161+
__bss_end__ = _ebss;
162+
} >RAM
163+
164+
/* User_heap_stack section, used to check that there is enough RAM left */
165+
._user_heap_stack :
166+
{
167+
. = ALIGN(8);
168+
PROVIDE ( end = . );
169+
PROVIDE ( _end = . );
170+
. = . + _Min_Heap_Size;
171+
. = . + _Min_Stack_Size;
172+
. = ALIGN(8);
173+
} >RAM
174+
175+
176+
177+
/* Remove information from the standard libraries */
178+
/DISCARD/ :
179+
{
180+
libc.a ( * )
181+
libm.a ( * )
182+
libgcc.a ( * )
183+
}
184+
185+
.ARM.attributes 0 : { *(.ARM.attributes) }
186+
}

‎variants/Generic_F401Rx/variant.cpp

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
/*
2+
Copyright (c) 2011 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include "pins_arduino.h"
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
// Digital PinName array
26+
const PinName digitalPin[] = {
27+
PA_0, // Digital pin 0
28+
PA_1, // Digital pin 1
29+
PA_2, // Digital pin 2
30+
PA_3, // Digital pin 3
31+
PA_4, // Digital pin 4
32+
PA_5, // Digital pin 5
33+
PA_6, // Digital pin 6
34+
PA_7, // Digital pin 7
35+
PA_8, // Digital pin 8
36+
PA_9, // Digital pin 9
37+
PA_10, // Digital pin 10
38+
PA_11, // Digital pin 11
39+
PA_12, // Digital pin 12
40+
PA_13, // Digital pin 13
41+
PA_14, // Digital pin 14
42+
PA_15, // Digital pin 15
43+
44+
PB_0, // Digital pin 16
45+
PB_1, // Digital pin 17
46+
PB_2, // Digital pin 18
47+
PB_3, // Digital pin 19
48+
PB_4, // Digital pin 20
49+
PB_5, // Digital pin 21
50+
PB_6, // Digital pin 22
51+
PB_7, // Digital pin 23
52+
PB_8, // Digital pin 24
53+
PB_9, // Digital pin 25
54+
PB_10, // Digital pin 26
55+
PB_12, // Digital pin 27
56+
PB_13, // Digital pin 28
57+
PB_14, // Digital pin 29
58+
PB_15, // Digital pin 30
59+
60+
PC_0, // Digital pin 31
61+
PC_1, // Digital pin 32
62+
PC_2, // Digital pin 33
63+
PC_3, // Digital pin 34
64+
PC_4, // Digital pin 35
65+
PC_5, // Digital pin 36
66+
PC_6, // Digital pin 37
67+
PC_7, // Digital pin 38
68+
PC_8, // Digital pin 39
69+
PC_9, // Digital pin 40
70+
PC_10, // Digital pin 41
71+
PC_11, // Digital pin 42
72+
PC_12, // Digital pin 43
73+
PC_13, // Digital pin 44
74+
PC_14, // Digital pin 45
75+
PC_15, // Digital pin 46
76+
77+
PD_2, // Digital pin 47
78+
79+
PH_0, // Digital pin 48, used by the external oscillator
80+
PH_1 // Digital pin 49, used by the external oscillator
81+
};
82+
83+
// Analog (Ax) pin number array
84+
const uint32_t analogInPin[] = {
85+
0, // A0, PA0
86+
1, // A1, PA1
87+
2, // A2, PA2
88+
3, // A3, PA3
89+
4, // A4, PA4
90+
5, // A5, PA5
91+
6, // A6, PA6
92+
7, // A7, PA7
93+
16, // A8, PB0
94+
17, // A9, PB1
95+
31, // A10, PC0
96+
32, // A11, PC1
97+
33, // A12, PC2
98+
34, // A13, PC3
99+
35, // A14, PC4
100+
36 // A15, PC5
101+
};
102+
103+
#ifdef __cplusplus
104+
}
105+
#endif
106+
107+
// ----------------------------------------------------------------------------
108+
109+
#ifdef __cplusplus
110+
extern "C" {
111+
#endif
112+
113+
/*
114+
* @brief Configures the System clock source, PLL Multiplier and Divider factors,
115+
* AHB/APBx prescalers and Flash settings
116+
* @note This function should be called only once the RCC clock configuration
117+
* is reset to the default reset state (done in SystemInit() function).
118+
* @param None
119+
* @retval None
120+
*/
121+
122+
/******************************************************************************/
123+
/* PLL (clocked by HSE) used as System clock source */
124+
/******************************************************************************/
125+
static uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
126+
{
127+
RCC_OscInitTypeDef RCC_OscInitStruct;
128+
RCC_ClkInitTypeDef RCC_ClkInitStruct;
129+
130+
/* The voltage scaling allows optimizing the power consumption when the device is
131+
clocked below the maximum system frequency, to update the voltage scaling value
132+
regarding system frequency refer to product datasheet. */
133+
__HAL_RCC_PWR_CLK_ENABLE();
134+
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
135+
136+
// Enable HSE oscillator and activate PLL with HSE as source
137+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
138+
if (bypass == 0) {
139+
RCC_OscInitStruct.HSEState = RCC_HSE_ON; // External 8 MHz xtal on OSC_IN/OSC_OUT
140+
} else {
141+
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; // External 8 MHz clock on OSC_IN
142+
}
143+
144+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
145+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
146+
RCC_OscInitStruct.PLL.PLLM = 8; // VCO input clock = 1 MHz (8 MHz / 8)
147+
RCC_OscInitStruct.PLL.PLLN = 336; // VCO output clock = 336 MHz (1 MHz * 336)
148+
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; // PLLCLK = 84 MHz (336 MHz / 4)
149+
RCC_OscInitStruct.PLL.PLLQ = 7; // USB clock = 48 MHz (336 MHz / 7) --> OK for USB
150+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
151+
return 0; // FAIL
152+
}
153+
154+
// Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers
155+
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
156+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; // 84 MHz
157+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; // 84 MHz
158+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; // 42 MHz
159+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // 84 MHz
160+
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
161+
return 0; // FAIL
162+
}
163+
164+
/* Output clock on MCO1 pin(PA8) for debugging purpose */
165+
/*
166+
if (bypass == 0)
167+
HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_2); // 4 MHz
168+
else
169+
HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_1); // 8 MHz
170+
*/
171+
172+
return 1; // OK
173+
}
174+
175+
/******************************************************************************/
176+
/* PLL (clocked by HSI) used as System clock source */
177+
/******************************************************************************/
178+
uint8_t SetSysClock_PLL_HSI(void)
179+
{
180+
RCC_OscInitTypeDef RCC_OscInitStruct;
181+
RCC_ClkInitTypeDef RCC_ClkInitStruct;
182+
183+
/* The voltage scaling allows optimizing the power consumption when the device is
184+
clocked below the maximum system frequency, to update the voltage scaling value
185+
regarding system frequency refer to product datasheet. */
186+
__HAL_RCC_PWR_CLK_ENABLE();
187+
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
188+
189+
// Enable HSI oscillator and activate PLL with HSI as source
190+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE;
191+
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
192+
RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
193+
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
194+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
195+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
196+
RCC_OscInitStruct.PLL.PLLM = 16; // VCO input clock = 1 MHz (16 MHz / 16)
197+
RCC_OscInitStruct.PLL.PLLN = 336; // VCO output clock = 336 MHz (1 MHz * 336)
198+
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; // PLLCLK = 84 MHz (336 MHz / 4)
199+
RCC_OscInitStruct.PLL.PLLQ = 7; // USB clock = 48 MHz (336 MHz / 7) --> freq is ok but not precise enough
200+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
201+
return 0; // FAIL
202+
}
203+
204+
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
205+
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
206+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; // 84 MHz
207+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; // 84 MHz
208+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; // 42 MHz
209+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // 84 MHz
210+
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
211+
return 0; // FAIL
212+
}
213+
214+
/* Output clock on MCO1 pin(PA8) for debugging purpose */
215+
//HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1); // 16 MHz
216+
217+
return 1; // OK
218+
}
219+
220+
WEAK void SystemClock_Config(void)
221+
{
222+
/* 1- If fail try to start with HSE and external xtal */
223+
if (SetSysClock_PLL_HSE(0) == 0) {
224+
/* 2- Try to start with HSE and external clock */
225+
if (SetSysClock_PLL_HSE(1) == 0) {
226+
/* 3- If fail start with HSI clock */
227+
if (SetSysClock_PLL_HSI() == 0) {
228+
Error_Handler();
229+
}
230+
}
231+
}
232+
/* Output clock on MCO2 pin(PC9) for debugging purpose */
233+
//HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_4);
234+
}
235+
236+
#ifdef __cplusplus
237+
}
238+
#endif

‎variants/Generic_F401Rx/variant.h

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
Copyright (c) 2011 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#ifndef _VARIANT_ARDUINO_STM32_
20+
#define _VARIANT_ARDUINO_STM32_
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif // __cplusplus
25+
26+
27+
// | DIGITAL | ANALOG | USART | TWI | SPI | SPECIAL |
28+
// |---------|--------|-----------|----------|------------------------|-----------|
29+
#define PA0 A0 // | 0 | A0 | | | | |
30+
#define PA1 A1 // | 1 | A1 | | | | |
31+
#define PA2 A2 // | 2 | A2 | USART2_TX | | | |
32+
#define PA3 A3 // | 3 | A3 | USART2_RX | | | |
33+
#define PA4 A4 // | 4 | A4 | | | SPI1_SS, (SPI3_SS) | |
34+
#define PA5 A5 // | 5 | A5 | | | SPI1_SCK | |
35+
#define PA6 A6 // | 6 | A6 | | | SPI1_MISO | |
36+
#define PA7 A7 // | 7 | A7 | | | SPI1_MOSI | |
37+
#define PA8 8 // | 8 | | | TWI3_SCL | | |
38+
#define PA9 9 // | 9 | | USART1_TX | | | |
39+
#define PA10 10 // | 10 | | USART1_RX | | | |
40+
#define PA11 11 // | 11 | | USART6_TX | | | |
41+
#define PA12 12 // | 12 | | USART6_RX | | | |
42+
#define PA13 13 // | 13 | | | | | SWD_SWDIO |
43+
#define PA14 14 // | 14 | | | | | SWD_SWCLK |
44+
#define PA15 15 // | 15 | | | | SPI1_SS, (SPI3_SS) | |
45+
// |---------|--------|-----------|----------|------------------------|-----------|
46+
#define PB0 A8 // | 16 | A8 | | | | |
47+
#define PB1 A9 // | 17 | A9 | | | | |
48+
#define PB2 18 // | 18 | | | | | BOOT1 |
49+
#define PB3 19 // | 19 | | | TWI2_SDA | SPI1_SCK, (SPI3_SCK) | |
50+
#define PB4 20 // | 20 | | | TWI3_SDA | SPI1_MISO, (SPI3_MISO) | |
51+
#define PB5 21 // | 21 | | | | SPI1_MOSI, (SPI3_MOSI) | |
52+
#define PB6 22 // | 22 | | USART1_TX | TWI1_SCL | | |
53+
#define PB7 23 // | 23 | | USART1_RX | TWI1_SDA | | |
54+
#define PB8 24 // | 24 | | | TWI1_SCL | | |
55+
#define PB9 25 // | 25 | | | TWI1_SDA | SPI2_SS | |
56+
#define PB10 26 // | 26 | | | TWI2_SCL | SPI2_SCK | |
57+
#define PB12 27 // | 27 | | | | SPI2_SS | |
58+
#define PB13 28 // | 28 | | | | SPI2_SCK | |
59+
#define PB14 29 // | 29 | | | | SPI2_MISO | |
60+
#define PB15 30 // | 30 | | | | SPI2_MOSI | |
61+
// |---------|--------|-----------|----------|------------------------|-----------|
62+
#define PC0 A10 // | 31 | A10 | | | | |
63+
#define PC1 A11 // | 32 | A11 | | | | |
64+
#define PC2 A12 // | 33 | A12 | | | SPI2_MISO | |
65+
#define PC3 A13 // | 34 | A13 | | | SPI2_MOSI | |
66+
#define PC4 A14 // | 35 | A14 | | | | |
67+
#define PC5 A15 // | 36 | A15 | | | | |
68+
#define PC6 37 // | 37 | | USART6_TX | | | |
69+
#define PC7 38 // | 38 | | USART6_RX | | | |
70+
#define PC8 39 // | 39 | | | | | |
71+
#define PC9 40 // | 40 | | | TWI3_SDA | | |
72+
#define PC10 41 // | 41 | | | | SPI3_SCK | |
73+
#define PC11 42 // | 42 | | | | SPI3_MISO | |
74+
#define PC12 43 // | 43 | | | | SPI3_MOSI | |
75+
#define PC13 44 // | 44 | | | | | |
76+
#define PC14 45 // | 45 | | | | | OSC32_IN |
77+
#define PC15 46 // | 46 | | | | | OSC32_OUT |
78+
// |---------|--------|-----------|----------|------------------------|-----------|
79+
#define PD2 47 // | 47 | | | | | |
80+
// |---------|--------|-----------|----------|------------------------|-----------|
81+
#define PH0 48 // | 48 | | | | | OSC_IN |
82+
#define PH1 49 // | 49 | | | | | OSC_OUT |
83+
// |---------|--------|-----------|----------|------------------------|-----------|
84+
85+
// This must be a literal
86+
#define NUM_DIGITAL_PINS 50
87+
#define NUM_ANALOG_INPUTS 16
88+
89+
// On-board LED pin number
90+
#define LED_BUILTIN PA5
91+
#define LED_GREEN LED_BUILTIN
92+
93+
// On-board user button
94+
#define USER_BTN PC13
95+
96+
// SPI definitions
97+
#define PIN_SPI_SS PA4
98+
#define PIN_SPI_SS1 PA4
99+
#define PIN_SPI_SS2 PB12
100+
#define PIN_SPI_SS3 PA15
101+
#define PIN_SPI_MOSI PA7
102+
#define PIN_SPI_MISO PA6
103+
#define PIN_SPI_SCK PA5
104+
105+
// I2C definitions
106+
#define PIN_WIRE_SDA PB9
107+
#define PIN_WIRE_SCL PB8
108+
109+
// Timer Definitions
110+
#define TIMER_TONE TIM10
111+
#define TIMER_SERVO TIM11
112+
113+
// UART Definitions
114+
#define SERIAL_UART_INSTANCE 2 //Connected to ST-Link
115+
116+
// Default pin used for 'Serial' instance (ex: ST-Link)
117+
// Mandatory for Firmata
118+
#define PIN_SERIAL_RX PA3
119+
#define PIN_SERIAL_TX PA2
120+
121+
#ifdef __cplusplus
122+
} // extern "C"
123+
#endif
124+
/*----------------------------------------------------------------------------
125+
* Arduino objects - C++ only
126+
*----------------------------------------------------------------------------*/
127+
128+
#ifdef __cplusplus
129+
// These serial port names are intended to allow libraries and architecture-neutral
130+
// sketches to automatically default to the correct port name for a particular type
131+
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
132+
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
133+
//
134+
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
135+
//
136+
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
137+
//
138+
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
139+
//
140+
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
141+
//
142+
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
143+
// pins are NOT connected to anything by default.
144+
#define SERIAL_PORT_MONITOR Serial
145+
#define SERIAL_PORT_HARDWARE Serial
146+
#endif
147+
148+
#endif /* _VARIANT_ARDUINO_STM32_ */

0 commit comments

Comments
 (0)
Please sign in to comment.