Skip to content

Commit e3ab513

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 e3ab513

File tree

1 file changed

+113
-107
lines changed

1 file changed

+113
-107
lines changed

docs/porting/target/static_pinmap.md

Lines changed: 113 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,123 @@
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

55
### Overview and background
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.
7+
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.
88

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.
9+
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.
1010

1111
Supported peripherals:
12-
 - `PWM`
13-
 - `AnalogIn`
14-
 - `AnalogOut`
15-
 - `SPI`
16-
 - `I2C`
17-
 - `UART`
18-
 - `QSPI`
19-
 - `CAN`
12+
13+
- `PWM`.
14+
- `AnalogIn`.
15+
- `AnalogOut`.
16+
- `SPI`.
17+
- `I2C`.
18+
- `UART`.
19+
- `QSPI`.
20+
- `CAN`.
2021

21-
### Implementing static pin-map extension
22+
## Implementing static pin map extension
2223

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

2526
- 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.
27+
- `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()`.
28+
- `xxx_init_direct()` performs peripheral initialization using given static pin map structure.
2829

29-
Example implementation below:
30+
Example implementation:
3031

31-
```
32-
void xxx_init_direct(xxx_t *obj, const PinMap *pinmap)
33-
{
34-
    obj->spi.instance = pinmap->peripheral;
32+
```
33+
void xxx_init_direct(xxx_t *obj, const PinMap *pinmap)
34+
{
35+
obj->spi.instance = pinmap->peripheral;
3536
36-
    // pin out the xxx pins
37-
    pin_function(pinmap->pin, pinmap->function);
38-
    pin_mode(pinmap->pin, PullNone);
37+
// pin out the xxx pins
38+
pin_function(pinmap->pin, pinmap->function);
39+
pin_mode(pinmap->pin, PullNone);
3940
40-
    // Some additional init code
41-
}
41+
// Some additional init code
42+
}
4243
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);
44+
void xxx_init(xxx_t *obj, PinName pin)
45+
{
46+
int peripheral = (int)pinmap_peripheral(pin, PinMap_xxx);
47+
int function = (int)pinmap_find_function(pin, PinMap_xxx);
4748
48-
    const PinMap static_pinmap = {pin, peripheral, function};
49+
const PinMap static_pinmap = {pin, peripheral, function};
4950
50-
    xxx_init_direct(obj, &static_pinmap);
51-
}
52-
```
51+
xxx_init_direct(obj, &static_pinmap);
52+
}
53+
```
5354

5455
- Provide `constexpr` pin-map tables in the header file.
5556

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

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`.
59+
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.
6160

62-
Example pin-map table below:
61+
<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>
6362

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

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

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

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

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

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

117-
### Example usage/testing
118+
## Testing
118119

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

121122
```
122123
int main()
@@ -136,36 +137,41 @@ int main()
136137
}
137138
```
138139

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

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

164-
Run FPGA tests to check if your implementation is valid:
171+
Run FPGA tests to check whether your implementation is valid:
165172

166173
```
167174
 mbed test -t ARM -m K64F -n tests-mbed_hal_fpga_ci_test_shield*
168175
```
169176

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

0 commit comments

Comments
 (0)