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
Hi:
I have tried to printf() to different port, for example UART4 on PTC14 and 15. It doesn't have any problem. I don't see any abnormal signal on PTC13.
I also tried to output debug message by UART_DRV_SendData() instead of printf(). I still see the abnormal signal from PTC13. It looks like the PTC13 has some kind of relationship with UART1. Any idea? please let me know. Thanks!
static uint16_t i = 0;
static uint8_t msg1[]="\r\n Test Start:\r\n";
uart_state_t uart1State;
int main(void)
{
/* Write your code here */
// Init hardware
hardware_init();
uart1_init();
gpio_Init();
GPIOE_PSOR |= 0x00000001;
//PRINTF("\r\n Test Start:\r\n");
UART_DRV_SendData(BOARD_DEBUG_UART_INSTANCE, msg1, sizeof(msg1));
while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(BOARD_DEBUG_UART_INSTANCE, NULL)){}
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(".");
UART_DRV_SendData(BOARD_DEBUG_UART_INSTANCE, ".", 1);
while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(BOARD_DEBUG_UART_INSTANCE, NULL)){}
GPIOE_PCOR |= 0x00000001;
}
}
/* Never leave main */
return 0;
}
void uart1_init(void)
{
uart_user_config_t uartConfig;
configure_uart_pins(BOARD_DEBUG_UART_INSTANCE);
uartConfig.bitCountPerChar = kUart8BitsPerChar;
uartConfig.parityMode = kUartParityDisabled;
uartConfig.stopBitCount = kUartOneStopBit;
uartConfig.baudRate = BOARD_DEBUG_UART_BAUD;
// Initialize the uart module with base address and config structure
UART_DRV_Init(BOARD_DEBUG_UART_INSTANCE, &uart1State, &uartConfig);
}
void UART1_RX_TX_IRQHandler(void)
{
UART_DRV_IRQHandler(1);
}
Hello petershih
I have some confusion.
Does the UART1 can transfer data correctly ?
You said when use UART1 send data, the PTC13 will changed statues , does it receive the date UART1 send ?
And your board is customer board or demo board , if it customer board , please check the PTC14 pin connected where ,
and if it is a demo board , please tell me the name of board name .
And also i recommend you send your project to me .
BR
Alice
Hi Alice:
The UART1 transfer data correctly. I am able to see the correct message sent through UART1 on PC with Tera Term software.
Whenever UART1 transfer data, I can see PTC13 status changed also. This is weird since the PTC13 is declare as input pin, and this port is nothing to do with UART1. As I mentioned this is on a custom board with K66 MCU. I am also sending you the project file for your review. the project is sending "." character constantly through UART1 at 115200 baud. The following are the signal captures by scope.
yellow signal: UART1_TX, sending '.' every 5ms.
red signal: PTC13 signal.
Please let me know if you have any idea. Thanks!
Hello peter,
Please configure the internal pullup or pulldown for the PTC13, that is to say change the "false" to "true"
or it will the electrical disturebance on your board .
Hope it helps
Alice