Before a microcontroller can interact with external hardware, its pins must be configured correctly. Whether you want to read a button state, drive an LED, communicate with a sensor, or use a peripheral, the first step is to configure the corresponding pins.
First, identify the pin you want to use. In this example, we will use the following pin:
RGBLED0_REDPTA29GPIO29Configure the pins according to their intended use: input, output, or input/output. To begin, open the Pins Tool by clicking the Pins button in the upper-right corner.
In the Pins Tool, the pins are organized into Functional Groups. In the default projects provided with the Model-Based Design Toolbox, these groups are arranged based on the peripheral to which the pins are routed.
For this step, focus on the Pins tab in the upper-left area of the window. Search for the pin you want to configure; in this example, PTA29.
If the desired functionality is already routed to a different pin, first disable that routing by clearing the corresponding selection before assigning it to PTA29. Next, update the identifier and label as needed, then enable the routing by selecting the checkbox on the left. This opens the routing selection dialog.
Select SIUL2:gpio,29, as it matches the intended functionality. A second dialog then prompts you to select the pin direction.
In this example, the LED is configured as Input/Output, matching the configuration used by the example project. Depending on the intended use of the pin, a different direction may be required — for example, a push button is typically configured as an input. Additional examples can be found in the default projects provided with the Model-Based Design Toolbox.
The Port component must reflect the same pin configuration defined in the Pins Tool. After returning to the Peripherals Tool, the Port component may be highlighted in red because the pin configuration was modified in the Pins Tool and has not yet been updated in the Port component.
In the default Model-Based Design Toolbox projects, PortPins are grouped into PortContainers according to their associated peripheral, such as Dio_Pins or Can_Pins. Locate the Dio_Pins PortContainer and update the PortPin entries so that they match the values configured in the Pins Tool.
The pin will already contain the MSCR value inherited from the Pins configuration. Update the pin name as desired so it can be easily identified in the model, then repeat the process for each additional pin.
The PortPin Id uniquely identifies each PortPin entry. The identifier must remain unique across all PortContainers.
Assign a unique PortPin Id value to each configured pin. For example, a configuration containing 40 pins can use identifiers within the range described by the tool configuration.
Once the pin configuration is complete and the Port component has been updated accordingly, you can continue with the configuration of the software components that will use those pins.