Skip to content

Commit f9de648

Browse files
authored
Merge pull request #60 from fpistm/STM32F1_merge_nucleo_F103RB
STM32F1 merge: Nucleo F103RB
2 parents 247310a + b7d2390 commit f9de648

22 files changed

+2010
-14
lines changed

Diff for: boards.txt

+14
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ Nucleo_64.menu.board_part_num.NUCLEO_F091RC.build.product_line=STM32F091xC
8686
Nucleo_64.menu.board_part_num.NUCLEO_F091RC.build.variant=NUCLEO_F091RC
8787
Nucleo_64.menu.board_part_num.NUCLEO_F091RC.build.cmsis_lib_gcc=arm_cortexM0l_math
8888

89+
# NUCLEO_F103RB board
90+
# Support: Serial1 (USART1 on PA10, PA9) and Serial2 (USART3 on PC11, PC10)
91+
Nucleo_64.menu.board_part_num.NUCLEO_F103RB=Nucleo F103RB
92+
Nucleo_64.menu.board_part_num.NUCLEO_F103RB.node="NODE_F103RB,NUCLEO"
93+
Nucleo_64.menu.board_part_num.NUCLEO_F103RB.upload.maximum_size=131072
94+
Nucleo_64.menu.board_part_num.NUCLEO_F103RB.upload.maximum_data_size=20480
95+
Nucleo_64.menu.board_part_num.NUCLEO_F103RB.build.mcu=cortex-m3
96+
Nucleo_64.menu.board_part_num.NUCLEO_F103RB.build.f_cpu=72000000L
97+
Nucleo_64.menu.board_part_num.NUCLEO_F103RB.build.board=NUCLEO_F103RB
98+
Nucleo_64.menu.board_part_num.NUCLEO_F103RB.build.series=STM32F1xx
99+
Nucleo_64.menu.board_part_num.NUCLEO_F103RB.build.product_line=STM32F103xB
100+
Nucleo_64.menu.board_part_num.NUCLEO_F103RB.build.variant=NUCLEO_F103RB
101+
Nucleo_64.menu.board_part_num.NUCLEO_F103RB.build.cmsis_lib_gcc=arm_cortexM3l_math
102+
89103
# NUCLEO_F303RE board
90104
# Support: Serial1 (USART1 on PA10, PA9) and Serial2 (USART2 on PA1, PA0)
91105
Nucleo_64.menu.board_part_num.NUCLEO_F303RE=Nucleo F303RE

Diff for: cores/arduino/WInterrupts.c

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
extern "C" {
2323
#endif
2424

25+
#include "PinAF_STM32F1.h"
26+
2527
void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode)
2628
{
2729
uint32_t it_mode;
@@ -46,6 +48,11 @@ void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode)
4648
it_mode = GPIO_MODE_IT_RISING;
4749
break;
4850
}
51+
52+
#ifdef STM32F1xx
53+
pinF1_DisconnectDebug(p);
54+
#endif /* STM32F1xx */
55+
4956
stm32_interrupt_enable(port, STM_GPIO_PIN(p), callback, it_mode);
5057
}
5158

Diff for: cores/arduino/stm32/PinAF_STM32F1.h

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2017, 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+
*/
30+
31+
#ifndef _PINAF_STM32F1_H
32+
#define _PINAF_STM32F1_H
33+
34+
#ifdef STM32F1xx
35+
36+
#include "Arduino.h"
37+
38+
#ifdef __cplusplus
39+
extern "C" {
40+
#endif
41+
42+
static inline void pinF1_DisconnectDebug(PinName pin)
43+
{
44+
/** Enable this flag gives the possibility to use debug pins without any risk
45+
* to lose traces
46+
*/
47+
#ifndef STM32F1_LOCK_DEBUG
48+
// Enable AFIO clock
49+
__HAL_RCC_AFIO_CLK_ENABLE();
50+
51+
// Disconnect JTAG-DP + SW-DP signals.
52+
// Warning: Need to reconnect under reset
53+
if ((pin == PA13) || (pin == PA14)) {
54+
__HAL_AFIO_REMAP_SWJ_DISABLE(); // JTAG-DP Disabled and SW-DP Disabled
55+
}
56+
if ((pin == PA15) || (pin == PB3) || (pin == PB4)) {
57+
__HAL_AFIO_REMAP_SWJ_NOJTAG(); // JTAG-DP Disabled and SW-DP enabled
58+
}
59+
#endif /* STM32F1_FORCE_DEBUG */
60+
}
61+
62+
static inline void pin_SetF1AFPin(uint32_t afnum)
63+
{
64+
// Enable AFIO clock
65+
__HAL_RCC_AFIO_CLK_ENABLE();
66+
67+
if (afnum > 0) {
68+
switch (afnum) {
69+
case 1: // Remap SPI1
70+
__HAL_AFIO_REMAP_SPI1_ENABLE();
71+
break;
72+
case 2: // Remap I2C1
73+
__HAL_AFIO_REMAP_I2C1_ENABLE();
74+
break;
75+
case 3: // Remap USART1
76+
__HAL_AFIO_REMAP_USART1_ENABLE();
77+
break;
78+
case 4: // Remap USART2
79+
__HAL_AFIO_REMAP_USART2_ENABLE();
80+
break;
81+
case 5: // Partial Remap USART3
82+
__HAL_AFIO_REMAP_USART3_PARTIAL();
83+
break;
84+
case 6: // Partial Remap TIM1
85+
__HAL_AFIO_REMAP_TIM1_PARTIAL();
86+
break;
87+
case 7: // Partial Remap TIM3
88+
__HAL_AFIO_REMAP_TIM3_PARTIAL();
89+
break;
90+
case 8: // Full Remap TIM2
91+
__HAL_AFIO_REMAP_TIM2_ENABLE();
92+
break;
93+
case 9: // Full Remap TIM3
94+
__HAL_AFIO_REMAP_TIM3_ENABLE();
95+
break;
96+
#if defined(AFIO_MAPR_CAN_REMAP_REMAP1)
97+
case 10: // CAN_RX mapped to PB8, CAN_TX mapped to PB9
98+
__HAL_AFIO_REMAP_CAN1_2();
99+
break;
100+
case 11: // CAN_RX mapped to PB8, CAN_TX mapped to PB9
101+
__HAL_AFIO_REMAP_CAN1_3();
102+
break;
103+
#endif
104+
case 12: // Full Remap USART3
105+
__HAL_AFIO_REMAP_USART3_ENABLE();
106+
break;
107+
case 13: // Full Remap TIM1
108+
__HAL_AFIO_REMAP_TIM1_ENABLE();
109+
break;
110+
case 14: // Full Remap TIM4
111+
__HAL_AFIO_REMAP_TIM4_ENABLE();
112+
break;
113+
default:
114+
break;
115+
}
116+
}
117+
}
118+
119+
#ifdef __cplusplus
120+
}
121+
#endif
122+
123+
#endif /* STM32F1xx */
124+
125+
#endif /* _PINAF_STM32F1_H */

Diff for: cores/arduino/stm32/analog.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "hw_config.h"
5151
#include "analog.h"
5252
#include "timer.h"
53+
#include "PinAF_STM32F1.h"
5354

5455
#ifdef __cplusplus
5556
extern "C" {
@@ -83,6 +84,7 @@
8384
#error "ADC SAMPLINGTIME could not be defined"
8485
#endif
8586

87+
#ifndef STM32F1xx
8688
#ifdef ADC_CLOCK_SYNC_PCLK_DIV2
8789
#define ADC_CLOCK_DIV ADC_CLOCK_SYNC_PCLK_DIV2
8890
#elif defined(ADC_CLOCK_ASYNC_DIV1)
@@ -92,6 +94,7 @@
9294
#else
9395
#error "ADC_CLOCK_DIV could not be defined"
9496
#endif
97+
#endif /* STM32F1xx */
9598

9699
#ifndef ADC_REGULAR_RANK_1
97100
#define ADC_REGULAR_RANK_1 1
@@ -432,7 +435,8 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)
432435
#ifdef __HAL_RCC_ADC_CLK_ENABLE
433436
__HAL_RCC_ADC_CLK_ENABLE();
434437
#endif
435-
#ifdef __HAL_RCC_ADC_CONFIG
438+
/* For STM32F1xx, ADC prescaler is confgured in SystemClock_Config (variant.cpp) */
439+
#if defined(__HAL_RCC_ADC_CONFIG) && !defined(STM32F1xx)
436440
/* ADC Periph interface clock configuration */
437441
__HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK);
438442
#endif
@@ -557,16 +561,18 @@ uint16_t adc_read_value(PinName pin)
557561

558562
if (AdcHandle.Instance == NP) return 0;
559563

564+
#ifndef STM32F1xx
560565
AdcHandle.Init.ClockPrescaler = ADC_CLOCK_DIV; /* Asynchronous clock mode, input ADC clock divided */
561566
AdcHandle.Init.Resolution = ADC_RESOLUTION_12B; /* 12-bit resolution for converted data */
567+
AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; /* EOC flag picked-up to indicate conversion end */
568+
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */
569+
AdcHandle.Init.DMAContinuousRequests = DISABLE; /* DMA one-shot mode selected (not applied to this example) */
570+
#endif
562571
AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; /* Right-alignment for converted data */
563572
AdcHandle.Init.ScanConvMode = DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
564-
AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; /* EOC flag picked-up to indicate conversion end */
565573
AdcHandle.Init.ContinuousConvMode = DISABLE; /* Continuous mode disabled to have only 1 conversion at each conversion trig */
566574
AdcHandle.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */
567575
AdcHandle.Init.ExternalTrigConv = ADC_SOFTWARE_START; /* Software start to trig the 1st conversion manually, without external event */
568-
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */
569-
AdcHandle.Init.DMAContinuousRequests = DISABLE; /* DMA one-shot mode selected (not applied to this example) */
570576
AdcHandle.State = HAL_ADC_STATE_RESET;
571577
#if defined (STM32F0xx) || defined (STM32L0xx)
572578
AdcHandle.Init.LowPowerAutoWait = DISABLE; /* Auto-delayed conversion feature disabled */
@@ -609,9 +615,9 @@ uint16_t adc_read_value(PinName pin)
609615
return 0;
610616
}
611617

612-
#if defined (STM32F0xx) || defined (STM32F3xx) || defined (STM32L4xx)
618+
#if defined (STM32F0xx) || defined (STM32F1xx) || defined (STM32F3xx) || defined (STM32L4xx)
613619
/*##-2.1- Calibrate ADC then Start the conversion process ####################*/
614-
#if defined (STM32F0xx)
620+
#if defined (STM32F0xx) || defined (STM32F1xx)
615621
if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK)
616622
#else
617623
if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED) != HAL_OK)
@@ -687,7 +693,11 @@ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
687693
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
688694
GPIO_InitStruct.Pull = GPIO_NOPULL;
689695
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
696+
#ifdef STM32F1xx
697+
pin_SetF1AFPin(STM_PIN_AFNUM(function));
698+
#else
690699
GPIO_InitStruct.Alternate = STM_PIN_AFNUM(function);
700+
#endif /* STM32F1xx */
691701
GPIO_InitStruct.Pin = STM_GPIO_PIN(g_current_pin);
692702

693703
HAL_GPIO_Init(port, &GPIO_InitStruct);

Diff for: cores/arduino/stm32/digital_io.c

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "digital_io.h"
3939
#include "stm32_def.h"
4040
#include "hw_config.h"
41+
#include "PinAF_STM32F1.h"
4142

4243
#ifdef __cplusplus
4344
extern "C" {
@@ -59,6 +60,9 @@ void digital_io_init(PinName pin, uint32_t mode, uint32_t pull)
5960
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
6061
GPIO_InitStructure.Mode = mode;
6162
GPIO_InitStructure.Pull = pull;
63+
#ifdef STM32F1xx
64+
pinF1_DisconnectDebug(pin);
65+
#endif /* STM32F1xx */
6266
HAL_GPIO_Init(port, &GPIO_InitStructure);
6367
}
6468

Diff for: cores/arduino/stm32/interrupt.c

+34-2
Original file line numberDiff line numberDiff line change
@@ -170,23 +170,55 @@ uint8_t get_pin_id(uint16_t pin)
170170
void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, void (*callback)(void), uint32_t mode)
171171
{
172172
GPIO_InitTypeDef GPIO_InitStruct;
173-
uint32_t pull;
174173
uint8_t id = get_pin_id(pin);
174+
175+
#ifdef STM32F1xx
176+
uint8_t position;
177+
uint32_t CRxRegOffset = 0;
178+
uint32_t ODRRegOffset = 0;
179+
volatile uint32_t *CRxRegister;
180+
const uint32_t ConfigMask = 0x00000008; //MODE0 == 0x0 && CNF0 == 0x2
181+
#else
182+
uint32_t pull;
183+
#endif /* STM32F1xx */
184+
175185
// GPIO pin configuration
176186
GPIO_InitStruct.Pin = pin;
177187
GPIO_InitStruct.Mode = mode;
178188

179189
//read the pull mode directly in the register as no function exists to get it.
180190
//Do it in case the user already defines the IO through the digital io
181191
//interface
192+
#ifndef STM32F1xx
182193
pull = port->PUPDR;
183194
#ifdef GPIO_PUPDR_PUPD0
184195
pull &=(GPIO_PUPDR_PUPD0<<(id*2));
185196
GPIO_InitStruct.Pull = (GPIO_PUPDR_PUPD0 & (pull>>(id*2)));
186197
#else
187198
pull &=(GPIO_PUPDR_PUPDR0<<(id*2));
188199
GPIO_InitStruct.Pull = (GPIO_PUPDR_PUPDR0 & (pull>>(id*2)));
189-
#endif
200+
#endif /* GPIO_PUPDR_PUPD0 */
201+
#else
202+
CRxRegister = (pin < GPIO_PIN_8) ? &port->CRL : &port->CRH;
203+
204+
for (position = 0; position < 16; position++) {
205+
if(pin == (0x0001 << position)) {
206+
CRxRegOffset = (pin < GPIO_PIN_8) ? (position << 2) : ((position - 8) << 2);
207+
ODRRegOffset = position;
208+
}
209+
}
210+
211+
if((*CRxRegister & ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0) << CRxRegOffset)) == (ConfigMask << CRxRegOffset)) {
212+
if((port->ODR & (GPIO_ODR_ODR0 << ODRRegOffset)) == (GPIO_ODR_ODR0 << ODRRegOffset)) {
213+
GPIO_InitStruct.Pull = GPIO_PULLUP;
214+
} else {
215+
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
216+
}
217+
} else {
218+
GPIO_InitStruct.Pull = GPIO_NOPULL;
219+
}
220+
#endif /* STM32F1xx */
221+
190222
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
191223

192224
HAL_GPIO_Init(port, &GPIO_InitStruct);

Diff for: cores/arduino/stm32/spi_com.c

+17
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "stm32_def.h"
5050
#include "hw_config.h"
5151
#include "spi_com.h"
52+
#include "PinAF_STM32F1.h"
5253

5354
#ifdef __cplusplus
5455
extern "C" {
@@ -275,7 +276,11 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb)
275276
GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->pin_mosi,PinMap_SPI_MOSI));
276277
GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->pin_mosi,PinMap_SPI_MOSI));
277278
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
279+
#ifdef STM32F1xx
280+
pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_mosi,PinMap_SPI_MOSI)));
281+
#else
278282
GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_mosi,PinMap_SPI_MOSI));
283+
#endif /* STM32F1xx */
279284
HAL_GPIO_Init(port, &GPIO_InitStruct);
280285
}
281286

@@ -285,7 +290,11 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb)
285290
GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->pin_miso,PinMap_SPI_MISO));
286291
GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->pin_miso,PinMap_SPI_MISO));
287292
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
293+
#ifdef STM32F1xx
294+
pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_miso,PinMap_SPI_MISO)));
295+
#else
288296
GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_miso,PinMap_SPI_MISO));
297+
#endif /* STM32F1xx */
289298
HAL_GPIO_Init(port, &GPIO_InitStruct);
290299
}
291300

@@ -303,7 +312,11 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb)
303312
GPIO_InitStruct.Pull = GPIO_PULLUP;
304313
}
305314
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
315+
#ifdef STM32F1xx
316+
pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_sclk,PinMap_SPI_SCLK)));
317+
#else
306318
GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_sclk,PinMap_SPI_SCLK));
319+
#endif /* STM32F1xx */
307320
HAL_GPIO_Init(port, &GPIO_InitStruct);
308321
}
309322

@@ -313,7 +326,11 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb)
313326
GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->pin_ssel,PinMap_SPI_SSEL));
314327
GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->pin_ssel,PinMap_SPI_SSEL));
315328
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
329+
#ifdef STM32F1xx
330+
pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_ssel,PinMap_SPI_SSEL)));
331+
#else
316332
GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_ssel,PinMap_SPI_SSEL));
333+
#endif /* STM32F1xx */
317334
HAL_GPIO_Init(port, &GPIO_InitStruct);
318335
}
319336

Diff for: cores/arduino/stm32/stm32_def_build.h

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#define CMSIS_STARTUP_FILE "startup_stm32l476xx.s"
4141
#elif defined(STM32L432xx)
4242
#define CMSIS_STARTUP_FILE "startup_stm32l432xx.s"
43+
#elif defined(STM32F103xB)
44+
#define CMSIS_STARTUP_FILE "startup_stm32f103xb.s"
4345
#else
4446
#error UNKNOWN CHIP
4547
#endif

0 commit comments

Comments
 (0)