The Rx interrupt has to be disabled during UART init. Otherwise, the execution of the firmware hanging.

Hello,

I'm working on a project which uses RA6M5 MCU. The FSP version is 3.5.0. The IAR version is 9.10.2.

There is a UART connected to a third party chip on the board. I found a problem: after the UART initialization, the execution never return from the next statement. After some retries, I disabled the Rx interrupt. Then it seems working. But I can't disable Rx interrupt forever. Is there a way to fix it? Could you please point out where the problem is? Here is the code:

sci_uart_instance_ctrl_t g_uart_ctrl;
baud_setting_t g_uart_baud_setting =
{
  .semr_baudrate_bits_b.abcse = 0,
  .semr_baudrate_bits_b.abcs = 0,
  .semr_baudrate_bits_b.bgdm = 1,
  .cks = 0,
  .brr = 53,
  .mddr = (uint8_t) 256,
  .semr_baudrate_bits_b.brme = false
};

const sci_uart_extended_cfg_t g_uart_cfg_extend =
{
  .clock            = SCI_UART_CLOCK_INT,
  .rx_edge_start    = SCI_UART_START_BIT_FALLING_EDGE,
  .noise_cancel     = SCI_UART_NOISE_CANCELLATION_DISABLE,
  .rx_fifo_trigger  = SCI_UART_RX_FIFO_TRIGGER_MAX,
  .p_baud_setting   = &g_uart_baud_setting,
  .flow_control     = SCI_UART_FLOW_CONTROL_RTS,
  .flow_control_pin = (bsp_io_port_pin_t) UINT16_MAX,
};

const uart_cfg_t g_uart_cfg =
{
  .channel       = 8,
  .data_bits     = UART_DATA_BITS_8,
  .parity        = UART_PARITY_OFF,
  .stop_bits     = UART_STOP_BITS_1,
  .p_callback    = isr_callback,
  .p_context     = NULL,         
  .p_extend      = &g_uart_cfg_extend,
  .p_transfer_tx = NULL, 
  .p_transfer_rx = NULL, 
  .rxi_ipl       = (12),
  .txi_ipl       = (12),
  .tei_ipl       = (12), 
  .eri_ipl       = (12),
  .rxi_irq       = VECTOR_NUMBER_SCI8_RXI,
  .txi_irq       = VECTOR_NUMBER_SCI8_TXI,
  .tei_irq       = VECTOR_NUMBER_SCI8_TEI,
  .eri_irq       = VECTOR_NUMBER_SCI8_ERI,
};

void uart_init()
{
  fsp_err_t err = FSP_SUCCESS;
  sci_uart_instance_ctrl_t * p_ctrl = &g_uart_ctrl;
  
  R_IOPORT_PinCfg(&gpio_ctrl, UART_TX_PIN, ((uint32_t) IOPORT_CFG_PERIPHERAL_PIN | (uint32_t) IOPORT_PERIPHERAL_SCI0_2_4_6_8));
  R_IOPORT_PinCfg(&gpio_ctrl, UART_RX_PIN, ((uint32_t) IOPORT_CFG_PERIPHERAL_PIN | (uint32_t) IOPORT_PERIPHERAL_SCI0_2_4_6_8));
  
  err = R_SCI_UART_Open(&g_uart_ctrl, &g_uart_cfg);
  if (FSP_SUCCESS != err)
  {
    tsPrintf("** uart_init: R_SCI_UART_Open API failed **\r\n");
    return;
  }
  
  p_ctrl->p_reg->SCR &= ~SCI_SCR_RIE_MASK;  // Have to disable the Rx interrupt
}

// Calling code
void func()
{
  . . .
  uart_init();
  
  memset(&buffer, 0, sizeof(buffer));  // <-- Never come back after this line if Rx interrupt not disabled at Line 60
  . . .
}

The behaviour is similar to this post(community.renesas.com/.../code-execution-never-finished-from-r_icu_externalirqenable-or-memset). The execution of memset() never returns if the Rx interrupt isn't disabled.

Thanks in advance!