Hi
I'm trying to use a UART on a Sharc core using DMA so I can send strings of data in the background. I have been able to configure the UART to transmit using core register access, but having difficulty getting a small DMA test function working. My code is below. The ARM just calls adi_gic_Init() before enabling the Sharc.
My code should output '[Hello][world!]', but only outputs '[][]' which are done using core access of the UART.
Can you point me towards where I'm going wrong?
Thanks
Howard
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "services/int/adi_sec.h"
#include "services/int/adi_int.h"
#include "platform_include.h"
#include "ADSP-SC59x_typedefs.h"
void uart_init(void) {
/* Use UART 0 for testing
* UART0_TX = PA_06 (multiplexed function 1)
* UART0_RX = PA_07 (multiplexed function 1)
*/
ADI_SPU_SECUREP_t secure_peripheral_reg;
secure_peripheral_reg.VALUE32 = 0;
secure_peripheral_reg.SSEC = 1;
secure_peripheral_reg.MSEC = 1;
*pREG_SPU0_SECUREP29 = secure_peripheral_reg.VALUE32; /* UART0 */
ADI_PORT_FER_SET_t port_func_set;
port_func_set.VALUE32 = 0;
port_func_set.PX6 = 1;
port_func_set.PX7 = 1;
*pREG_PORTA_FER_SET = port_func_set.VALUE32;
ADI_PORT_MUX_t port_mux;
port_mux.VALUE32 = 0;
port_mux.MUX6 = 1;
port_mux.MUX7 = 1;
*pREG_PORTA_MUX = port_mux.VALUE32;
/* Set baud rate to 300 - looks like SCLK0 is 125 MHz, not 100MHz as hinted in Hardware reference manual */
ADI_UART_CLK_t uart_clk;
uart_clk.VALUE32 = 0;
uart_clk.EDBO = UART_CLK_DIS_DIV_BY_ONE;
uart_clk.DIV = 26041;
*pREG_UART0_CLK = uart_clk.VALUE32;
ADI_UART_CTL_t uart_ctl;
uart_ctl.VALUE32 = 0;
uart_ctl.EN = UART_CTL_CLK_EN;
uart_ctl.MOD = UART_CTL_UART_MODE;
uart_ctl.WLS = UART_CTL_WL8BITS;
*pREG_UART0_CTL = uart_ctl.VALUE32;
*pREG_DMA20_STAT = 0xffffffff;
*pREG_DMA20_CFG = 0;
*pREG_DMA20_DSCPTR_NXT = 0;
*pREG_DMA20_ADDRSTART = 0;
*pREG_DMA20_XCNT = 0;
*pREG_DMA20_XMOD = 0;
*pREG_DMA20_YCNT = 0;
*pREG_DMA20_YMOD = 0;
adi_int_ClearPending(INTR_UART0_TXDMA);
}
void uart_print(const char * p_str) {
while ((*pREG_UART0_STAT & (1<<5)) == 0) {
;
}
*pREG_UART0_THR = '[';
/*
* From page 22-24 of SC592 HRM
*
* 1. Make sure that the UART_IMSK.ETBEI or the UART_IMSK.ERBFI bits are cleared before configuring the DMA.
* 2. Configure the dedicated DMA channel.
* 3. Set the UART_IMSK.ETBEI or UART_IMSK.ERBFI bits to start the transfer.
*
* From page 34-4 of SC592 HRM
*
* DMA20 UART0_TXDMA UART0 Transmit DMA
*/
ADI_UART_IMSK_CLR_t uart_imsk_clr;
uart_imsk_clr.VALUE32 = 0;
uart_imsk_clr.ETBEI = UART_IMSK_ETBEI_HI;
*pREG_UART0_IMSK_CLR = uart_imsk_clr.VALUE32;
ADI_DMA_CFG0_CFG_t dma_cfg;
dma_cfg.VALUE32 = 0;
dma_cfg.EN = DMA_CFG_EN;
dma_cfg.WNR = DMA_CFG_READ;
dma_cfg.PSIZE = DMA_CFG_PSIZE01;
dma_cfg.MSIZE = DMA_CFG_MSIZE01;
dma_cfg.FLOW = DMA_CFG_STOP;
dma_cfg.INT = DMA_CFG_XCNT_INT;
dma_cfg.TWOD = DMA_CFG_ADDR1D;
*pREG_DMA20_CFG = 0;
*pREG_DMA20_ADDRSTART = (uint32_t *)p_str;
*pREG_DMA20_XCNT = strlen(p_str);
*pREG_DMA20_XMOD = 1;
*pREG_DMA20_CFG = dma_cfg.VALUE32;
ADI_UART_IMSK_SET_t uart_imsk_set;
uart_imsk_set.VALUE32 = 0;
uart_imsk_set.ETBEI = UART_IMSK_ETBEI_HI;
*pREG_UART0_IMSK_SET = uart_imsk_set.VALUE32;
while ((*pREG_UART0_STAT & (1<<5)) == 0) {
;
}
*pREG_UART0_THR = ']';
adi_uart_DMAWrite()
return;
}
int main(int argc, char *argv[]) {
if (adi_sec_Init() != ADI_SEC_SUCCESS) {
return 1;
}
uart_init();
uart_print("Hello");
uart_print("world!");
return 0;
}