AnsweredAssumed Answered

Abnormal output port signal triggered by printf()

Question asked by PETER SHIH on Dec 14, 2015
Latest reply on Dec 22, 2015 by Alice_Yang

Hi:

 

I am working on a custom board equipped with K66 MCU(120MHz, and 60MHz bus clock) and other peripherals. Recently, I am facing a issue regarding printf(). I have PTC13 as input port, and PTC3 and PTC4 from UART1 as debug port for my project. I discovered whenever the printf() output words, the PTC13 also change status. For diagnostic purpose, I set the PTE0 port before printf(), and clear the port after printf(). Based on the scope, I can pretty sure the strange PTC3 outputs are from printf(). As I mentioned the PTC13 is declare as input (verified by PCR13_MUX=1), I have no idea how this port can be toggled as output. Please help me out if you have any idea or recommendation. Thank you very much.

 

Yellow signal: PTC13 (GPIO input),

Red signal: PTE0 (GPIO output) for diagnostic purpose only.

In Main.c:

int main(void) {     /* Write your code here */     // Init hardware     hardware_init();     gpio_Init();      GPIOE_PSOR |= 0x00000001;     PRINTF("\r\n Test Start:\r\n");     GPIOE_PCOR |= 0x00000001;      /* This for loop should be replaced. By default this loop allows a single stepping. */     for (;;) {         i++;         if (!i)    {             GPIOE_PSOR |= 0x00000001;             PRINTF(".");             GPIOE_PCOR |= 0x00000001;         }     }     /* Never leave main */     return 0; }  void gpio_Init(void) {     gpio_input_pin_user_config_t     inputPinConfig;     gpio_output_pin_user_config_t     outputPinConfig;      outputPinConfig.pinName = kGpioE0;     outputPinConfig.config.outputLogic = 0;     outputPinConfig.config.slewRate = kPortSlowSlewRate;     outputPinConfig.config.isOpenDrainEnabled = false;     outputPinConfig.config.driveStrength = kPortLowDriveStrength;     GPIO_DRV_OutputPinInit(&outputPinConfig);      inputPinConfig.pinName = kGpioC13;     inputPinConfig.config.isPullEnable = false;     inputPinConfig.config.pullSelect = kPortPullUp;     inputPinConfig.config.isPassiveFilterEnabled = false;     inputPinConfig.config.isDigitalFilterEnabled = false;     inputPinConfig.config.interrupt = kPortIntDisabled;     GPIO_DRV_InputPinInit(&inputPinConfig); }

 

In pin_mux.c:

void configure_uart_pins(uint32_t instance) {   switch(instance) {     case UART1_IDX:       /* Affects PORTE_PCR17 register */       PORT_HAL_SetMuxMode(PORTC,3UL,kPortMuxAlt3);       /* Affects PORTE_PCR16 register */       PORT_HAL_SetMuxMode(PORTC,4UL,kPortMuxAlt3);       break;     case UART2_IDX:                      /* HW_UART2 */       /* Affects PORTD_PCR2 register */       PORT_HAL_SetMuxMode(PORTD,2UL,kPortMuxAlt3);       /* Affects PORTD_PCR3 register */       PORT_HAL_SetMuxMode(PORTD,3UL,kPortMuxAlt3);       break;     case UART4_IDX:                      /* HW_UART4 */       /* Affects PORTC_PCR14 register */       PORT_HAL_SetMuxMode(PORTC,14UL,kPortMuxAlt3);       /* Affects PORTC_PCR15 register */       PORT_HAL_SetMuxMode(PORTC,15UL,kPortMuxAlt3);       break;     default:       break;   } }

 

In hardware_init.c

void hardware_init(void) {     /* enable clock for PORTs */     CLOCK_SYS_EnablePortClock(PORTA_IDX);     CLOCK_SYS_EnablePortClock(PORTB_IDX);     CLOCK_SYS_EnablePortClock(PORTC_IDX);     CLOCK_SYS_EnablePortClock(PORTD_IDX);     CLOCK_SYS_EnablePortClock(PORTE_IDX);      /* Init board clock */     BOARD_ClockInit();     dbg_uart_init();      /* Set clock source for Ethernet */ //    if (0 == strcmp("TWR-K65F180M", BOARD_NAME)) //    { //        CLOCK_SYS_SetEnetRmiiSrc(ENET_IDX, kClockRmiiSrcExt); //    } }

 

In board.c

/* Initialize debug console. */ void dbg_uart_init(void) {     configure_uart_pins(BOARD_DEBUG_UART_INSTANCE);      DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_DEBUG_UART_BAUD, kDebugConsoleUART); }

 

Peter Shih

Outcomes