I am trying to setup a second USART on my MIMXRT600. I started with the SDK polling example and wanted to add a second USART on Flexcomm2. I setup the clock and attach it to the Flexcomm interface, initialize the USART and send someting, but I receive nothing no signal on the wire.
Here is the code of the main.
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_usart.h"
#include "fsl_debug_console.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define DEBUG_BOOT_USART USART0
//#define DEBUG_BOOT_USART_CLK_SRC kCLOCK_Flexcomm0
#define DEBUG_BOOT_USART_CLK_FREQ CLOCK_GetFlexCommClkFreq(0U)
#define SERIAL_BOOT_USART USART2
#define SERIAL_BOOT_USART_CLK_FREQ CLOCK_GetFlexCommClkFreq(2U)
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
uint8_t txbuff1[] = "Flexcom1 Test\r\n";
uint8_t txbuff2[] = "Flexcom2 Test\r\n";
uint8_t rxbuff[20] = {0};
/*******************************************************************************
* Code
******************************************************************************/
/*!
* @brief Main functioné
*/
int main(void)
{
uint8_t ch;
usart_config_t usart0_config;
usart_config_t usart2_config;
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
/*
* config.baudRate_Bps = 115200U;
* config.parityMode = kUSART_ParityDisabled;
* config.stopBitCount = kUSART_OneStopBit;
* config.loopback = false;
* config.enableTx = false;
* config.enableRx = false;
*/
USART_GetDefaultConfig(&usart0_config);
usart0_config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
usart0_config.enableTx = true;
usart0_config.enableRx = true;
USART_Init(DEBUG_BOOT_USART, &usart0_config, DEBUG_BOOT_USART_CLK_FREQ);
/* attach FRG0 clock to FLEXCOMM2 (debug console) */
CLOCK_SetFRGClock(SERIAL_BOOT_UART_FRG_CLK);
CLOCK_AttachClk(SERIAL_BOOT_UART_CLK_ATTACH);
USART_GetDefaultConfig(&usart2_config);
usart2_config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
usart2_config.enableTx = true;
usart2_config.enableRx = true;
USART_Init(SERIAL_BOOT_USART, &usart2_config, SERIAL_BOOT_USART_CLK_FREQ);
DbgConsole_Printf("DEBUG_BOOT_USART_CLK_FREQ: %d\n", DEBUG_BOOT_USART_CLK_FREQ);
DbgConsole_Printf("SERIAL_USART_CLK_FREQ: %d\n", SERIAL_BOOT_USART_CLK_FREQ) ;
USART_WriteBlocking(DEBUG_BOOT_USART, txbuff1, sizeof(txbuff1) - 1);
USART_WriteBlocking(SERIAL_BOOT_USART, txbuff2, sizeof(txbuff2) - 1);
return 0;
}
The ini_pins function:
void BOARD_InitPins(void)
{
const uint32_t port0_pin1_config = (/* Pin is configured as FC0_TXD_SCL_MISO_WS */
IOPCTL_PIO_FUNC1 |
/* Disable pull-up / pull-down function */
IOPCTL_PIO_PUPD_DI |
/* Enable pull-down function */
IOPCTL_PIO_PULLDOWN_EN |
/* Disable input buffer function */
IOPCTL_PIO_INBUF_DI |
/* Normal mode */
IOPCTL_PIO_SLEW_RATE_NORMAL |
/* Normal drive */
IOPCTL_PIO_FULLDRIVE_DI |
/* Analog mux is disabled */
IOPCTL_PIO_ANAMUX_DI |
/* Pseudo Output Drain is disabled */
IOPCTL_PIO_PSEDRAIN_DI |
/* Input function is not inverted */
IOPCTL_PIO_INV_DI);
/* PORT0 PIN1 (coords: G2) is configured as FC0_TXD_SCL_MISO_WS */
IOPCTL_PinMuxSet(IOPCTL, 0U, 1U, port0_pin1_config);
const uint32_t port0_pin2_config = (/* Pin is configured as FC0_RXD_SDA_MOSI_DATA */
IOPCTL_PIO_FUNC1 |
/* Disable pull-up / pull-down function */
IOPCTL_PIO_PUPD_DI |
/* Enable pull-down function */
IOPCTL_PIO_PULLDOWN_EN |
/* Enables input buffer function */
IOPCTL_PIO_INBUF_EN |
/* Normal mode */
IOPCTL_PIO_SLEW_RATE_NORMAL |
/* Normal drive */
IOPCTL_PIO_FULLDRIVE_DI |
/* Analog mux is disabled */
IOPCTL_PIO_ANAMUX_DI |
/* Pseudo Output Drain is disabled */
IOPCTL_PIO_PSEDRAIN_DI |
/* Input function is not inverted */
IOPCTL_PIO_INV_DI);
/* PORT0 PIN2 (coords: G4) is configured as FC0_RXD_SDA_MOSI_DATA */
IOPCTL_PinMuxSet(IOPCTL, 0U, 2U, port0_pin2_config);
const uint32_t port0_pin15_config = (/* Pin is configured as FC2_TXD_SCL_MISO_WS */
IOPCTL_PIO_FUNC1 |
/* Disable pull-up / pull-down function */
IOPCTL_PIO_PUPD_DI |
/* Enable pull-down function */
IOPCTL_PIO_PULLDOWN_EN |
/* Disable input buffer function */
IOPCTL_PIO_INBUF_DI |
/* Normal mode */
IOPCTL_PIO_SLEW_RATE_NORMAL |
/* Normal drive */
IOPCTL_PIO_FULLDRIVE_DI |
/* Analog mux is disabled */
IOPCTL_PIO_ANAMUX_DI |
/* Pseudo Output Drain is disabled */
IOPCTL_PIO_PSEDRAIN_DI |
/* Input function is not inverted */
IOPCTL_PIO_INV_DI);
/* PORT0 PIN15 (coords: G2) is configured as FC2_TXD_SCL_MISO_WS */
IOPCTL_PinMuxSet(IOPCTL, 0U, 15U, port0_pin15_config);
const uint32_t port0_pin16_config = (/* Pin is configured as FC2_RXD_SDA_MOSI_DATA */
IOPCTL_PIO_FUNC1 |
/* Disable pull-up / pull-down function */
IOPCTL_PIO_PUPD_DI |
/* Enable pull-down function */
IOPCTL_PIO_PULLDOWN_EN |
/* Enables input buffer function */
IOPCTL_PIO_INBUF_EN |
/* Normal mode */
IOPCTL_PIO_SLEW_RATE_NORMAL |
/* Normal drive */
IOPCTL_PIO_FULLDRIVE_DI |
/* Analog mux is disabled */
IOPCTL_PIO_ANAMUX_DI |
/* Pseudo Output Drain is disabled */
IOPCTL_PIO_PSEDRAIN_DI |
/* Input function is not inverted */
IOPCTL_PIO_INV_DI);
/* PORT0 PIN16 (coords: G4) is configured as FC2_RXD_SDA_MOSI_DATA */
IOPCTL_PinMuxSet(IOPCTL, 0U, 16U, port0_pin16_config);
}
the relevant part of board.h:
/*! @brief The UART to use for debug messages. */
#define BOARD_DEBUG_UART_TYPE kSerialPort_Uart
#define BOARD_DEBUG_UART_BASEADDR (uint32_t) USART0
#define BOARD_DEBUG_UART_INSTANCE 0U
#define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetFlexCommClkFreq(0U)
#define BOARD_DEBUG_UART_FRG_CLK \
(&(const clock_frg_clk_config_t){0, kCLOCK_FrgPllDiv, 255, 0}) /*!< Select FRG0 mux as frg_pll */
#define BOARD_DEBUG_UART_CLK_ATTACH kFRG_to_FLEXCOMM0
#define BOARD_DEBUG_UART_RST kFC0_RST_SHIFT_RSTn
#define BOARD_DEBUG_UART_CLKSRC kCLOCK_Flexcomm0
#define BOARD_UART_IRQ_HANDLER FLEXCOMM0_IRQHandler
#define BOARD_UART_IRQ FLEXCOMM0_IRQn
/*! @brief The UART to use for serial boot. */
#define SERIAL_BOOT_UART_TYPE kSerialPort_Uart
#define SERIAL_BOOT_UART_BASEADDR (uint32_t) USART2
#define SERIAL_BOOT_UART_INSTANCE 2U
#define SERIAL_BOOT_UART_CLK_FREQ CLOCK_GetFlexCommClkFreq(2U)
#define SERIAL_BOOT_UART_FRG_CLK \
(&(const clock_frg_clk_config_t){2, kCLOCK_FrgPllDiv, 255, 0}) /*!< Select FRG0 mux as frg_pll */
#define SERIAL_BOOT_UART_CLK_ATTACH kFRG_to_FLEXCOMM2
#define SERIAL_BOOT_UART_RST kFC2_RST_SHIFT_RSTn
#define SERIAL_BOOT_UART_CLKSRC kCLOCK_Flexcomm2
#define SERIAL_BOOT_UART_IRQ_HANDLER FLEXCOMM2_IRQHandler
#define SERIAL_BOOT_UART_IRQ FLEXCOMM2_IRQn
the code compiles and runs on the board, but I only get the output of USART0.
What else do I need in order to run the second USART?