Common mistakes

Informative

Pitfalls when using the Port driver, and how to avoid them. Each maps to a rule in Port — Requirements or an error in Errors.

  • Passing a real pointer to Port_Init. configPtr MUST be NULL_PTR — a non-null pointer raises PORT_DEVERR_PARAM_POINTER (CHI-PORT-MUST-02). The configuration is selected at build time.

  • Expecting to reconfigure a pin at runtime. A pin’s function mode and direction are fixed by Port_Init; there is no API to change them later. Only edge detection is runtime-settable (CHI-PORT-MUST-01).

  • Using raw pin/port numbers. Address pins and ports through the generated symbols (PORT_PIN_<...> / PORT_PORT_<...>); a pin id is (portId << 8) | pinIndex and an unconfigured pin raises PORT_DEVERR_PARAM_PIN (CHI-PORT-MUST-11).

  • Rewriting a whole port to change one pin. Use Port_SetMaskedPortValue with a mask so only the intended pins change and the update is atomic; a plain full-port write clobbers the others (CHI-PORT-MUST-06).

  • Assuming defined behavior when writing an input pin. Port_SetPinValue on an input pin is implementation-defined — don’t rely on it to steer pull-ups/downs portably (CHI-PORT-MUST-04).

  • Forgetting edge detection starts disabled. Port_Init disables detection on every pin; call Port_SetEdgeDetection to enable it before expecting Port_Callout_OnEdgeDetection (CHI-PORT-MUST-07).

  • Not servicing polled pins. A pin configured for Polling needs Port_PollFunction called cyclically, or its edge events never fire (CHI-PORT-MUST-09).

  • Treating a read error as a valid LOW. On error the Get APIs return PORT_PIN_VALUE_LOW (or all-LOW for a port) — indistinguishable from a genuine low, so validate the pin id first (CHI-PORT-MUST-03).