1# Microchip PIC32C/PIC32M pin configurations 2 3This directory contains a set of files describing valid pin configurations for 4multiple Microchiop PIC32C/PIC32M MCUs (PIC32C/PIC32M) devices. This configuration files maps a 5pin to a peripheral signal which multiplex, at end, I/O lines pins. For example, 6`sercom1, pad1` signal can be mapped to `PA01`, `PA17`, `PC23` or `PC28` 7for `PIC32CX` SoC. These configurations can be used to generate valid pin 8mappings. 9 10Microchip PIC32C devices use distinct controllers to configure signal 11multiplexing: PORT (PIC32CK, PIC32CM, PIC32CX) or PIO(PIC32CZ). In general, all devices 12use similar definitions where each pin has one or more associated alternate 13function. These alternate functions can be sometimes changed using especific 14system functionality. The struct created to map the alternate functions is 15shared between all controllers and was concepted to be more close possible to 16datasheet tables. 17 18In the following sections the expected file format is described. 19 20## Configuration 21 22All fields are common, independently of the pin controller, and all fields are 23mandatory. 24 25- `model`: Always defined as `microchip,sam` 26- `family`: Family name like: `ck`, `cm`, `cx`, `cz` 27- `map`: Define the macro that will be used to generate code for an specific 28 controller. 29 Currently `SAM_PINMUX` is used for PIC32CXSG. 30- `series`: The SoC series set 31- `revisions` (optional): The SoC die revision which exists for sam0 series. 32- `variants`: Each variant has a different set of valid pin combinations because 33 of a different number of pins. 34- `pins` (required): The pin map itself 35 36Example: 37 38The below `yaml` snip have all the common fields defined. It defines few 39aleatory pins to help understand the definition schema. 40 41```yaml 42# 43# Pin codes: 44# 45# - 064 pins: 64 46# - 080 pins: 80 47# - 100 pins: 100 48# - 128 pins: 128 49# 50# SoC Revision (variant) supported: 51# - A = Default Variant 52 53model: microchip,pic32cxsg 54 55family: cx 56 57map: PIC32CX_PINMUX 58 59series: [cx1025sg41, cx1025sg60, cx1025sg61] 60 61variants: 62 - pincode: 064 63 series: [cx1025sg41, cx1025sg60, cx1025sg61] 64 - pincode: 080 65 series: [cx1025sg41] 66 - pincode: 100 67 series: [cx1025sg41, cx1025sg60, cx1025sg61] 68 - pincode: 128 69 series: [cx1025sg41, cx1025sg60, cx1025sg61] 70 71pins: 72 pb08: 73 pincodes: [064, 080, 100, 128] 74 periph: 75 - [a, eic, extint8] 76 - [b, adc0, ain2] 77 - [b, adc1, ain0] 78 - [b, ptc, xy1] 79 - [d, sercom4, pad0] 80 - [e, tc4, wo0] 81 - [n, ccl, in8] 82 pb09: 83 pincodes: [064, 080, 100, 128] 84 periph: 85 - [a, eic, extint9] 86 - [b, adc0, ain3] 87 - [b, adc1, ain1] 88 - [b, ptc, xy2] 89 - [d, sercom4, pad1] 90 - [e, tc4, wo1] 91 - [n, ccl, out2] 92 pa04: 93 pincodes: [064, 080, 100, 128] 94 periph: 95 - [a, eic, extint4] 96 - [b, anaref, vrefb] 97 - [b, adc0, ain4] 98 - [b, ac, ain0] 99 - [b, ptc, xy3] 100 - [d, sercom0, pad0] 101 - [e, tc0, wo0] 102 - [n, ccl, in0] 103 pa05: 104 pincodes: [064, 080, 100, 128] 105 periph: 106 - [a, eic, extint5] 107 - [b, adc0, ain5] 108 - [b, ac, ain1] 109 - [b, dac, vout1] 110 - [d, sercom0, pad1] 111 - [e, tc0, wo1] 112 - [n, ccl, in1] 113 pa06: 114 pincodes: [064, 080, 100, 128] 115 periph: 116 - [a, eic, extint6] 117 - [b, anaref, vrefc] 118 - [b, adc0, ain6] 119 - [b, ac, ain2] 120 - [b, ptc, xy4] 121 - [d, sercom0, pad2] 122 - [e, tc1, wo0] 123 - [i, sdhc0, cd] 124 - [n, ccl, in2] 125``` 126 127The `series` key define a list of SoC models `[cx1025sg41, cx1025sg60, cx1025sg61]`. This list 128is used to generate file names and map peripherals. 129 130Some pic32 SoC have optimized pins in some revisions. To differentiate those a 131new mux table should be defined. The `revisions` help to identify correct 132pinctrl files by sufix. 133 134The `variants` key define a list of available packages by SoC series. This means 135that for `pincode: 64`, which is 64 pins packages, there are valid combination 136of `cx1025sg41` and `cx1025sg61` pin mux. Note, some devices my present some 137challenges like define a part number which uses same pin code with different 138pin counts. For that ones, we add `exception: y` property. The exception will 139add a `WARNING` message to uses in the auto generated file asking to user look 140datasheet. Any variation with exception must map all pins to allow users access 141functionality. 142 143The `pins` section is a variable length list of pin definitions. Each entry is 144a pin itself composed by one mandatory properties which is `pincodes` and many 145optional properties: `periph`, `extra`, `system`, `lpm`, `wakeup`. The `pincode` 146instructs the engine to generate pin definitions only for those packages were 147pin is, in fact, available. The `periph` is the set of multiplexed peripheral 148signals. It is a variable length list where each entry is a list. Each peripheral 149list entry is composed of 4 fields, where the first 3 are mandatory. The peripheral 150list represents: 151 - `alternate function index` 152 - `peripheral [instance]` 153 - `signal` 154 - `SoC/pincode exclusion list` (optional) 155 156Additionally some SoCs define special pin configuration. In the datasheet user 157can find a column named `extra` and another as `systems`. The syntax is the 158same as `periph`. The `lpm` is reserved for future use. Some SoCs may require 159special pin configuration to allow system consume less possible power. The 160special `wakeup` pin definition configure the pin to be used to wake-up the 161core power supply, see Supply Controller SUPC for more details. 162 163Example: 164 165At below `yaml` snip code defines `pc16` pin: 166 167```yaml 168 pc16: 169 pincodes: [ 080, 100, 128] 170 periph: 171 - [a, eic, extint0] 172 - [c, sercom6, pad0] 173 - [d, sercom0, pad1] 174 - [f, tcc0, wo0] 175 - [g, pdec, qdi0] 176 - [l, gmac, gtx2] 177``` 178 179This means, that port `C` pin 16 is available for packages `100` and `128`. The 180alternate function available for these pin is that: 181 - at position `a` the `eic` controller have access to signal `extint0` 182 - at position `c` the signal `pad0` can be defined for `sercom6` 183 - at position `d` the signal `pad1` can be defined for `sercom0` 184 - at position `f` the `tcc0` can output signal `wo0` 185 - at position `g` the `pdec` uses `qdi0` as quadrature input 0. 186 - at position `l` the `gmac` define signal `gtx2` 187 188In this case, besides `n` and `p` packages tells to engine that pin `pc16` must 189be generated for the entire SoC series `cx1025sg41, cx1025sg60, cx1025sg61` the engine allows 190to deliberate exclude some signal combination. 191 192The exclusion list can have both SoC `series` and `pincodes`. This allow create 193less files and give better granularity. The next example shows how to drop `smc` 194functionality in the `SAM4E` SoC. In this case, only one series can accomodate 195all variations and the tunning is made using `pincode` at periph config. 196 197```yaml 198# Pin codes: 199# 200# - 100 pins: c 201# - 144 pins: e 202 203model: microchip,pic32cx 204 205family: cx 206 207map: SAM_PINMUX 208 209series: [4eX] 210 211variants: 212 - pincode: c 213 series: [4eX] 214 - pincode: e 215 series: [4eX] 216 217pins: 218 pa0: 219 pincodes: [c, e] 220 periph: 221 - [a, pwm, pwmh0] 222 - [b, tc0, tioa0] 223 - [c, smc, a17, [c]] 224``` 225 226It is recommended use one filter at exclusion list. When necessary combine both 227`series` and `pincodes` the exclusion will operate first in the series and then 228will lookup by pincode. 229 230The next example shows how to specify `extra`, `wakeup` and `system` functions. 231 232```yaml 233 pb5: 234 pincodes: [c, e] 235 periph: 236 - [a, twi1, twck1] 237 - [b, pwm, pwml0] 238 extra: 239 - [x, adc, ad3] 240 wakeup: 241 - [x, supc, wkup13] 242 system: 243 - [s, jtag, tdo] 244 - [s, swd, traceswo] 245``` 246 247## Auto Generated Code 248 249After define all pins the user should run `scripts/sampinctrl.py` script to 250auto generate Zephyr RTOS devicetree pinctrl definitions. See `scripts/README` 251for instructions how to do it. 252 253### Output Format 254 255The output format define constants to be used inside devitree pins definitions, 256see below snip of output: 257 258```c 259/* 260 * Autogenerated file 261 * 262 * SPDX-License-Identifier: Apache-2.0 263 */ 264 265#include <dt-bindings/pinctrl/microchip_pic32_pinctrl.h> 266 267/* 268 * WARNING: this variant has package exception. 269 * 270 * Read datasheet topics related to I/O Multiplexing and Considerations or 271 * Peripheral Signal Multiplexing on I/O Lines for more information. 272 */ 273 274/* pa0a_eic_extint0 */ 275#define PA0A_EIC_EXTINT0 \ 276 PIC32_PINMUX(a, 0, a, periph) 277``` 278 279The output format uses the compressed representation which of: 280 - port index (PIOx, GPIOx or PORTx) 281 - pin number 282 - alternate function index 283 - function (gpio, periph, extra, system, lpm) 284 285In this case `PA0A_EIC_EXTINT0` is at PORT `a` pin `0` using alternate 286function `a`, which selects pin for external interrupt controller `EIC` 287interrupt `extint0`. 288 289 290## Devicetree definitions 291 292The pinctrl devicetree entries follow current Zephyr RTOS conventions. See 293below example which define serial console for `PIC32CX SGxx Curiosity Ultra` board. 294 295```devicetree 296#include <dt-bindings/pinctrl/pic32cxcx1025sg61128-pinctrl.h> 297 298&pinctrl { 299 sercom2_usart_default: sercom2_usart_default { 300 group1 { 301 pinmux = <PB25D_SERCOM2_PAD1>, <PB24D_SERCOM2_PAD0>; 302 }; 303 }; 304}; 305 306&sercom2 { 307 status = "okay"; 308 compatible = "microchip,pic32-uart"; 309 current-speed = <115200>; 310 rxpo = <1>; 311 txpo = <0>; 312 #address-cells = <1>; 313 #size-cells = <0>; 314 315 pinctrl-0 = <&sercom2_usart_default>; 316 pinctrl-names = "default"; 317}; 318``` 319