Skip to content

Commit 108effe

Browse files
committed
Resore initial edits provided by Amanda to static_pinmap.md
Make initial edits, mostly for active voice, formatting and spelling.
1 parent ca62a4e commit 108effe

File tree

1 file changed

+113
-109
lines changed

1 file changed

+113
-109
lines changed

docs/porting/target/static_pinmap.md

Lines changed: 113 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,121 @@
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-
### Implementing static pin-map extension
20+
## Implementing static pin map extension
2221

23-
If you want to make static pinmap available on your platform please perform the following steps:  
22+
If you want to make static pin map available on your platform please perform the following steps:  
2423

2524
- 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.
25+
- `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()`.
26+
- `xxx_init_direct()` performs peripheral initialization using given static pin map structure.
2827

29-
Example implementation below:
28+
Example implementation:
3029

31-
```
32-
void xxx_init_direct(xxx_t *obj, const PinMap *pinmap)
33-
{
34-
    obj->spi.instance = pinmap->peripheral;
30+
```
31+
void xxx_init_direct(xxx_t *obj, const PinMap *pinmap)
32+
{
33+
obj->spi.instance = pinmap->peripheral;
3534
36-
    // pin out the xxx pins
37-
    pin_function(pinmap->pin, pinmap->function);
38-
    pin_mode(pinmap->pin, PullNone);
35+
// pin out the xxx pins
36+
pin_function(pinmap->pin, pinmap->function);
37+
pin_mode(pinmap->pin, PullNone);
3938
40-
    // Some additional init code
41-
}
39+
// Some additional init code
40+
}
4241
43-
void xxx_init(xxx_t *obj, PinName pin)
44-
{
45-
    int peripheral = (int)pinmap_peripheral(pin, PinMap_xxx);
46-
    int function = (int)pinmap_find_function(pin, PinMap_xxx);
42+
void xxx_init(xxx_t *obj, PinName pin)
43+
{
44+
int peripheral = (int)pinmap_peripheral(pin, PinMap_xxx);
45+
int function = (int)pinmap_find_function(pin, PinMap_xxx);
4746
48-
    const PinMap static_pinmap = {pin, peripheral, function};
47+
const PinMap static_pinmap = {pin, peripheral, function};
4948
50-
    xxx_init_direct(obj, &static_pinmap);
51-
}
52-
```
49+
xxx_init_direct(obj, &static_pinmap);
50+
}
51+
```
5352

5453
- Provide `constexpr` pin-map tables in the header file.
5554

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

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`.
57+
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.
6158

62-
Example pin-map table below:
59+
<span class="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>
6360

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-
};
61+
Example pin map table:
7762

78-
```
63+
```
64+
#include <mstd_cstddef>
7965
80-
- Provide macros for pin-map tables  
66+
MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_ADC[] = {
67+
{P0_23, ADC0_SE0, 0},
68+
{P0_10, ADC0_SE1, 0},
69+
{P0_31, ADC0_SE3, 0},
70+
{P1_8, ADC0_SE4, 0},
71+
{P2_0, ADC0_SE5, 0},
72+
{P2_13, ADC0_SE6, 0},
73+
{P2_11, ADC0_SE7, 0},
74+
{NC , NC , 0}
75+
};
8176
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:
77+
```
8378

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-
```
79+
- Provide macros for pin map tables.
10780

108-
- Provide `STATIC_PINMAP_READY` macro in `PinNames.h`  
81+
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:
10982

110-
Adding this macro will enable the static pin-map support for the target.
83+
```
84+
#define PINMAP_ANALOGIN [PinMap ADC]
85+
#define PINMAP_ANALOGOUT [PinMap DAC]
86+
#define PINMAP_I2C_SDA [PinMap I2C SDA]
87+
#define PINMAP_I2C_SCL [PinMap I2C SCL]
88+
#define PINMAP_UART_TX [PinMap UART TX]
89+
#define PINMAP_UART_RX [PinMap UART RX]
90+
#define PINMAP_UART_CTS [PinMap UART CTS]
91+
#define PINMAP_UART_RTS [PinMap UART RTS]
92+
#define PINMAP_SPI_SCLK [PinMap SPI SCLK]
93+
#define PINMAP_SPI_MOSI [PinMap SPI MOSI]
94+
#define PINMAP_SPI_MISO [PinMap SPI MISO]
95+
#define PINMAP_SPI_SSEL [PinMap SPI SSEL]
96+
#define PINMAP_PWM [PinMap PWM]
97+
#define PINMAP_QSPI_DATA0 [PinMap QSPI DATA0]
98+
#define PINMAP_QSPI_DATA1 [PinMap QSPI DATA1]
99+
#define PINMAP_QSPI_DATA2 [PinMap QSPI DATA2]
100+
#define PINMAP_QSPI_DATA3 [PinMap QSPI DATA3]
101+
#define PINMAP_QSPI_SCLK [PinMap QSPI SCLK]
102+
#define PINMAP_QSPI_SSEL [PinMap QSPI SSEL]
103+
#define PINMAP_CAN_RD [PinMap CAN RD]
104+
#define PINMAP_CAN_TD [PinMap CAN RD]
105+
```
111106

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-
```
107+
- Provide `STATIC_PINMAP_READY` macro in `PinNames.h`  
108+
109+
Adding this macro enables the static pin map support for the target.
110+
111+
```
112+
/* If this macro is defined, you can use constexpr utility functions for pin map search. */
113+
#define STATIC_PINMAP_READY 1
114+
```
116115

117-
### Example usage/testing
116+
## Testing
118117

119-
Use code below to check if static pinmap extension works.
118+
Use the code below to test the static pin map extension:
120119

121120
```
122121
int main()
@@ -136,36 +135,41 @@ int main()
136135
}
137136
```
138137

139-
When static pinmap extension is used we should get some ROM savings:  
138+
When you use the static pin map extension, you save on ROM:  
140139

141140
```
142-
| Module                          |        .text |   .data |       .bss |
141+
| Module | .text | .data | .bss |
143142
|---------------------------------|--------------|---------|------------|
144-
| [lib]\c_w.l                     |    11175(+0) |  16(+0) |    348(+0) |
145-
| [lib]\fz_wm.l                   |       34(+0) |   0(+0) |      0(+0) |
146-
| [lib]\m_wm.l                    |       48(+0) |   0(+0) |      0(+0) |
147-
| anon$$obj.o                     |       32(+0) |   0(+0) | 197888(+0) |
148-
| drivers\source                  |      192(+0) |   0(+0) |      0(+0) |
149-
| features\netsocket              |      143(+0) |   0(+0) |      0(+0) |
150-
| hal\mbed_critical_section_api.o |      154(+0) |   0(+0) |      2(+0) |
151-
| hal\mbed_gpio.o                 |       96(+0) |   0(+0) |      0(+0) |
152-
| hal\mbed_pinmap_common.o        |      0(-272) |   0(+0) |      0(+0) |  // removed pinmap lib (this is common for all peripherals)
153-
| hal\mbed_ticker_api.o           |      978(+0) |   0(+0) |      0(+0) |
154-
| hal\mbed_us_ticker_api.o        |      114(+0) |   4(+0) |     65(+0) |
155-
| main.o                          |      70(+32) |   0(+0) |      0(+0) |  // extra space for static pinmap structure in application
156-
| platform\source                 |    5683(+46) |  64(+0) |    249(+0) |  // extra space for UART static pinmap structure to initialize the console
157-
| rtos\source                     |     8990(+0) | 168(+0) |   6626(+0) |
158-
| targets\TARGET_Freescale        |  16581(-816) |  12(+0) |    340(+0) |  // removed pinmaps + driver code reduction
159-
| Subtotals                       | 44290(-1010) | 264(+0) | 205518(+0) |
143+
| [lib]\c_w.l | 11175(+0) | 16(+0) | 348(+0) |
144+
| [lib]\fz_wm.l | 34(+0) | 0(+0) | 0(+0) |
145+
| [lib]\m_wm.l | 48(+0) | 0(+0) | 0(+0) |
146+
| anon$$obj.o | 32(+0) | 0(+0) | 197888(+0) |
147+
| drivers\source | 192(+0) | 0(+0) | 0(+0) |
148+
| features\netsocket | 143(+0) | 0(+0) | 0(+0) |
149+
| hal\mbed_critical_section_api.o | 154(+0) | 0(+0) | 2(+0) |
150+
| hal\mbed_gpio.o | 96(+0) | 0(+0) | 0(+0) |
151+
| hal\mbed_pinmap_common.o | 0(-272) | 0(+0) | 0(+0) | // removed pinmap lib (this is common for all peripherals)
152+
| hal\mbed_pinmap_common.o | 0(-272) | 0(+0) | 0(+0) | // remove pinmap lib (this is common for all peripherals)
153+
| hal\mbed_ticker_api.o | 978(+0) | 0(+0) | 0(+0) |
154+
| hal\mbed_us_ticker_api.o | 114(+0) | 4(+0) | 65(+0) |
155+
| main.o | 70(+32) | 0(+0) | 0(+0) | // extra space for static pinmap structure in application
156+
| platform\source | 5683(+46) | 64(+0) | 249(+0) | // extra space for UART static pinmap structure to initialize the console
157+
| main.o | 70(+32) | 0(+0) | 0(+0) | // extra space for static pin map structure in application
158+
| platform\source | 5683(+46) | 64(+0) | 249(+0) | // extra space for UART static pin map structure to initialize the console
159+
| rtos\source | 8990(+0) | 168(+0) | 6626(+0) |
160+
| targets\TARGET_Freescale | 16581(-816) | 12(+0) | 340(+0) | // removed pinmaps + driver code reduction
161+
| targets\TARGET_Freescale | 16581(-816) | 12(+0) | 340(+0) | // remove pin maps and driver code reduction
162+
| Subtotals | 44290(-1010) | 264(+0) | 205518(+0) |
160163
Total Static RAM memory (data + bss): 205782(+0) bytes
161164
Total Flash memory (text + data): 44554(-1010) bytes
165+
Total static RAM memory (data + bss): 205782(+0) bytes
166+
Total flash memory (text + data): 44554(-1010) bytes
162167
```
163168

164-
Run FPGA tests to check if your implementation is valid:
169+
Run FPGA tests to check whether your implementation is valid:
165170

166171
```
167172
 mbed test -t ARM -m K64F -n tests-mbed_hal_fpga_ci_test_shield*
168173
```
169174

170-
**Note:**
171-
Your target must be ready to run FPGA-Test-Shield tests.
175+
<span class="notes">**Note:** Your target must be ready to run FPGA-Test-Shield tests.</span>

0 commit comments

Comments
 (0)