You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The **Static Pinmap extension** allows the peripheral configuration (pin/periheral/function) to be staticly specified in the HAL API function.
3
+
The **Static Pinmap extension** allows you to statically specify the peripheral configuration (pin, peripheral or function) in the HAL API function.
4
4
5
5
### Overview and background
6
6
7
-
In modern MCUs peripherals often can be mapped to different pins and each pin can have multiple functions. Mbed supports dynamic pin mapping, meaning that pins can be reconfigured at run time to be used by different driver. That provides great flexibility, but it's not free. There's non trivial ROM cost to maintain the pinmap tables and infrastructure to parse it. In some use cases this flexibility is worth the cost. Quite often pin configuration is frozen at hw design stage and doesn't require runtime modification. Shifting this configuration to compile time will allow us free memory associated with the dynamic approach.
7
+
In modern MCUs, you can often map peripherals to different pins, and each pin can have multiple functions. Mbed supports dynamic pin mapping, meaning you can reconfigure pins at run time for different drivers to use. That provides great flexibility, but it's not free. There's a nontrivial ROM cost to maintain the pin map tables and infrastructure to parse it. In some use cases, this flexibility is worth the cost. Often, pin configuration is frozen at the hardware design stage and doesn't require run time modification. Shifting this configuration to compile time allows free memory associated with the dynamic approach.
8
8
9
-
HAL APIs making use of pins take these pins in their constructor and use those pins to lookup which peripheral/function to use. The process of looking up the peripheral/function requires there to be a pinmap table that maps pins to peripherals/functions. This pinmap table takes up ROM which could be saved if the pinmap wasn't used. Static pinmap extension provides additional HAL API/constructors which takes pinmap as a parameter where pin/peripheral/function is specified staticly and there is no need to use the pinmap tables.
9
+
HAL APIs using pins take these pins in their constructor and use those pins to look up which peripheral or function to use. The process of looking up the peripheral or function requires there to be a pin map table that maps pins to peripherals or functions. This pin map table takes up ROM. Static pinmap extension provides additional HAL APIconstructors, which take pin map as a parameter where the pin, peripheral or function is specified statically, and there is no need to use the pin map tables.
10
10
11
11
Supported peripherals:
12
-
- `PWM`
13
-
- `AnalogIn`
14
-
- `AnalogOut`
15
-
- `SPI`
16
-
- `I2C`
17
-
- `UART`
18
-
- `QSPI`
19
-
- `CAN`
12
+
13
+
-`PWM`.
14
+
-`AnalogIn`.
15
+
-`AnalogOut`.
16
+
-`SPI`.
17
+
-`I2C`.
18
+
-`UART`.
19
+
-`QSPI`.
20
+
-`CAN`.
20
21
21
-
###Implementing static pin-map extension
22
+
## Implementing static pinmap extension
22
23
23
-
If you want to make static pinmap available on your platform please perform the following steps:
24
+
If you want to make static pin map available on your platform please perform the following steps:
24
25
25
26
- Provide implementation of `xxx_init_direct(xxx_t *obj, static_pinmap_t *)` function and update implementation of `xxx_init()`.
26
-
- `xxx_init()`usees pinmap tables to determine associated peripheral/function with the given pins, populates the pin-map structure and calls void `xxx_init_direct()`.
27
-
- `xxx_init_direct()` performs peripheral initialization using given static pinmap structure.
27
+
-`xxx_init()`uses pin map tables to determine the associated peripheral or function with the given pins, populates the pinmap structure and calls void `xxx_init_direct()`.
28
+
-`xxx_init_direct()` performs peripheral initialization using given static pin map structure.
- Provide `constexpr` pin-map tables in the header file.
55
56
56
-
Move pinmap tables from `PeripheralPins.c` to `PeripheralPinMaps.h` (create new file) and add `constexpr` specifier in the pin-map table declarations.
57
-
The tables are required in the header file, so can be included and used by constant expression utility functions to find and return mapping without pulling the pin-map table into the image.
57
+
Move pin map tables from `PeripheralPins.c` to `PeripheralPinMaps.h` (create new file) and add `constexpr` specifier in the pin map table declarations.
58
58
59
-
**Note:**
60
-
Please include `<mstd_cstddef>` module and use `MSTD_CONSTEXPR_OBJ_11` macro instead `constexpr` specifier. When `PeripheralPinMaps.h` is included from the Mbed OS C++ code, we need to see it as `constexpr`, but if the target code includes it from C, it has to have it as `const`.
59
+
The tables are required in the header file, so constant expression utility functions can include and use them to find and return mapping without pulling the pin map table into the image.
61
60
62
-
Example pin-map table below:
61
+
<spanclass="notes">**Note:** Please include the `<mstd_cstddef>` module, and use the `MSTD_CONSTEXPR_OBJ_11` macro instead of the `constexpr` specifier. When `PeripheralPinMaps.h` is included from the Mbed OS C++ code, we need to see it as `constexpr`, but if the target code includes it from C, it has to have it as `const`.</span>
63
62
64
-
```
65
-
#include <mstd_cstddef>
66
-
67
-
MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_ADC[] = {
68
-
{P0_23, ADC0_SE0, 0},
69
-
{P0_10, ADC0_SE1, 0},
70
-
{P0_31, ADC0_SE3, 0},
71
-
{P1_8, ADC0_SE4, 0},
72
-
{P2_0, ADC0_SE5, 0},
73
-
{P2_13, ADC0_SE6, 0},
74
-
{P2_11, ADC0_SE7, 0},
75
-
{NC , NC , 0}
76
-
};
63
+
Example pin map table:
77
64
78
-
```
65
+
```
66
+
#include <mstd_cstddef>
79
67
80
-
- Provide macros for pin-map tables
68
+
MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_ADC[] = {
69
+
{P0_23, ADC0_SE0, 0},
70
+
{P0_10, ADC0_SE1, 0},
71
+
{P0_31, ADC0_SE3, 0},
72
+
{P1_8, ADC0_SE4, 0},
73
+
{P2_0, ADC0_SE5, 0},
74
+
{P2_13, ADC0_SE6, 0},
75
+
{P2_11, ADC0_SE7, 0},
76
+
{NC , NC , 0}
77
+
};
81
78
82
-
Since pin-map table names are not common across all targets the following macros for available pin-map tables are required in `PeripheralPinMaps.h` file:
79
+
```
83
80
84
-
```
85
-
#define PINMAP_ANALOGIN [PinMap ADC]
86
-
#define PINMAP_ANALOGOUT [PinMap DAC]
87
-
#define PINMAP_I2C_SDA [PinMap I2C SDA]
88
-
#define PINMAP_I2C_SCL [PinMap I2C SCL]
89
-
#define PINMAP_UART_TX [PinMap UART TX]
90
-
#define PINMAP_UART_RX [PinMap UART RX]
91
-
#define PINMAP_UART_CTS [PinMap UART CTS]
92
-
#define PINMAP_UART_RTS [PinMap UART RTS]
93
-
#define PINMAP_SPI_SCLK [PinMap SPI SCLK]
94
-
#define PINMAP_SPI_MOSI [PinMap SPI MOSI]
95
-
#define PINMAP_SPI_MISO [PinMap SPI MISO]
96
-
#define PINMAP_SPI_SSEL [PinMap SPI SSEL]
97
-
#define PINMAP_PWM [PinMap PWM]
98
-
#define PINMAP_QSPI_DATA0 [PinMap QSPI DATA0]
99
-
#define PINMAP_QSPI_DATA1 [PinMap QSPI DATA1]
100
-
#define PINMAP_QSPI_DATA2 [PinMap QSPI DATA2]
101
-
#define PINMAP_QSPI_DATA3 [PinMap QSPI DATA3]
102
-
#define PINMAP_QSPI_SCLK [PinMap QSPI SCLK]
103
-
#define PINMAP_QSPI_SSEL [PinMap QSPI SSEL]
104
-
#define PINMAP_CAN_RD [PinMap CAN RD]
105
-
#define PINMAP_CAN_TD [PinMap CAN RD]
106
-
```
81
+
- Provide macros for pin map tables.
107
82
108
-
- Provide `STATIC_PINMAP_READY` macro in `PinNames.h`
83
+
Because pin map table names are not common across all targets, the following macros for available pin map tables are required in the `PeripheralPinMaps.h`file:
109
84
110
-
Adding this macro will enable the static pin-map support for the target.
85
+
```
86
+
#define PINMAP_ANALOGIN [PinMap ADC]
87
+
#define PINMAP_ANALOGOUT [PinMap DAC]
88
+
#define PINMAP_I2C_SDA [PinMap I2C SDA]
89
+
#define PINMAP_I2C_SCL [PinMap I2C SCL]
90
+
#define PINMAP_UART_TX [PinMap UART TX]
91
+
#define PINMAP_UART_RX [PinMap UART RX]
92
+
#define PINMAP_UART_CTS [PinMap UART CTS]
93
+
#define PINMAP_UART_RTS [PinMap UART RTS]
94
+
#define PINMAP_SPI_SCLK [PinMap SPI SCLK]
95
+
#define PINMAP_SPI_MOSI [PinMap SPI MOSI]
96
+
#define PINMAP_SPI_MISO [PinMap SPI MISO]
97
+
#define PINMAP_SPI_SSEL [PinMap SPI SSEL]
98
+
#define PINMAP_PWM [PinMap PWM]
99
+
#define PINMAP_QSPI_DATA0 [PinMap QSPI DATA0]
100
+
#define PINMAP_QSPI_DATA1 [PinMap QSPI DATA1]
101
+
#define PINMAP_QSPI_DATA2 [PinMap QSPI DATA2]
102
+
#define PINMAP_QSPI_DATA3 [PinMap QSPI DATA3]
103
+
#define PINMAP_QSPI_SCLK [PinMap QSPI SCLK]
104
+
#define PINMAP_QSPI_SSEL [PinMap QSPI SSEL]
105
+
#define PINMAP_CAN_RD [PinMap CAN RD]
106
+
#define PINMAP_CAN_TD [PinMap CAN RD]
107
+
```
111
108
112
-
```
113
-
/* If this macro is defined, then constexpr utility functions for pin-map seach can be used. */
114
-
#define STATIC_PINMAP_READY 1
115
-
```
109
+
- Provide `STATIC_PINMAP_READY` macro in `PinNames.h`
110
+
111
+
Adding this macro enables the static pin map support for the target.
112
+
113
+
```
114
+
/* If this macro is defined, you can use constexpr utility functions for pin map search. */
115
+
#define STATIC_PINMAP_READY 1
116
+
```
116
117
117
-
### Example usage/testing
118
+
##Testing
118
119
119
-
Use code below to check if static pinmap extension works.
120
+
Use the code below to test the static pin map extension:
120
121
121
122
```
122
123
int main()
@@ -136,36 +137,41 @@ int main()
136
137
}
137
138
```
138
139
139
-
When static pinmap extension is used we should get some ROM savings:
140
+
When you use the static pin map extension, you save on ROM:
0 commit comments