0
\$\begingroup\$

I am working on s32k144 controller in which I learnt how to configure pins as INPUT, while referring data sheet I got to know the base address GPIOC base address: 400F_F080h which is matching with the PTC, but the next line of PTC there is PORTC.

From the code I got to know that PTC base address is 400F_F080h which is GPIOC base address represented in the data sheet but the base address of PORTC is 4004B000h which is not in the data sheet.

so my question is what is PTC,PORTC? wats the difference? why data direction is set by the using PTC base address and PORTC for setting as GPIO?

/* GPIO - Peripheral instance base addresses */
/** Peripheral PTA base address */
#define PTA_BASE                                 (0x400FF000u)
/** Peripheral PTA base pointer */
#define PTA                                      ((GPIO_Type *)PTA_BASE)
/** Peripheral PTB base address */
#define PTB_BASE                                 (0x400FF040u)
/** Peripheral PTB base pointer */
#define PTB                                      ((GPIO_Type *)PTB_BASE)
/** Peripheral PTC base address */
#define PTC_BASE                                 (0x400FF080u)
/** Peripheral PTC base pointer */
#define PTC                                      ((GPIO_Type *)PTC_BASE)
/** Peripheral PTD base address */
#define PTD_BASE                                 (0x400FF0C0u)
/** Peripheral PTD base pointer */
#define PTD                                      ((GPIO_Type *)PTD_BASE)
/** Peripheral PTE base address */
#define PTE_BASE                                 (0x400FF100u)
/** Peripheral PTE base pointer */
#define PTE                                      ((GPIO_Type *)PTE_BASE)
/** Array initializer of GPIO peripheral base addresses */
#define GPIO_BASE_ADDRS                          { PTA_BASE, PTB_BASE, PTC_BASE, PTD_BASE, PTE_BASE }
/** Array initializer of GPIO peripheral base pointers */
#define GPIO_BASE_PTRS                           { PTA, PTB, PTC, PTD, PTE }





* PORT - Peripheral instance base addresses */
/** Peripheral PORTA base address */
#define PORTA_BASE                               (0x40049000u)
/** Peripheral PORTA base pointer */
#define PORTA                                    ((PORT_Type *)PORTA_BASE)
/** Peripheral PORTB base address */
#define PORTB_BASE                               (0x4004A000u)
/** Peripheral PORTB base pointer */
#define PORTB                                    ((PORT_Type *)PORTB_BASE)
/** Peripheral PORTC base address */
#define PORTC_BASE                               (0x4004B000u)
/** Peripheral PORTC base pointer */
#define PORTC                                    ((PORT_Type *)PORTC_BASE)
/** Peripheral PORTD base address */
#define PORTD_BASE                               (0x4004C000u)
/** Peripheral PORTD base pointer */
#define PORTD                                    ((PORT_Type *)PORTD_BASE)
/** Peripheral PORTE base address */
#define PORTE_BASE                               (0x4004D000u)
/** Peripheral PORTE base pointer */
#define PORTE                                    ((PORT_Type *)PORTE_BASE)
/** Array initializer of PORT peripheral base addresses */
#define PORT_BASE_ADDRS                          { PORTA_BASE, PORTB_BASE, PORTC_BASE, PORTD_BASE, PORTE_BASE }
/** Array initializer of PORT peripheral base pointers */
#define PORT_BASE_PTRS                           { PORTA, PORTB, PORTC, PORTD, PORTE }
 /** Number of interrupt vector arrays for the PORT module. */
#define PORT_IRQS_ARR_COUNT                      (1u)
 /** Number of interrupt channels for the PORT module. */
#define PORT_IRQS_CH_COUNT                       (1u)
/** Interrupt vectors for the PORT peripheral type */
#define PORT_IRQS                                { PORTA_IRQn, PORTB_IRQn, PORTC_IRQn, PORTD_IRQn, PORTE_IRQn }

/* --------------------------------------------------------------------

int main(void) {

}
 int counter = 0;
 WDOG_disable();
 /* Enable clocks to peripherals (PORT modules) */
 PCC-> PCCn[PCC_PORTC_INDEX] = PCC_PCCn_CGC_MASK; /* Enable clock to PORT C */
 PCC-> PCCn[PCC_PORTD_INDEX] = PCC_PCCn_CGC_MASK; /* Enable clock to PORT D */
 /* Configure port C12 as GPIO input (BTN 0 [SW2] on EVB) */
 PTC->PDDR &= ~(1<<PTC12); /* Port C12: Data Direction= input (default) */
 PORTC->PCR[12] = 0x00000110; /* Port C12: MUX = GPIO, input filter enabled */
 /* Configure port D0 as GPIO output (LED on EVB) */
 PTD->PDDR |= 1<<PTD0; /* Port D0: Data Direction= output */
 PORTD->PCR[0] = 0x00000100; /* Port D0: MUX = GPIO */
 for(;;) {
 if (PTC->PDIR & (1<<PTC12)) { /* If Pad Data Input = 1 (BTN0 [SW2] pushed) */
 PTD-> PCOR |= 1<<PTD0; /* Clear Output on port D0 (LED on) */
 }
 else { /* If BTN0 was not pushed */
 PTD-> PSOR |= 1<<PTD0; /* Set Output on port D0 (LED off) */
 }
 counter++;
}

```
\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

I believe you'll find that these two symbols:

  1. PTC
  2. PORTC

Are identical. It really depends on the difference between GPIO_Type and PORT_Type but if you look where those are defined, they are likely both just aliases for an address.

The convention for this is if you are using the register as a PORT, use the PORT_Type declaration. If you are using one of the alternate functions on the pin/port, use the more general GPIO_Type.

But for all practical purposes, these two are interchangeable. Whatever you do the best thing is to be consistent.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Which leaves open the question of why they are mapped to completely different addresses. (Perhaps the OP has cobbled together these #defines from two different header files for two entirely different MCUs?) \$\endgroup\$
    – user16324
    Commented Jan 28, 2021 at 13:52
  • \$\begingroup\$ If they are likely both just aliases for an address, then why two different address? \$\endgroup\$ Commented Jan 29, 2021 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.