SAM4e Xplained Pro Debug UART

I’m having problems running the UART for the SAM4e Xplained Pro. First, I want to make sure it isn’t something simple. I’m trying to run it via the USB cable to a terminal emulator, such as PuTTY. I’m using sample setup code, but it doesn’t do anything. Which UART is used for this purpose? If that doesn’t solve it, I’ll post the setup code, but I’m just starting simple to see if that answers my problem. Many thanks in advance.

But aren’t there demo applications for the eval kit including UART usage ?
Did you try them to make sure your HW setup is working properly ?

One thing to note is that some processors setup a “Debug Serial Port” through the debug interface, and you need to use the debugger to access that port.

If the board has a USB Serial Port on it, then it should normally “just work”, though sometimes you need to load a device driver on your computer to access it (but many just identify themselves as the generic usb serial port so the built in PC drivers work).

The SAM4e Xplained board uses an EDBG device for the debugger. The EDBG device has 3 connections to the SAM4e. They are JTAG, Data Gateway Interface (DGI) and CDC. The CDC shows up as its own serial port on your PC. The schematics show the CDC UART connected to the PA9 and PA10 pins of the SAM4E. You should be able to connect a serial terminal (putty) to the serial port provided by the EDBG and send data on pin PA10 and see that data on your serial terminal.

Many thanks again everyone. I’m using Microchip Studio and I’ve tried to find demo applications, but for the USB UART, I haven’t found any. It doesn’t look like whatever my problem is, that it is going to have a simple solution. I’ve the following code:

In the .h file:
#ifndef UARTDRV_H_
#define UARTDRV_H_

#include <…\ASF\common\services\ioport\ioport.h>
#include <…\ASF\sam\utils\cmsis\sam4e\include\component\uart.h>
#include <…\ASF\sam\utils\cmsis\sam4e\include\instance\uart0.h>
#include <stdint.h>
#include <stdbool.h>

 //not completely sure if should be UART1 or  UART0, though the datasheet seems to say UART0
 #define EDBG_UART						 /*UART1*/UART0
 #define UART_SERIAL_BAUDRATE			 115200ul
 #define UART_SERIAL_CHAR_LENGTH			 US_MR_CHRL_8_BIT
 #define UART_SERIAL_PARITY				 US_MR_PAR_NO
//#define UART_SERIAL_STOP_BIT			 false - default (0) is one stop bit, but this is the 13 and 12 bits of the register, so, no good
 #define UART_SERIAL_STOP_BIT			 US_MR_NBSTOP_1_BIT
 #define UART_MCK_DIV					 16
 #define UART_MCK_DIV_MIN_FACTOR          1
 #define UART_MCK_DIV_MAX_FACTOR			 65535

 uint8_t initUART(Uart * pUart);
 void UARTPutC(Uart * pUart, char data);
 void UARTPutStr(Uart * pUart, char * data, uint8_t len);

 #endif /* UARTDRV_H_ */

In the .c file:

 #include <uartdrv.h>

  //sample code alternated between the use of p_Uart to the use of pUart. Just picked one for consistency (and needed by compiler).
 //sample code used both UART and Uart, where conflict in function title, picked one for consistency and compiler.

 uint8_t initUART(Uart * pUart) 
 {
     uint32_t cd = 0;
     uint8_t retVal = 0;
     Pmc this_pmc;
     // configure UART pins
/*
// ========== Pio definition for UART0 peripheral ========== */
//#define PIO_PA9A_URXD0       (1u << 9)  /**< \brief Uart0 signal: URXD0 */
//#define PIO_PA10A_UTXD0      (1u << 10) /**< \brief Uart0 signal: UTXD0 */
/* ========== Pio definition for UART1 peripheral ========== */
//These pins must be enables for the UART0 to work, they are set and then disabled in original code
//URXD0 is UART_1 PA9 RX line, UTXD0 is TX for same
//verify mode for these is set correctly!
ioport_set_port_mode(IOPORT_PIOA, PIO_PA9A_URXD0 | PIO_PA10A_UTXD0, IOPORT_MODE_MUX_A);
//ioport_disable_port(IOPORT_PIOA, PIO_PA9A_URXD0 | PIO_PA10A_UTXD0);
//need to be enabled
ioport_enable_port(IOPORT_PIOA, PIO_PA9A_URXD0 | PIO_PA10A_UTXD0);
//The DEBUG port must then be setup to receive the UART output, otherwise not going anywhere
//I can't remember one way or the other, but I don't believe this was on the original assignment?
//Need to setup CCFG_SYSIO potentially?

//only needed for synchronous operation
sysclk_enable_peripheral_clock(ID_UART0);
//	sysclk_enable_peripheral_clock(ID_UART1);
// Configure UART Control Registers
// Reset and Disable RX and TX
pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS;

// Configure Mode - needed SERIAL_CHAR_LENGTH, default (0) is 5 bits
//unless otherwise specified, the defaults are fine
pUart->UART_MR = UART_SERIAL_PARITY | UART_SERIAL_CHAR_LENGTH | UART_SERIAL_STOP_BIT;

// Check and configure baudrate
// Asynchronous, no oversampling
cd = (sysclk_get_peripheral_hz() / UART_SERIAL_BAUDRATE) / UART_MCK_DIV;
if(cd < UART_MCK_DIV_MIN_FACTOR || cd > UART_MCK_DIV_MAX_FACTOR)
{
	retVal = 1;
}

if(retVal != 1)
{
	// Set The Actual BAUD to Control Register
	pUart->UART_BRGR = cd;

	
	// Disable PDC Channel
	pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
	
	// Enable RX and TX
	pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN;
	
	
}

return retVal;

}

 void UARTPutC(Uart * pUart, char data)
 {
     // Wait for Transmitter to be Ready
     //also reading SR register, or the status reg
      while((pUart->UART_SR & UART_SR_TXRDY) == 0)
      {
		//This while loop will make sure that the transmitter is ready before you send your character to it.
         	     pUart->UART_THR = (uint32_t)data;
    }

 }
 void UARTPutStr(Uart * pUart, char * data, uint8_t len)
 {
     char ret_char = '\r';
      char newline_char = '\n';
     //larger than max parm value, might be overkill but intended to prevent rollover error
     for (uint16_t i = 0; i < len; i++)
    {
	     //could also use pointer arithmetic, see what works
	    UARTPutC(pUart, data[i]);		
    }

      UARTPutC(pUart, ret_char);
      UARTPutC(pUart, newline_char);
 }

In main:

#include “uartdrv.h”

 int main (void)
 {
     Uart this_uart;
     board_init();
     initUART(&this_uart);

     while (1) 
    {
	    UARTPutC(&this_uart, 'W');
     }
 }

I was also given the following code that I edited to the above. It didn’t work either, but just in case I missed something:

Inside the .h:

#define EDBG_UART                        UART0

 #define UART_SERIAL_BAUDRATE             115200ul

 #define UART_SERIAL_CHAR_LENGTH          US_MR_CHRL_8_BIT

  #define UART_SERIAL_PARITY               US_MR_PAR_NO

  #define UART_SERIAL_STOP_BIT             false

  #define UART_MCK_DIV                     16

  #define UART_MCK_DIV_MIN_FACTOR          1

 #define UART_MCK_DIV_MAX_FACTOR          65535



 uint8_t initUART(Uart * pUart);

  void UARTPutC(Uart * pUart, char data);

  void UARTPutStr(Uart * pUart, char * data, uint8_t len);

In the .c:

 uint8_t initUart(Uart * p_Uart)
 {

       uint32_t cd = 0;

        uint8_t retVal = 0;

  

       // configure UART pins

       ioport_set_port_mode(IOPORT_PIOA, PIO_PA9A_URXD0 | PIO_PA10A_UTXD0, IOPORT_MODE_MUX_A);

       ioport_disable_port(IOPORT_PIOA, PIO_PA9A_URXD0 | PIO_PA10A_UTXD0);

        sysclk_enable_peripheral_clock(ID_UART0);

      // Configure UART Control Registers

      // Reset and Disable RX and TX

        p_Uart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS;

      // Check and configure baudrate

       // Asynchronous, no oversampling

        cd = (sysclk_get_peripheral_hz() / UART_SERIAL_BAUDRATE) / UART_MCK_DIV;

      if(cd < UART_MCK_DIV_MIN_FACTOR || cd > UART_MCK_DIV_MAX_FACTOR)

      {

             retVal = 1;

      }

  

       if(retVal != 1)

      {

             // Set The Actual BAUD to Control Register

               p_Uart->UART_BRGR = cd;

              // Configure Mode

               p_Uart->UART_MR = UART_SERIAL_PARITY;

         

              // Disable PDC Channel

              p_Uart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;

         

             // Enable RX and TX

              p_Uart->UART_CR = UART_CR_RXEN | UART_CR_TXEN;

      }

  

       return retVal;

}

In main:

  //only major difference in main, tried it instead of this_uart, still doesn't' work

 initUART(EDBG_UART);

Maybe I’m wrong, but this is just the normal UART0 @ PA9/10 connected to the EDBG, right ?
I dont think that the UART peripheral supports configuring SERIAL_CHAR_LENGTH and STOP_BITs (as the USART peripheral does). Your setup code seems to be a confusing mix of UART and USART configurations.
I also think you’ve to disable the PIO mode (probably with ioport_disable_port) when using UART0 pin functions.
I’d recommend to search again for matching UART demos/examples and/or use the reference manual for UART(0) details and ensure you setup your host terminal application matching your interface configuration (baud rate, 8 data bits, 1 start + 1 stop bit, parity).
Good luck !

It doesn’t look like this question is related to FreeRTOS. If that is the case I recommend asking on the microchip forms as there will be more people with chip specific knowledge there… Preference is to keep this forum dedicated to FreeRTOS.

Please send an email to support@microchip.com