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
-
### Overview and background
5
+
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.
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.
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.
7
+
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 API constructors, 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
8
11
9
Supported peripherals:
12
-
- `PWM`
13
-
- `AnalogIn`
14
-
- `AnalogOut`
15
-
- `SPI`
16
-
- `I2C`
17
-
- `UART`
18
-
- `QSPI`
19
-
- `CAN`
10
+
11
+
- `PWM`.
12
+
- `AnalogIn`.
13
+
- `AnalogOut`.
14
+
- `SPI`.
15
+
- `I2C`.
16
+
- `UART`.
17
+
- `QSPI`.
18
+
- `CAN`.
20
19
21
-
### Requirements and assumptions
20
+
##Assumptions
22
21
23
-
1. Provide types which will hold static pinmaps for peripherals(`PWM`, `AnalogIn`, `AnalogOut`, `SPI`, `I2C`, `UART`, `QSPI`, `CAN`).
24
-
2. Provide `xxx_init_direct(xxx_t *obj, static_pinmap_t *)` functions to HAL API (these functions will not use pinmap tables).
25
-
3. Provide additional constructors in drivers layer which will use the `xxx_init_direct(xxx_t *obj, static_pinmap_t*)` HAL functions.
26
-
4. Provide default weak implementations of `xxx_init_direct(static_pinmap_t *)` functions. These functions will call standard `xxx_init(xxx_t *obj, PinName, ...)` function (backward compatibility for targets which do not support static pinmap mechanism).
22
+
1. Provide types that will hold static pin maps for peripherals(`PWM`, `AnalogIn`, `AnalogOut`, `SPI`, `I2C`, `UART`, `QSPI`, `CAN`).
23
+
2. Provide `xxx_init_direct(xxx_t *obj, static_pinmap_t *)` functions to HAL API (these functions won't use pin map tables).
24
+
3. Provide additional constructors in the drivers layer, which will use the `xxx_init_direct(xxx_t *obj, static_pinmap_t*)` HAL functions.
25
+
4. Provide default weak implementations of `xxx_init_direct(static_pinmap_t *)` functions. These functions call standard `xxx_init(xxx_t *obj, PinName, ...)` function (backward compatibility for targets that don't support the static pin map mechanism).
27
26
5. Provide `constexpr` utility functions to lookup for pin mapping in compile time (requires C++14).
28
-
6. Provide `constexpr` pin-map tables in the header file.
29
-
7. Provide macros for the pin-map tables.
27
+
6. Provide `constexpr` pinmap tables in the header file.
28
+
7. Provide macros for the pinmap tables.
30
29
8. Provide `STATIC_PINMAP_READY` macro in `PinNames.h`.
31
30
32
-
###Implementing static pin-map extension
33
-
34
-
Most of the above points are already implemented. If you want to make static pinmap available on your platform please perform the following steps:
35
-
36
-
- Provide implementation of `xxx_init_direct(xxx_t *obj, static_pinmap_t *)` function (which does not use pinmap tables).
37
-
- `xxx_init()`will use pinmap tables to determine associated peripheral/function with the given pins, populate the pin-map structure and call void `xxx_init_direct()`.
38
-
- `xxx_init_direct()`will perform peripheral initialization using given static pinmap structure.
Most of the above points are already implemented. To make static pin map available on your platform, please perform the following steps:
34
+
35
+
- Provide implementation of `xxx_init_direct(xxx_t *obj, static_pinmap_t *)` function (which does not use pin map tables).
36
+
- `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()`.
37
+
- `xxx_init_direct()`performs peripheral initialization using given static pin map structure.
- Provide `constexpr` pin-map tables in the header file.
66
65
67
-
Move pinmap tables from `PeripheralPins.c` to `PeripheralPinMaps.h` (create new file) and add `constexpr` specifier in the pin-map table declarations.
68
-
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.
69
-
70
-
**Note:**
71
-
Please include `<mstd_cstddef>` module and use `MSTD_CONSTEXPR_OBJ_11` macro instead `constexpr` specifier. This must be done for backward compatibility with `ARM 5` compiler which does not support constant expressions. When `ARM 5` compiler is in use`MSTD_CONSTEXPR_OBJ_11`will be translated to `const`.
72
-
73
-
Example pin-map table below:
74
-
75
-
```
76
-
#include <mstd_cstddef>
77
-
78
-
MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_ADC[] = {
79
-
{P0_23, ADC0_SE0, 0},
80
-
{P0_10, ADC0_SE1, 0},
81
-
{P0_31, ADC0_SE3, 0},
82
-
{P1_8, ADC0_SE4, 0},
83
-
{P2_0, ADC0_SE5, 0},
84
-
{P2_13, ADC0_SE6, 0},
85
-
{P2_11, ADC0_SE7, 0},
86
-
{NC , NC , 0}
87
-
};
88
-
89
-
```
90
-
91
-
- Provide macros for pin-map tables
92
-
93
-
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:
94
-
95
-
```
96
-
#define PINMAP_ANALOGIN [PinMap ADC]
97
-
#define PINMAP_ANALOGOUT [PinMap DAC]
98
-
#define PINMAP_I2C_SDA [PinMap I2C SDA]
99
-
#define PINMAP_I2C_SCL [PinMap I2C SCL]
100
-
#define PINMAP_UART_TX [PinMap UART TX]
101
-
#define PINMAP_UART_RX [PinMap UART RX]
102
-
#define PINMAP_UART_CTS [PinMap UART CTS]
103
-
#define PINMAP_UART_RTS [PinMap UART RTS]
104
-
#define PINMAP_SPI_SCLK [PinMap SPI SCLK]
105
-
#define PINMAP_SPI_MOSI [PinMap SPI MOSI]
106
-
#define PINMAP_SPI_MISO [PinMap SPI MISO]
107
-
#define PINMAP_SPI_SSEL [PinMap SPI SSEL]
108
-
#define PINMAP_PWM [PinMap PWM]
109
-
#define PINMAP_QSPI_DATA0 [PinMap QSPI DATA0]
110
-
#define PINMAP_QSPI_DATA1 [PinMap QSPI DATA1]
111
-
#define PINMAP_QSPI_DATA2 [PinMap QSPI DATA2]
112
-
#define PINMAP_QSPI_DATA3 [PinMap QSPI DATA3]
113
-
#define PINMAP_QSPI_SCLK [PinMap QSPI SCLK]
114
-
#define PINMAP_QSPI_SSEL [PinMap QSPI SSEL]
115
-
#define PINMAP_CAN_RD [PinMap CAN RD]
116
-
#define PINMAP_CAN_TD [PinMap CAN RD]
117
-
```
66
+
Move pin map tables from `PeripheralPins.c` to `PeripheralPinMaps.h` (create new file) and add `constexpr` specifier in the pinmap table declarations.
67
+
68
+
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.
69
+
70
+
<spanclass="notes">**Note:**Please include the `<mstd_cstddef>` module, and use the `MSTD_CONSTEXPR_OBJ_11` macro instead of the `constexpr` specifier. This must be done for backward compatibility with the Arm 5 compiler, which does not support constant expressions. When you use the Arm 5 compiler,`MSTD_CONSTEXPR_OBJ_11`translates to `const`.</span>
71
+
72
+
Example pinmap table:
73
+
74
+
```
75
+
#include <mstd_cstddef>
76
+
77
+
MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_ADC[] = {
78
+
{P0_23, ADC0_SE0, 0},
79
+
{P0_10, ADC0_SE1, 0},
80
+
{P0_31, ADC0_SE3, 0},
81
+
{P1_8, ADC0_SE4, 0},
82
+
{P2_0, ADC0_SE5, 0},
83
+
{P2_13, ADC0_SE6, 0},
84
+
{P2_11, ADC0_SE7, 0},
85
+
{NC , NC , 0}
86
+
};
87
+
88
+
```
89
+
90
+
- Provide macros for pinmap tables.
91
+
92
+
Because pinmap table names are not common across all targets, the following macros for available pinmap tables are required in the`PeripheralPinMaps.h` file:
93
+
94
+
```
95
+
#define PINMAP_ANALOGIN [PinMap ADC]
96
+
#define PINMAP_ANALOGOUT [PinMap DAC]
97
+
#define PINMAP_I2C_SDA [PinMap I2C SDA]
98
+
#define PINMAP_I2C_SCL [PinMap I2C SCL]
99
+
#define PINMAP_UART_TX [PinMap UART TX]
100
+
#define PINMAP_UART_RX [PinMap UART RX]
101
+
#define PINMAP_UART_CTS [PinMap UART CTS]
102
+
#define PINMAP_UART_RTS [PinMap UART RTS]
103
+
#define PINMAP_SPI_SCLK [PinMap SPI SCLK]
104
+
#define PINMAP_SPI_MOSI [PinMap SPI MOSI]
105
+
#define PINMAP_SPI_MISO [PinMap SPI MISO]
106
+
#define PINMAP_SPI_SSEL [PinMap SPI SSEL]
107
+
#define PINMAP_PWM [PinMap PWM]
108
+
#define PINMAP_QSPI_DATA0 [PinMap QSPI DATA0]
109
+
#define PINMAP_QSPI_DATA1 [PinMap QSPI DATA1]
110
+
#define PINMAP_QSPI_DATA2 [PinMap QSPI DATA2]
111
+
#define PINMAP_QSPI_DATA3 [PinMap QSPI DATA3]
112
+
#define PINMAP_QSPI_SCLK [PinMap QSPI SCLK]
113
+
#define PINMAP_QSPI_SSEL [PinMap QSPI SSEL]
114
+
#define PINMAP_CAN_RD [PinMap CAN RD]
115
+
#define PINMAP_CAN_TD [PinMap CAN RD]
116
+
```
118
117
119
118
- Provide `STATIC_PINMAP_READY` macro in `PinNames.h`
120
119
121
-
Adding this macro will enable the static pin-map support for the target.
120
+
Adding this macro enables the static pinmap support for the target.
122
121
123
-
```
124
-
/* If this macro is defined, then constexpr utility functions for pin-map seach can be used. */
125
-
#define STATIC_PINMAP_READY 1
126
-
```
122
+
```
123
+
/* If this macro is defined, you can use constexpr utility functions for pinmap search. */
124
+
#define STATIC_PINMAP_READY 1
125
+
```
127
126
128
-
### Example usage/testing
127
+
##Testing
129
128
130
-
Use code below to check if static pinmap extension works.
129
+
Use the code below to test the static pin map extension:
131
130
132
131
```
133
132
int main()
@@ -147,7 +146,7 @@ int main()
147
146
}
148
147
```
149
148
150
-
When static pinmap extension is used we should get some ROM savings:
149
+
When you use the static pin map extension, you save on ROM:
151
150
152
151
```
153
152
| Module | .text | .data | .bss |
@@ -160,24 +159,22 @@ When static pinmap extension is used we should get some ROM savings:
Total Static RAM memory (data + bss): 205782(+0) bytes
172
-
Total Flash memory (text + data): 44554(-1010) bytes
170
+
Total static RAM memory (data + bss): 205782(+0) bytes
171
+
Total flash memory (text + data): 44554(-1010) bytes
173
172
```
174
173
175
-
Run FPGA tests to check if your implementation is valid:
174
+
Run FPGA tests to check whether your implementation is valid:
176
175
177
176
```
178
177
mbed test -t ARM -m K64F -n tests-mbed_hal_fpga_ci_test_shield*
179
178
```
180
179
181
-
**Note:**
182
-
Your target must be ready to run FPGA-Test-Shield tests.
183
-
Currently the following peripherals can be tested: `Analogin`, `SPI`, `I2C`, `PWM`, `UART`.
180
+
<spanclass="notes">**Note:** Your target must be ready to run FPGA-Test-Shield tests. You can test the following peripherals: `Analogin`, `SPI`, `I2C`, `PWM`, `UART`.</span>
0 commit comments