Skip to content

Commit 95e66aa

Browse files
committed
Move the target dependent code from the shared code to the HAL implementation
1 parent 39f4d26 commit 95e66aa

File tree

7 files changed

+82
-91
lines changed

7 files changed

+82
-91
lines changed

libraries/mbed/common/pinmap_common.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ void pinmap_pinout(PinName pin, const PinMap *map) {
2222
while (map->pin != NC) {
2323
if (map->pin == pin) {
2424
pin_function(pin, map->function);
25-
#if defined(TARGET_STM32F407)
26-
pin_alternate_function(pin, map->alternate_function);
27-
#endif
25+
2826
pin_mode(pin, PullNone);
2927
return;
3028
}

libraries/mbed/hal/pinmap.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,9 @@ typedef struct {
2626
PinName pin;
2727
int peripheral;
2828
int function;
29-
#if defined(TARGET_STM32F407)
30-
int alternate_function;
31-
#endif
3229
} PinMap;
3330

3431
void pin_function(PinName pin, int function);
35-
# if defined(TARGET_STM32F407)
36-
void pin_alternate_function(PinName pin, int alternate_function);
37-
#endif
3832
void pin_mode (PinName pin, PinMode mode);
3933

4034
uint32_t pinmap_peripheral(PinName pin, const PinMap* map);

libraries/mbed/targets/hal/STM/TARGET_STM32F4XX/PinNames.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
extern "C" {
2323
#endif
2424

25+
#define STM_PIN_DATA(MODE, FUNC) (((MODE) << 8) | (FUNC))
26+
#define STM_PIN_MODE(X) ((X) >> 8)
27+
#define STM_PIN_FUNC(X) ((X) & 0xFF)
28+
2529
typedef enum {
2630
PIN_INPUT,
2731
PIN_OUTPUT

libraries/mbed/targets/hal/STM/TARGET_STM32F4XX/analogin_api.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@
2525
#define ADC_12BIT_RANGE 0xFFF
2626

2727
static const PinMap PinMap_ADC[] = {
28-
{PA_0, ADC0_0, 3, 0},
29-
{PA_1, ADC0_1, 3, 0},
30-
{PA_2, ADC0_2, 3, 0},
31-
{PA_3, ADC0_3, 3, 0},
32-
{PA_4, ADC0_4, 3, 0},
33-
{PA_5, ADC0_5, 3, 0},
34-
{PA_6, ADC0_6, 3, 0},
35-
{PA_7, ADC0_7, 3, 0},
36-
{PB_0, ADC0_8, 3, 0},
37-
{PB_1, ADC0_9, 3, 0},
38-
{PC_0, ADC0_10, 3, 0},
39-
{PC_1, ADC0_11, 3, 0},
40-
{PC_2, ADC0_12, 3, 0},
41-
{PC_3, ADC0_13, 3, 0},
42-
{PC_4, ADC0_14, 3, 0},
43-
{PC_5, ADC0_15, 3, 0},
44-
{NC, NC, 0, 0}
28+
{PA_0, ADC0_0, STM_PIN_DATA(3, 0)},
29+
{PA_1, ADC0_1, STM_PIN_DATA(3, 0)},
30+
{PA_2, ADC0_2, STM_PIN_DATA(3, 0)},
31+
{PA_3, ADC0_3, STM_PIN_DATA(3, 0)},
32+
{PA_4, ADC0_4, STM_PIN_DATA(3, 0)},
33+
{PA_5, ADC0_5, STM_PIN_DATA(3, 0)},
34+
{PA_6, ADC0_6, STM_PIN_DATA(3, 0)},
35+
{PA_7, ADC0_7, STM_PIN_DATA(3, 0)},
36+
{PB_0, ADC0_8, STM_PIN_DATA(3, 0)},
37+
{PB_1, ADC0_9, STM_PIN_DATA(3, 0)},
38+
{PC_0, ADC0_10, STM_PIN_DATA(3, 0)},
39+
{PC_1, ADC0_11, STM_PIN_DATA(3, 0)},
40+
{PC_2, ADC0_12, STM_PIN_DATA(3, 0)},
41+
{PC_3, ADC0_13, STM_PIN_DATA(3, 0)},
42+
{PC_4, ADC0_14, STM_PIN_DATA(3, 0)},
43+
{PC_5, ADC0_15, STM_PIN_DATA(3, 0)},
44+
{NC, NC, 0}
4545
};
4646

4747
# define ADC_RANGE ADC_12BIT_RANGE

libraries/mbed/targets/hal/STM/TARGET_STM32F4XX/i2c_api.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@
2222
#include "error.h"
2323

2424
static const PinMap PinMap_I2C_SDA[] = {
25-
{PB_7, I2C_1, 2, 4},
26-
{PB_9, I2C_1, 2, 4},
27-
{PB_11, I2C_2, 2, 4},
28-
{PC_9, I2C_3, 2, 4},
29-
{PF_0, I2C_2, 2, 4},
30-
{PH_5, I2C_2, 2, 4},
31-
{PH_8, I2C_3, 2, 4},
32-
{NC , NC , 0, 0}
25+
{PB_7, I2C_1, STM_PIN_DATA(2, 4)},
26+
{PB_9, I2C_1, STM_PIN_DATA(2, 4)},
27+
{PB_11, I2C_2, STM_PIN_DATA(2, 4)},
28+
{PC_9, I2C_3, STM_PIN_DATA(2, 4)},
29+
{PF_0, I2C_2, STM_PIN_DATA(2, 4)},
30+
{PH_5, I2C_2, STM_PIN_DATA(2, 4)},
31+
{PH_8, I2C_3, STM_PIN_DATA(2, 4)},
32+
{NC, NC, 0}
3333
};
3434

3535
static const PinMap PinMap_I2C_SCL[] = {
36-
{PA_8, I2C_3, 2, 4},
37-
{PB_6, I2C_1, 2, 4},
38-
{PB_8, I2C_1, 2, 4},
39-
{PB_10, I2C_2, 2, 4},
40-
{PF_1, I2C_2, 2, 4},
41-
{PH_4, I2C_2, 2, 4},
42-
{PH_7, I2C_3, 2, 4},
43-
{NC , NC, 0, 0}
36+
{PA_8, I2C_3, STM_PIN_DATA(2, 4)},
37+
{PB_6, I2C_1, STM_PIN_DATA(2, 4)},
38+
{PB_8, I2C_1, STM_PIN_DATA(2, 4)},
39+
{PB_10, I2C_2, STM_PIN_DATA(2, 4)},
40+
{PF_1, I2C_2, STM_PIN_DATA(2, 4)},
41+
{PH_4, I2C_2, STM_PIN_DATA(2, 4)},
42+
{PH_7, I2C_3, STM_PIN_DATA(2, 4)},
43+
{NC, NC, 0}
4444
};
4545

4646
static const uint32_t I2C_addr_offset[2][4] = {

libraries/mbed/targets/hal/STM/TARGET_STM32F4XX/pinmap.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,38 @@
1919
/**
2020
* Set the pin into input, output, alternate function or analog mode
2121
*/
22-
void pin_function(PinName pin, int function) {
22+
void pin_function(PinName pin, int data) {
2323
if (pin == (uint32_t)NC) return;
24-
24+
25+
int mode = STM_PIN_MODE(data);
26+
int func = STM_PIN_FUNC(data);
27+
2528
uint32_t pin_number = (uint32_t)pin;
2629
int port_index = pin_number >> 4;
2730
int pin_index = (pin_number & 0xF);
28-
int offset = pin_index << 1;
29-
3031
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) (GPIOA_BASE + (port_index << 10)));
32+
33+
// MODE
34+
int offset = pin_index << 1;
3135
gpio->MODER &= ~(0x3 << offset);
32-
gpio->MODER |= function << offset;
33-
36+
gpio->MODER |= mode << offset;
37+
3438
// Set high-speed mode
3539
gpio->OSPEEDR &= ~(0x3 << offset);
3640
gpio->OSPEEDR |= (0x2 << offset);
37-
}
38-
39-
void pin_alternate_function(PinName pin, int function) {
40-
if (pin == (uint32_t)NC) return;
41-
42-
uint32_t pin_number = (uint32_t)pin;
43-
int port_index = pin_number >> 4;
44-
int pin_index = (pin_number & 0xF);
45-
int offset = (pin_index & 0x7) << 2;
46-
47-
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) (GPIOA_BASE + (port_index << 10)));
48-
41+
42+
// FUNCTION
4943
// Bottom seven pins are in AFR[0], top seven in AFR[1]
44+
offset = (pin_index & 0x7) << 2;
5045
if (pin_index <= 0x7) {
5146
gpio->AFR[0] &= ~(0xF << offset);
52-
gpio->AFR[0] |= function << offset;
47+
gpio->AFR[0] |= func << offset;
5348
}
5449
else {
5550
gpio->AFR[1] &= ~(0xF << offset);
56-
gpio->AFR[1] |= function << offset;
51+
gpio->AFR[1] |= func << offset;
5752
}
58-
}
53+
}
5954

6055
void pin_mode(PinName pin, PinMode mode) {
6156
if (pin == (uint32_t)NC) { return; }

libraries/mbed/targets/hal/STM/TARGET_STM32F4XX/spi_api.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,43 @@
2323
#include "error.h"
2424

2525
static const PinMap PinMap_SPI_SCLK[] = {
26-
{PA_5, SPI_1, 2, 5},
27-
{PB_3, SPI_1, 2, 5},
28-
{PB_3, SPI_3, 2, 6},
29-
{PB_10, SPI_2, 2, 5},
30-
{PB_13, SPI_2, 2, 5},
31-
{PC_10, SPI_3, 2, 6},
32-
{NC , NC , 0, 0}
26+
{PA_5, SPI_1, STM_PIN_DATA(2, 5)},
27+
{PB_3, SPI_1, STM_PIN_DATA(2, 5)},
28+
{PB_3, SPI_3, STM_PIN_DATA(2, 6)},
29+
{PB_10, SPI_2, STM_PIN_DATA(2, 5)},
30+
{PB_13, SPI_2, STM_PIN_DATA(2, 5)},
31+
{PC_10, SPI_3, STM_PIN_DATA(2, 6)},
32+
{NC, NC, 0}
3333
};
3434

3535
static const PinMap PinMap_SPI_MOSI[] = {
36-
{PA_7, SPI_1, 2, 5},
37-
{PB_5, SPI_1, 2, 5},
38-
{PB_5, SPI_3, 2, 6},
39-
{PB_15, SPI_2, 2, 5},
40-
{PC_3, SPI_2, 2, 5},
41-
{PC_12, SPI_3, 2, 6},
42-
{NC , NC , 0, 0}
36+
{PA_7, SPI_1, STM_PIN_DATA(2, 5)},
37+
{PB_5, SPI_1, STM_PIN_DATA(2, 5)},
38+
{PB_5, SPI_3, STM_PIN_DATA(2, 6)},
39+
{PB_15, SPI_2, STM_PIN_DATA(2, 5)},
40+
{PC_3, SPI_2, STM_PIN_DATA(2, 5)},
41+
{PC_12, SPI_3, STM_PIN_DATA(2, 6)},
42+
{NC, NC, 0}
4343
};
4444

4545
static const PinMap PinMap_SPI_MISO[] = {
46-
{PA_6, SPI_1, 2, 5},
47-
{PB_4, SPI_1, 2, 5},
48-
{PB_4, SPI_3, 2, 6},
49-
{PB_14, SPI_2, 2, 5},
50-
{PC_2, SPI_2, 2, 5},
51-
{PC_11, SPI_3, 2, 6},
52-
{NC , NC , 0, 0}
46+
{PA_6, SPI_1, STM_PIN_DATA(2, 5)},
47+
{PB_4, SPI_1, STM_PIN_DATA(2, 5)},
48+
{PB_4, SPI_3, STM_PIN_DATA(2, 6)},
49+
{PB_14, SPI_2, STM_PIN_DATA(2, 5)},
50+
{PC_2, SPI_2, STM_PIN_DATA(2, 5)},
51+
{PC_11, SPI_3, STM_PIN_DATA(2, 6)},
52+
{NC, NC, 0}
5353
};
5454

5555
static const PinMap PinMap_SPI_SSEL[] = {
56-
{PA_4, SPI_1, 2, 5},
57-
{PA_4, SPI_3, 2, 6},
58-
{PA_15, SPI_1, 2, 5},
59-
{PA_15, SPI_3, 2, 6},
60-
{PB_9, SPI_2, 2, 5},
61-
{PB_12, SPI_2, 2, 5},
62-
{NC , NC , 0, 0}
56+
{PA_4, SPI_1, STM_PIN_DATA(2, 5)},
57+
{PA_4, SPI_3, STM_PIN_DATA(2, 6)},
58+
{PA_15, SPI_1, STM_PIN_DATA(2, 5)},
59+
{PA_15, SPI_3, STM_PIN_DATA(2, 6)},
60+
{PB_9, SPI_2, STM_PIN_DATA(2, 5)},
61+
{PB_12, SPI_2, STM_PIN_DATA(2, 5)},
62+
{NC, NC, 0}
6363
};
6464

6565

0 commit comments

Comments
 (0)