missing PORT_PCR_PS in Pull Select configuration

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

missing PORT_PCR_PS in Pull Select configuration

1,579 Views
GuillaumeAudirac
NXP Employee
NXP Employee

When using the Config Tools v4.1 (MCUXpresso 10.2)

Conditions:

product: Pins v4.1
processor: MK64FN1M0xxx12
package_id: MK64FN1M0VMD12
mcu_data: ksdk2_0
processor_version: 4.0.0
board: FRDM-K64F

pin_mux.c extract:

/* PORTE26 (pin K4) is configured as PTE26 */
PORT_SetPinMux(BOARD_INITPINS_KW41_UART_RTS_PORT, BOARD_INITPINS_KW41_UART_RTS_PIN, kPORT_MuxAsGpio);

/* Interrupt configuration on PORTE26 (pin K4): Interrupt on rising edge */
PORT_SetPinInterruptConfig(BOARD_INITPINS_KW41_UART_RTS_PORT, BOARD_INITPINS_KW41_UART_RTS_PIN, kPORT_InterruptRisingEdge);

PORTE->PCR[26] = ((PORTE->PCR[26] &
    /* Mask bits to zero which are setting */
    (~(PORT_PCR_PS_MASK | PORT_PCR_PE_MASK | PORT_PCR_PFE_MASK | PORT_PCR_ISF_MASK)))

    /* Pull Select: Internal pulldown resistor is enabled on the corresponding pin, if the
     * corresponding PE field is set. */
    | (uint32_t)(kPORT_PullDown)

    /* Passive Filter Enable: Passive input filter is enabled on the corresponding pin, if the
     * pin is configured as a digital input.
     * Refer to the device data sheet for filter characteristics. */
    | PORT_PCR_PFE(kPORT_PassiveFilterEnable));

Why "(uint32_t)(kPORT_PullDown)" and not "PORT_PCR_PS(kPORT_PullDown)"?

Even if it is functionaly identical, it creates some discrepancies in the pin_mux.c file.

Guillaume Audirac
Labels (1)
0 Kudos
Reply
3 Replies

1,198 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Guillaume Audirac

kPORT_PullDown and kPORT_PullUp were designed to not only select the pull resistor but also to enable the resistor itself. So if you use something like PORT_PCR_PS(kPORT_PullDown), it will only select the corresponding resistor, but it will not enable the resistor. I think this is why the Config tool doesn't use the Mask Macro to setup the internal resistor.

Hope it helps

Best regards

Jorge Alcala

0 Kudos
Reply

1,198 Views
GuillaumeAudirac
NXP Employee
NXP Employee

I'm sorry but your answer is apparently not related to my point.

In the Pin Control Register (PORTn_PCR[m]), the difference between Pull Select (PS) and Pull Enable (PE) is clear for me. It is not the point here.

My question is related to coding consistancy in the pin_mux.c file. To isolate the proper bit field in PCR, macros have been defined in the file MK64F12.h and are usually used:

/*! @name PCR - Pin Control Register n */
#define PORT_PCR_PS_MASK                         (0x1U)
#define PORT_PCR_PS_SHIFT                        (0U)
#define PORT_PCR_PS(x)                           (((uint32_t)(((uint32_t)(x)) << PORT_PCR_PS_SHIFT)) & PORT_PCR_PS_MASK)
#define PORT_PCR_PE_MASK                         (0x2U)
#define PORT_PCR_PE_SHIFT                        (1U)
#define PORT_PCR_PE(x)                           (((uint32_t)(((uint32_t)(x)) << PORT_PCR_PE_SHIFT)) & PORT_PCR_PE_MASK)

[...]

But for some reason, it is not always the case and it looks like a mistake in the code generation. See the difference between the two configs below. In my opinion "(uint32_t)(kPORT_PullDown)" should be replaced with "PORT_PCR_PS(kPORT_PullDown)".

PORTA->PCR[7] = ((PORTA->PCR[7] &
                      /* Mask bits to zero which are setting */
                      (~(PORT_PCR_PS_MASK | PORT_PCR_ISF_MASK)))

                     /* Pull Select: Internal pulldown resistor is enabled on the corresponding pin, if the
                      * corresponding PE field is set. */
                     | PORT_PCR_PS(kPORT_PullDown));

PORTE->PCR[26] = ((PORTE->PCR[26] &
                       /* Mask bits to zero which are setting */
                       (~(PORT_PCR_PS_MASK | PORT_PCR_PE_MASK | PORT_PCR_PFE_MASK | PORT_PCR_ISF_MASK)))

                      /* Pull Select: Internal pulldown resistor is enabled on the corresponding pin, if the
                       * corresponding PE field is set. */
                      | (uint32_t)(kPORT_PullDown)

                      /* Passive Filter Enable: Passive input filter is enabled on the corresponding pin, if the
                       * pin is configured as a digital input.
                       * Refer to the device data sheet for filter characteristics. */
                      | PORT_PCR_PFE(kPORT_PassiveFilterEnable));

Guillaume Audirac
0 Kudos
Reply

1,198 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Guillaume Audirac

I agree with you, it looks like a mistake in the code generation as long as these codes have a different implementation.

My previous post is more to mention that  "(uint32_t)(kPORT_PullDown)" and "PORT_PCR_PS(kPORT_PullDown)" are not functional identical, PORT_PCR_PS uses a mask that will not set up the same that (uint32_t)(kPORT_PullDown)

Regards

Jorge Alcala

0 Kudos
Reply