2021-12-13 21:39:13 -08:00
|
|
|
/**
|
|
|
|
**************************************************************************
|
|
|
|
* @file main.c
|
|
|
|
* @brief main program
|
|
|
|
**************************************************************************
|
|
|
|
* Copyright notice & Disclaimer
|
|
|
|
*
|
2022-04-11 04:50:25 -07:00
|
|
|
* The software Board Support Package (BSP) that is made available to
|
|
|
|
* download from Artery official website is the copyrighted work of Artery.
|
|
|
|
* Artery authorizes customers to use, copy, and distribute the BSP
|
|
|
|
* software and its related documentation for the purpose of design and
|
|
|
|
* development in conjunction with Artery microcontrollers. Use of the
|
2021-12-13 21:39:13 -08:00
|
|
|
* software is governed by this copyright notice and the following disclaimer.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
|
|
|
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
|
|
|
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
|
|
|
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
|
|
|
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
|
|
|
*
|
|
|
|
**************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "at32f435_437_board.h"
|
|
|
|
#include "at32f435_437_clock.h"
|
|
|
|
|
|
|
|
/** @addtogroup AT32F437_periph_examples
|
|
|
|
* @{
|
|
|
|
*/
|
2022-04-11 04:50:25 -07:00
|
|
|
|
2021-12-13 21:39:13 -08:00
|
|
|
/** @addtogroup 437_DMA_data_to_gpio DMA_data_to_gpio
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
gpio_init_type gpio_init_struct = {0};
|
|
|
|
dma_init_type dma_init_struct;
|
|
|
|
|
|
|
|
#define BUFFER_SIZE 16
|
2022-04-11 04:50:25 -07:00
|
|
|
uint16_t src_buffer[BUFFER_SIZE] = {0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008,
|
2021-12-13 21:39:13 -08:00
|
|
|
0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief main function.
|
|
|
|
* @param none
|
|
|
|
* @retval none
|
|
|
|
*/
|
|
|
|
int main(void)
|
|
|
|
{
|
2022-04-11 04:50:25 -07:00
|
|
|
/* initial system clock */
|
|
|
|
system_clock_config();
|
|
|
|
|
2021-12-13 21:39:13 -08:00
|
|
|
/* at board initial */
|
|
|
|
at32_board_init();
|
|
|
|
|
|
|
|
/* enable dma2/gpioc/tmr2 clock */
|
|
|
|
crm_periph_clock_enable(CRM_DMA2_PERIPH_CLOCK, TRUE);
|
|
|
|
crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
|
|
|
|
crm_periph_clock_enable(CRM_TMR2_PERIPH_CLOCK, TRUE);
|
2022-04-11 04:50:25 -07:00
|
|
|
|
2021-12-13 21:39:13 -08:00
|
|
|
/* config gpioc pin for output mode */
|
|
|
|
gpio_init_struct.gpio_pins = GPIO_PINS_ALL;
|
|
|
|
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
|
|
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
|
|
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
|
|
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
|
|
|
gpio_init(GPIOC, &gpio_init_struct);
|
2022-04-11 04:50:25 -07:00
|
|
|
|
2021-12-13 21:39:13 -08:00
|
|
|
tmr_base_init(TMR2, 0xFF, 0);
|
|
|
|
tmr_cnt_dir_set(TMR2, TMR_COUNT_UP);
|
2022-04-11 04:50:25 -07:00
|
|
|
|
2021-12-13 21:39:13 -08:00
|
|
|
/* enable tmr2 overflow dma request */
|
|
|
|
tmr_dma_request_enable(TMR2, TMR_OVERFLOW_DMA_REQUEST, TRUE);
|
2022-04-11 04:50:25 -07:00
|
|
|
|
2021-12-13 21:39:13 -08:00
|
|
|
/* dma2 channel1 configuration */
|
|
|
|
dma_reset(DMA2_CHANNEL1);
|
|
|
|
dma_init_struct.buffer_size = BUFFER_SIZE;
|
|
|
|
dma_init_struct.direction = DMA_DIR_MEMORY_TO_PERIPHERAL;
|
|
|
|
dma_init_struct.memory_base_addr = (uint32_t)src_buffer;
|
|
|
|
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_HALFWORD;
|
|
|
|
dma_init_struct.memory_inc_enable = TRUE;
|
|
|
|
dma_init_struct.peripheral_base_addr = (uint32_t)&GPIOC->odt;
|
|
|
|
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_HALFWORD;
|
|
|
|
dma_init_struct.peripheral_inc_enable = FALSE;
|
|
|
|
dma_init_struct.priority = DMA_PRIORITY_MEDIUM;
|
|
|
|
dma_init_struct.loop_mode_enable = FALSE;
|
|
|
|
dma_init(DMA2_CHANNEL1, &dma_init_struct);
|
2022-04-11 04:50:25 -07:00
|
|
|
|
2023-01-05 22:52:01 -08:00
|
|
|
/* enable transfer full data interrupt */
|
2021-12-13 21:39:13 -08:00
|
|
|
dma_interrupt_enable(DMA2_CHANNEL1, DMA_FDT_INT, TRUE);
|
2022-04-11 04:50:25 -07:00
|
|
|
|
2021-12-13 21:39:13 -08:00
|
|
|
/* dma2 channel1 interrupt nvic init */
|
|
|
|
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
|
|
|
|
nvic_irq_enable(DMA2_Channel1_IRQn, 1, 0);
|
2022-04-11 04:50:25 -07:00
|
|
|
|
2021-12-13 21:39:13 -08:00
|
|
|
/* tmr2 dmamux function enable */
|
|
|
|
dmamux_enable(DMA2, TRUE);
|
|
|
|
dmamux_init(DMA2MUX_CHANNEL1, DMAMUX_DMAREQ_ID_TMR2_OVERFLOW);
|
2022-04-11 04:50:25 -07:00
|
|
|
|
2021-12-13 21:39:13 -08:00
|
|
|
/* enable dma channel */
|
|
|
|
dma_channel_enable(DMA2_CHANNEL1, TRUE);
|
2022-04-11 04:50:25 -07:00
|
|
|
|
2021-12-13 21:39:13 -08:00
|
|
|
/* enable tmr2 */
|
|
|
|
tmr_counter_enable(TMR2, TRUE);
|
2022-04-11 04:50:25 -07:00
|
|
|
|
2021-12-13 21:39:13 -08:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
2022-04-11 04:50:25 -07:00
|
|
|
*/
|
2021-12-13 21:39:13 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|