/** * \file * * * \brief SAM3 debug support (implementation). * * \author Stefano Fedrigo */ #include #include /* for BV() */ #include #include #if (CONFIG_KDEBUG_PORT == 0) #define UART_BASE UART0_BASE #define UART_ID UART0_ID #define UART_PIO_BASE UART0_PORT #define UART_PERIPH UART0_PERIPH #define UART_PINS (BV(URXD0) | BV(UTXD0)) #elif (CONFIG_KDEBUG_PORT == 1) && UART_PORTS > 1 #define UART_BASE UART1_BASE #define UART_ID UART1_ID #define UART_PIO_BASE UART1_PORT #define UART_PERIPH UART1_PERIPH #define UART_PINS (BV(URXD1) | BV(UTXD1)) #else #error "UART port not supported in this board" #endif // TODO: refactor serial simple functions and use them, see lm3s kdebug #define KDBG_WAIT_READY() while (!(HWREG(UART_BASE + UART_SR_OFF) & BV(UART_SR_TXRDY))) {} #define KDBG_WAIT_TXDONE() while (!(HWREG(UART_BASE + UART_SR_OFF) & BV(UART_SR_TXEMPTY))) {} #define KDBG_WRITE_CHAR(c) do { HWREG(UART_BASE + UART_THR_OFF) = (c); } while(0) /* Debug unit is used only for debug purposes so does not generate interrupts. */ #define KDBG_MASK_IRQ(old) do { (void)old; } while(0) /* Debug unit is used only for debug purposes so does not generate interrupts. */ #define KDBG_RESTORE_IRQ(old) do { (void)old; } while(0) typedef uint32_t kdbg_irqsave_t; INLINE void kdbg_hw_init(void) { /* * Disable PIO mode and set appropriate UART pins peripheral mode. * SAM3X,A,N,S,U: all of them has all UARTs on peripheral A. */ HWREG(UART_PIO_BASE + PIO_PDR_OFF) = UART_PINS; PIO_PERIPH_SEL(UART_PIO_BASE, UART_PINS, UART_PERIPH); /* Enable the peripheral clock */ pmc_periphEnable(UART_ID); /* Reset and disable receiver & transmitter */ HWREG(UART_BASE + UART_CR_OFF) = BV(UART_CR_RSTRX) | BV(UART_CR_RSTTX) | BV(UART_CR_RXDIS) | BV(UART_CR_TXDIS); /* Set mode: normal, no parity */ HWREG(UART_BASE + UART_MR_OFF) = UART_MR_PAR_NO; /* Set baud rate */ HWREG(UART_BASE + UART_BRGR_OFF) = CPU_FREQ / CONFIG_KDEBUG_BAUDRATE / 16; /* Enable receiver & transmitter */ HWREG(UART_BASE + UART_CR_OFF) = BV(UART_CR_RXEN) | BV(UART_CR_TXEN); }