Stair56E UART project

This commit is contained in:
2026-08-05 19:07:52 +08:00
parent 7ca1af130d
commit f5654b70cc
2500 changed files with 619007 additions and 282610 deletions
+210
View File
@@ -0,0 +1,210 @@
/*!
* \file dma.c
*
* \brief Target dma implementation
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include "dma.h"
#include "xc_drv_dma.h"
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
// Source memory location
#define SRC_MEMORY_BASE (0x10006400)
#define SRC_MEMORY_TOP (0x100067ff)
// Destination memory location
#define DST_MEMORY_BASE (0x10007800)
#define DST_MEMORY_TOP (0x10007bff)
/*------------------------------------------------------------------------------------
Local Variables
-------------------------------------------------------------------------------------*/
static volatile bool tfr_flag;
static volatile bool err_flag;
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Func Prototype
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Functions
-------------------------------------------------------------------------------------*/
/**
****************************************************************************************
* @brief
*
* @param[in]
* @param[in]
****************************************************************************************
*/
void finish_callback(uint8_t eCode)
{
tfr_flag = true;
}
/**
****************************************************************************************
* @brief
*
* @param[in]
* @param[in]
****************************************************************************************
*/
void err_callback(uint8_t eCode)
{
// -------
// This function is called by the IRQ handler.
// We use this function to deal with interrupts that the DMA
// driver is unable to cater for (these are application
// specific). All of the interrupts handled by this function
// are cleared by the DMA driver, so there's no need to clear here.
// -------
// Check the source of the interrupt
if(eCode == DMA_IRQ_ERR) {
// Just inform the application that this interrupt has occured.
err_flag = true;
}
}
/**
****************************************************************************************
* @brief
*
* @param[in]
* @param[in]
****************************************************************************************
*/
void dma_mem2mem_finish(void)
{
while(tfr_flag == false) {
if(err_flag == true) {
// Wasn't expecting this !!
DEBUG("\nERROR: Recieved an err interrupt\n");
}
}
}
/**
****************************************************************************************
* @brief
*
* @param[in]
* @param[in]
****************************************************************************************
*/
/**
****************************************************************************************
* @brief
*
* @param[in]
* @param[in]
****************************************************************************************
*/
void dma_memory(void)
{
uint32_t *address;
uint8_t errorCode = DMA_OK, chIndex;
DMA_Chx_Cfg_t ch_cfg;
DEBUG("__DMA_MEMORY__\n");
xc_dma_init( );
NVIC_EnableIRQ(DMA_IRQn);
address = (uint32_t *) SRC_MEMORY_BASE;
while(address <= (uint32_t *) SRC_MEMORY_TOP) {
*(address) = (uint32_t) address;
DEBUG("SrcAddr0x%04x, val: 0x%04x\n", address, *(address));
address++;
}
address = (uint32_t *) DST_MEMORY_BASE;
while(address <= (uint32_t *) DST_MEMORY_TOP) {
*(address) = (uint32_t) 0x0;
DEBUG("DstVal: 0x%04x\n", *(address));
address++;
}
chIndex = xc_dma_get_channel_index(DMA_CHANNEL0);
// Enable the interrupts on Channel zero
errorCode = xc_dma_enable_channel_irq(DMA_CHANNEL0);
if(errorCode != 0) {
DEBUG("\nERROR: Failed to enable channel %d interrupts\n",
chIndex);
}
ch_cfg.sar = (uint32_t) SRC_MEMORY_BASE;
ch_cfg.dar = (uint32_t) DST_MEMORY_BASE;
ch_cfg.ctl_src_msize = DMA_MSIZE_1;
ch_cfg.ctl_dst_msize = DMA_MSIZE_1;
ch_cfg.ctl_sinc = DMA_ADDR_INCREMENT;
ch_cfg.ctl_dinc = DMA_ADDR_INCREMENT;
ch_cfg.ctl_src_tr_width = DMA_TRANS_WIDTH_32;
ch_cfg.ctl_dst_tr_width = DMA_TRANS_WIDTH_32;
ch_cfg.ctl_block_ts = (SRC_MEMORY_TOP - SRC_MEMORY_BASE + 1);
ch_cfg.ctl_tt_fc = DMA_MEM2MEM_DMA;
// Now we can intialise the channel configuration structure for
// DMA channel 0 by loading the structure members with the
// contents of the DMAC's channel 0 registers.
errorCode = xc_dma_set_channel_config(DMA_CHANNEL0, &ch_cfg);
if(errorCode != 0) {
DEBUG("\nERROR: Failed to initialise configuration\n");
}
xc_dma_set_listener(DMA_CHANNEL0, err_callback);
xc_dma_enable( );
errorCode = xc_dma_start_transfer(DMA_CHANNEL0, finish_callback);
if(errorCode != 0) {
DEBUG("\nERROR: Failed to begin the interrupt transfer\n");
}
dma_mem2mem_finish( );
xc_dma_disable( );
DEBUG("DMA Memory data transfer over: \n");
address = (uint32_t *) DST_MEMORY_BASE;
while(address <= (uint32_t *) DST_MEMORY_TOP) {
DEBUG("Rd_DstVal: 0x%04x\n", *(address));
address++;
}
}
+123
View File
@@ -0,0 +1,123 @@
/*!
* \file main.c
*
* \brief Target main implementation
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include "main.h"
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Func Prototype
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Functions
-------------------------------------------------------------------------------------*/
void clock_init(void)
{
CLOCK_InitCfg_t clock_cfg;
clock_cfg.hfclk_src = CLOCK_HFCLK_SRC_XTAL;
clock_cfg.hfclk_in = CLOCK_HFCLK_IN_32M;
clock_cfg.lfclk_src = CLOCK_LFCLK_SRC_RC;
if (clock_cfg.lfclk_src == CLOCK_LFCLK_SRC_XTAL) {
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32768;
} else if (clock_cfg.lfclk_src == CLOCK_LFCLK_SRC_RC) {
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32K;
}
xc_clock_init_cfg(&clock_cfg);
SysTick_Config(xc_clock_hfclk_in_get() / 100);
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
}
void app_uart_init(void)
{
GPIO_InitCfg_t gpio_cfg = {0};
gpio_cfg.Mux = GPIO_Mux0;
gpio_cfg.Pull = GPIO_PULLUP;
gpio_cfg.Int = NOT_INT;
gpio_cfg.FunSel = UART0_TX;
gpio_cfg.Pin = GPIO_18;
gpio_cfg.Dir = GPIO_DIR_OUTPUT;
xc_gpio_init(&gpio_cfg);
gpio_cfg.FunSel = UART0_RX;
gpio_cfg.Pin = GPIO_19;
gpio_cfg.Dir = GPIO_DIR_INPUT;
xc_gpio_init(&gpio_cfg);
UART_InitCfg_t uart_cfg = {0};
uart_cfg.Parity = UART_PARITY_DISABLE;
uart_cfg.StopBits = UART_STOP_1_BITS;
uart_cfg.WordLength = UART_DATA_8_BITS;
uart_cfg.BaudRate = UART_BAUDRATE_115200;
uart_cfg.HardwareFlowControl = UART_HWFC_DISABLE;
xc_uart_init(UART0_IDX, &uart_cfg);
}
/**
* @brief main
* @details
* @param[in] void
* @param[out] void
* @retval int - 0
* @retval void
* @par identifier
* reserve
* @par other
* void
* @par change log
* Alex created on 2023-05-31
*/
int main(void)
{
clock_init( );
app_uart_init( );
DEBUG("__START__\n");
dma_memory( );
while(1)
{
/* main loop */
}
}