Skip to content

Commit 359178b

Browse files
committed
fix naming: explicit to static and update Overview and background section
1 parent 5b543f0 commit 359178b

File tree

1 file changed

+45
-43
lines changed

1 file changed

+45
-43
lines changed

docs/porting/target/explicit_pinmap.md renamed to docs/porting/target/static_pinmap.md

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
1-
<h2 id="explicit-pinmap-port">Explicit Pinmap extension</h2>
1+
<h2 id="static-pinmap-port">Static Pinmap extension</h2>
22

3-
The **Explicit Pinmap extension** allows the peripheral configuration (pin/periheral/function) to be explicitly specified in the HAL API function.
3+
The **Static Pinmap extension** allows the peripheral configuration (pin/periheral/function) to be staticly specified in the HAL API function.
44

55
### Overview and background
66

7-
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. Explicit pinmap extension provides additional HAL API/constructors which takes pinmap as a parameter where pin/peripheral/function is specified explicitly and there is no need to use the pinmap tables.
8-
9-
Supported peripherals:
10-
 - `PWM`
11-
 - `AnalogIn`
12-
 - `AnalogOut`
13-
 - `SPI`
14-
 - `I2C`
15-
 - `UART`
16-
 - `QSPI`
17-
 - `CAN`
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.
10+
11+
Supported peripherals:
12+
 - `PWM`
13+
 - `AnalogIn`
14+
 - `AnalogOut`
15+
 - `SPI`
16+
 - `I2C`
17+
 - `UART`
18+
 - `QSPI`
19+
 - `CAN`
1820

1921
### Requirements and assumptions
2022

21-
1. Provide types which will hold explicit pinmaps for peripherals(`PWM`, `AnalogIn`, `AnalogOut`, `SPI`, `I2C`, `UART`, `QSPI`, `CAN`).
22-
2. Provide `xxx_init_direct(xxx_t *obj, explicit_pinmap_t *)` functions to HAL API (these functions will not use pinmap tables).
23-
3. Provide additional constructors in drivers layer which will use the `xxx_init_direct(xxx_t *obj, explicit_pinmap_t*)` HAL functions.
24-
4. Provide default weak implementations of `xxx_init_direct(explicit_pinmap_t *)` functions. These functions will call standard `xxx_init(xxx_t *obj, PinName, ...)` function (backward compatibility for targets which do not support explicit pinmap mechanism).
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).
2527
5. Provide `constexpr` utility functions to lookup for pin mapping in compile time (requires C++14).
2628
6. Provide `constexpr` pin-map tables in the header file.
2729
7. Provide macros for the pin-map tables.
28-
8. Provide `EXPLICIT_PINMAP_READY` macro in `PinNames.h`.
30+
8. Provide `STATIC_PINMAP_READY` macro in `PinNames.h`.
2931

30-
### Implementing explicit pin-map extension
32+
### Implementing static pin-map extension
3133

32-
Most of the above points are already implemented. If you want to make explicit pinmap available on your platform please perform the following steps:  
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:  
3335

34-
- Provide implementation of `xxx_init_direct(xxx_t *obj, explicit_pinmap_t *)` function (which does not use pinmap tables).
35-
  - `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()`.
36-
  - `xxx_init_direct()` will perform peripheral initialization using given explicit pinmap structure.
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.
3739

3840
Example implementation below:
3941

@@ -54,18 +56,18 @@ void xxx_init(xxx_t *obj, PinName pin)
5456
    int peripheral = (int)pinmap_peripheral(pin, PinMap_xxx);
5557
    int function = (int)pinmap_find_function(pin, PinMap_xxx);
5658
57-
    const PinMap explicit_pinmap = {pin, peripheral, function};
59+
    const PinMap static_pinmap = {pin, peripheral, function};
5860
59-
    xxx_init_direct(obj, &explicit_pinmap);
61+
    xxx_init_direct(obj, &static_pinmap);
6062
}
6163
```
6264

6365
- Provide `constexpr` pin-map tables in the header file.
6466

65-
Move pinmap tables from `PeripheralPins.c` to `PeripheralPinMaps.h` (create new file) and add `constexpr` specifier in the pin-map table declarations.
66-
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.
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.
6769

68-
**Note:**
70+
**Note:**
6971
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`.  
7072

7173
Example pin-map table below:
@@ -114,38 +116,38 @@ Since pin-map table names are not common across all targets the following macros
114116
#define PINMAP_CAN_TD [PinMap CAN RD]
115117
```
116118

117-
- Provide `EXPLICIT_PINMAP_READY` macro in `PinNames.h`  
119+
- Provide `STATIC_PINMAP_READY` macro in `PinNames.h`  
118120

119-
Adding this macro will enable the explicit pin-map support for the target.
121+
Adding this macro will enable the static pin-map support for the target.
120122

121123
```
122124
/* If this macro is defined, then constexpr utility functions for pin-map seach can be used. */
123-
#define EXPLICIT_PINMAP_READY 1
125+
#define STATIC_PINMAP_READY 1
124126
```
125127

126128
### Example usage/testing
127129

128-
Use code below to check if explicit pinmap extension works.
130+
Use code below to check if static pinmap extension works.
129131

130132
```
131133
int main()
132134
{
133135
    /* Regular use */
134136
    SPI spi(D1, D2, D3, D4);
135137
136-
    /* Explicit pinmap */
137-
    const spi_pinmap_t explicit_spi_pinmap = {SPI_1, D1, 2, D2, 2, D3, 2, D4, 2};
138-
    SPI spi(explicit_spi_pinmap);
138+
    /* Static pinmap */
139+
    const spi_pinmap_t static_spi_pinmap = {SPI_1, D1, 2, D2, 2, D3, 2, D4, 2};
140+
    SPI spi(static_spi_pinmap);
139141
140-
    /* Explicit pinmap with constexpr utility function */
141-
    constexpr spi_pinmap_t explicit_spi_pinmap = get_spi_pinmap(D1, D2, D3, D4);
142-
    SPI spi(explicit_spi_pinmap);
142+
    /* Static pinmap with constexpr utility function */
143+
    constexpr spi_pinmap_t static_spi_pinmap = get_spi_pinmap(D1, D2, D3, D4);
144+
    SPI spi(static_spi_pinmap);
143145
144146
    return 0;
145147
}
146148
```
147149

148-
When explicit pinmap extension is used we should get some ROM savings:  
150+
When static pinmap extension is used we should get some ROM savings:  
149151

150152
```
151153
| Module                          |        .text |   .data |       .bss |
@@ -161,8 +163,8 @@ When explicit pinmap extension is used we should get some ROM savings:  
161163
| hal\mbed_pinmap_common.o        |      0(-272) |   0(+0) |      0(+0) |  // removed pinmap lib (this is common for all peripherals)
162164
| hal\mbed_ticker_api.o           |      978(+0) |   0(+0) |      0(+0) |
163165
| hal\mbed_us_ticker_api.o        |      114(+0) |   4(+0) |     65(+0) |
164-
| main.o                          |      70(+32) |   0(+0) |      0(+0) |  // extra space for explicit pinmap structure in application
165-
| platform\source                 |    5683(+46) |  64(+0) |    249(+0) |  // extra space for UART explicit pinmap structure to initialize the console
166+
| main.o                          |      70(+32) |   0(+0) |      0(+0) |  // extra space for static pinmap structure in application
167+
| platform\source                 |    5683(+46) |  64(+0) |    249(+0) |  // extra space for UART static pinmap structure to initialize the console
166168
| rtos\source                     |     8990(+0) | 168(+0) |   6626(+0) |
167169
| targets\TARGET_Freescale        |  16581(-816) |  12(+0) |    340(+0) |  // removed pinmaps + driver code reduction
168170
| Subtotals                       | 44290(-1010) | 264(+0) | 205518(+0) |
@@ -176,6 +178,6 @@ Run FPGA tests to check if your implementation is valid:
176178
 mbed test -t ARM -m K64F -n tests-mbed_hal_fpga_ci_test_shield*
177179
```
178180

179-
**Note:**
180-
Your target must be ready to run FPGA-Test-Shield tests.
181+
**Note:**
182+
Your target must be ready to run FPGA-Test-Shield tests.
181183
Currently the following peripherals can be tested: `Analogin`, `SPI`, `I2C`, `PWM`, `UART`.

0 commit comments

Comments
 (0)