Skip to content

Commit fc679b7

Browse files
author
Amanda Butler
authored
Make initial edits to static_pinmap.md
Make initial edits, mostly for active voice, formatting and spelling.
1 parent 359178b commit fc679b7

File tree

1 file changed

+119
-122
lines changed

1 file changed

+119
-122
lines changed

docs/porting/target/static_pinmap.md

Lines changed: 119 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,132 @@
1-
<h2 id="static-pinmap-port">Static Pinmap extension</h2>
1+
<h1 id="static-pinmap-port">Static Pinmap extension</h1>
22

3-
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.
44

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.
66

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.
108

119
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`.
2019

21-
### Requirements and assumptions
20+
## Assumptions
2221

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).
2726
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` pin map tables in the header file.
28+
7. Provide macros for the pin map tables.
3029
8. Provide `STATIC_PINMAP_READY` macro in `PinNames.h`.
3130

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.
39-
40-
Example implementation below:
41-
42-
```
43-
void xxx_init_direct(xxx_t *obj, const PinMap *pinmap)
44-
{
45-
    obj->spi.instance = pinmap->peripheral;
46-
47-
    // pin out the xxx pins
48-
    pin_function(pinmap->pin, pinmap->function);
49-
    pin_mode(pinmap->pin, PullNone);
50-
51-
    // Some additional init code
52-
}
53-
54-
void xxx_init(xxx_t *obj, PinName pin)
55-
{
56-
    int peripheral = (int)pinmap_peripheral(pin, PinMap_xxx);
57-
    int function = (int)pinmap_find_function(pin, PinMap_xxx);
58-
59-
    const PinMap static_pinmap = {pin, peripheral, function};
60-
61-
    xxx_init_direct(obj, &static_pinmap);
62-
}
63-
```
31+
## Implementing static pin map extension
32+
33+
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 pin map structure and calls void `xxx_init_direct()`.
37+
  - `xxx_init_direct()` performs peripheral initialization using given static pin map structure.
38+
39+
Example implementation:
40+
41+
```
42+
void xxx_init_direct(xxx_t *obj, const PinMap *pinmap)
43+
{
44+
    obj->spi.instance = pinmap->peripheral;
45+
46+
    // pin out the xxx pins
47+
    pin_function(pinmap->pin, pinmap->function);
48+
    pin_mode(pinmap->pin, PullNone);
49+
50+
    // Some additional init code
51+
}
52+
53+
void xxx_init(xxx_t *obj, PinName pin)
54+
{
55+
    int peripheral = (int)pinmap_peripheral(pin, PinMap_xxx);
56+
    int function = (int)pinmap_find_function(pin, PinMap_xxx);
57+
58+
    const PinMap static_pinmap = {pin, peripheral, function};
59+
60+
    xxx_init_direct(obj, &static_pinmap);
61+
}
62+
```
6463

6564
- Provide `constexpr` pin-map tables in the header file.
6665

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 pin map 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+
<span class="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 pin map 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 pin map tables.
91+
92+
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:
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+
```
118117

119118
- Provide `STATIC_PINMAP_READY` macro in `PinNames.h`  
120119

121-
Adding this macro will enable the static pin-map support for the target.
120+
Adding this macro enables the static pin map support for the target.
122121

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 pin map search. */
124+
#define STATIC_PINMAP_READY 1
125+
```
127126

128-
### Example usage/testing
127+
## Testing
129128

130-
Use code below to check if static pinmap extension works.
129+
Use the code below to test the static pin map extension:
131130

132131
```
133132
int main()
@@ -147,7 +146,7 @@ int main()
147146
}
148147
```
149148

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:  
151150

152151
```
153152
| Module                          |        .text |   .data |       .bss |
@@ -160,24 +159,22 @@ When static pinmap extension is used we should get some ROM savings:  
160159
| features\netsocket              |      143(+0) |   0(+0) |      0(+0) |
161160
| hal\mbed_critical_section_api.o |      154(+0) |   0(+0) |      2(+0) |
162161
| hal\mbed_gpio.o                 |       96(+0) |   0(+0) |      0(+0) |
163-
| hal\mbed_pinmap_common.o        |      0(-272) |   0(+0) |      0(+0) |  // removed pinmap lib (this is common for all peripherals)
162+
| hal\mbed_pinmap_common.o        |      0(-272) |   0(+0) |      0(+0) | // remove pinmap lib (this is common for all peripherals)
164163
| hal\mbed_ticker_api.o           |      978(+0) |   0(+0) |      0(+0) |
165164
| hal\mbed_us_ticker_api.o        |      114(+0) |   4(+0) |     65(+0) |
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
165+
| main.o                          |      70(+32) |   0(+0) |      0(+0) | // extra space for static pin map structure in application
166+
| platform\source                 |    5683(+46) |  64(+0) |    249(+0) | // extra space for UART static pin map structure to initialize the console
168167
| rtos\source                     |     8990(+0) | 168(+0) |   6626(+0) |
169-
| targets\TARGET_Freescale        |  16581(-816) |  12(+0) |    340(+0) |  // removed pinmaps + driver code reduction
168+
| targets\TARGET_Freescale        |  16581(-816) |  12(+0) |    340(+0) | // remove pin maps and driver code reduction
170169
| Subtotals                       | 44290(-1010) | 264(+0) | 205518(+0) |
171-
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
173172
```
174173

175-
Run FPGA tests to check if your implementation is valid:
174+
Run FPGA tests to check whether your implementation is valid:
176175

177176
```
178177
 mbed test -t ARM -m K64F -n tests-mbed_hal_fpga_ci_test_shield*
179178
```
180179

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+
<span class="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

Comments
 (0)