Electrical – UART communication between Cypress FM4 (Cortex M4) and Arduino

arduinoarmuart

I am trying to transmit data from (FM4-176L-S6E2CC-ETH Starter kit) to Arduino (Leonardo) using UART communication. Wire connections (FM4 [p. 8-9] -> Arduino):

P19 (SOT2_0) -> D10

P18 (SIN2_0) -> D11

For programming FM4 I use Keil uVision5 (5.24.1) with PDL (2.1.0).
I have turned on UART ch.2 in pdl_user.c

#define PDL_PERIPHERAL_ENABLE_MFS2              PDL_ON

and initialized both FM4 pins (P18, P19) for communication using a function SetPinFunc_XXX()

#define SetPinFunc_SIN2_0(dummy)        do{ \
                                            bFM_GPIO_ADE_AN08=0u; \
                                            PINRELOC_SET_EPFR( FM_GPIO->EPFR07, 16u, 2u,  1u ); \
                                            bFM_GPIO_PFR1_P8 = 1u; \
                                        }while (0u)

and

#define SetPinFunc_SOT2_0(dummy)        do{ \
                                            bFM_GPIO_ADE_AN09=0u; \
                                            PINRELOC_SET_EPFR( FM_GPIO->EPFR07, 18u, 2u,  1u ); \
                                            bFM_GPIO_PFR1_P9 = 1u; \
                                        }while (0u)

When I upload the code on FM4 (no compilation errors), nothing have been transmitted to Arduino, even after I push reset button. Am I missing something?

If change UART channel to &UART0 and use SOT0_0 and SIN0_0, I can view transmitted data in console. Also I have tested Arduino with BT module and Android, and it works fine with the same code.

FM4-S6E2CC:

#include "mcu.h"
#include "pdl_header.h"

#define SAMPLE_UART_RX_BUFFSIZE sizeof(au8UartTxBuf)/sizeof(char)

volatile stc_mfsn_uart_t* UartCh2 = &UART2;
stc_mfs_uart_config_t stcUartConfig;
uint8_t u8Cnt = 0;

static uint8_t au8UartTxBuf[] = "Data sent from UART2!";

void InitUart(void)
{
   PDL_ZERO_STRUCT(stcUartConfig);
   
   /* Initialize UART TX and RX channel */
    stcUartConfig.enMode = UartNormal;
    stcUartConfig.u32BaudRate = 9600;
    stcUartConfig.enDataLength = UartEightBits;
    stcUartConfig.enParity = UartParityNone;
    stcUartConfig.enStopBit = UartOneStopBit;
    stcUartConfig.enBitDirection = UartDataLsbFirst; 
    stcUartConfig.bInvertData = FALSE;
    stcUartConfig.bHwFlow = FALSE;
    stcUartConfig.bUseExtClk = FALSE;
    stcUartConfig.pstcFifoConfig = NULL;

    Mfs_Uart_Init(UartCh2, &stcUartConfig);
}

int main(void)
{   
    /* Initialize UART function I/O */
    SetPinFunc_SIN2_0();
    SetPinFunc_SOT2_0();
        
    /* UART initialization */
    InitUart();
    
    /* Enable TX function of UART2 */
    Mfs_Uart_EnableFunc(UartCh2, UartTx);

    while(u8Cnt < SAMPLE_UART_RX_BUFFSIZE)
    {
        while (TRUE != Mfs_Uart_GetStatus(UartCh2, UartTxEmpty)); /* wait until TX buffer empty */
        Mfs_Uart_SendData(UartCh2, au8UartTxBuf[u8Cnt]);
        
        u8Cnt++;
    }
    
    Mfs_Uart_DeInit(UartCh2, TRUE);
    
    while(1)
    {
        /* Data is normally sent and received */
    }
}

Arduino Leonardo:

#include <SoftwareSerial.h>
SoftwareSerial UART(10, 11); 
// creates a "virtual" serial port/UART
// connect FM4 pin TX to D10
// connect FM4 pin RX to D11

void setup(){
  UART.begin(9600); // set the data rate for the SoftwareSerial port
}

void loop(){
  if (UART.available())
    Serial.println(UART.read());
}

Best Answer

Found the problem thanks to ThreePhaseEel. The schematic document (p6) shows that a connector CN9 has Pin109 and Pin110, while for wiring I looked into Starter Kit Guide (p8), which shows Pin106 and Pin107. So, basically I have to use another UART channel, in this case - ch.12. Changes I made:

SetPinFunc_SIN12_0();

SetPinFunc_SOT12_0();

UartCh2 = &UART12

#define PDL_PERIPHERAL_ENABLE_MFS2 PDL_ON