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 **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.
4
4
5
5
### Overview and background
6
6
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`
18
20
19
21
### Requirements and assumptions
20
22
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).
25
27
5. Provide `constexpr` utility functions to lookup for pin mapping in compile time (requires C++14).
26
28
6. Provide `constexpr` pin-map tables in the header file.
27
29
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`.
29
31
30
-
### Implementing explicit pin-map extension
32
+
### Implementing static pin-map extension
31
33
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:
33
35
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.
- Provide `constexpr` pin-map tables in the header file.
64
66
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.
67
69
68
-
**Note:**
70
+
**Note:**
69
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`.
70
72
71
73
Example pin-map table below:
@@ -114,38 +116,38 @@ Since pin-map table names are not common across all targets the following macros
114
116
#define PINMAP_CAN_TD [PinMap CAN RD]
115
117
```
116
118
117
-
- Provide `EXPLICIT_PINMAP_READY` macro in `PinNames.h`
119
+
- Provide `STATIC_PINMAP_READY` macro in `PinNames.h`
118
120
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.
120
122
121
123
```
122
124
/* 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
124
126
```
125
127
126
128
### Example usage/testing
127
129
128
-
Use code below to check if explicit pinmap extension works.
130
+
Use code below to check if static pinmap extension works.
0 commit comments