基于AT32_Work_Bench配置AT32工程

基于AT32_Work_Bench配置AT32工程


AT32_Work_Bench工具是用来给AT32 MCU快速构建外设初始化工程软件,类似STM32的STM32CubeMX工具软件。

  • 📍AT32 TOOL系列工具下载地址:https://www.arterytek.com/cn/support/index.jsp?index=4
  • 🏷这里以AT32F435RGT7作为测试对象(对标STMF4系列),创建基于Keil平台编译的代码工程。
  • 🎈对应 Keil AT pack包下载地址:https://www.arterytek.com/cn/support/index.jsp?index=4

📑工程创建

🔖下面列举一些常见外设的基本配置。

    1. 新建工程
    1. 根据个人配置习惯,先配置debug,也就是下载和在线调试方式配置。
    1. CRM时钟配置:(如果选择关闭,则默认使用内部时钟源)

  • 点开列表可以参看对应总线上挂载的具体的哪些外设:



    1. GPIO 配置引脚输出
    1. 中断引脚配置
    1. NVIC中断配置
    1. 串口配置
    1. 代码预览功能查看
    1. 工程代码生成配置

  • Firmware Library固件包下载:https://www.arterytek.com/cn/product/AT32F435.jsp#Resource
  • 📜生成的工程:

    1. 使用DAP-LINK进行程序下载

  • 串口打印信息:

main测试代码

c 复制代码
/* add user code begin Header */
/**
  **************************************************************************
  * @file     main.c
  * @brief    main program
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * 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
  * 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.
  *
  **************************************************************************
  */
/* add user code end Header */

/* Includes ------------------------------------------------------------------*/
#include "at32f435_437_wk_config.h"

/* private includes ----------------------------------------------------------*/
/* add user code begin private includes */
#include "stdio.h"
#include "at32f435_437_int.h"
/* add user code end private includes */

/* private typedef -----------------------------------------------------------*/
/* add user code begin private typedef */

/* add user code end private typedef */

/* private define ------------------------------------------------------------*/
/* add user code begin private define */
/* delay macros */
#define STEP_DELAY_MS                    50
/**************** define print uart ******************/
#define PRINT_UART                       USART1

/* add user code end private define */

/* private macro -------------------------------------------------------------*/
/* add user code begin private macro */

/* add user code end private macro */

/* private variables ---------------------------------------------------------*/
/* add user code begin private variables */
/* delay variable */
static __IO uint32_t fac_us;
static __IO uint32_t fac_ms;
/* add user code end private variables */

/* private function prototypes --------------------------------------------*/
/* add user code begin function prototypes */
/* delay function */
void delay_init(void);
void delay_us(uint32_t nus);
void delay_ms(uint16_t nms);
void delay_sec(uint16_t sec);
/* add user code end function prototypes */

/* private user code ---------------------------------------------------------*/
/* add user code begin 0 */
/* support printf function, usemicrolib is unnecessary */
#if (__ARMCC_VERSION > 6000000)
__asm(".global __use_no_semihosting\n\t");
void _sys_exit(int x)
{
    x = x;
}
/* __use_no_semihosting was requested, but _ttywrch was */
void _ttywrch(int ch)
{
    ch = ch;
}
FILE __stdout;
#else
#ifdef __CC_ARM
#pragma import(__use_no_semihosting)
struct __FILE {
    int handle;
};
FILE __stdout;
void _sys_exit(int x)
{
    x = x;
}
/* __use_no_semihosting was requested, but _ttywrch was */
void _ttywrch(int ch)
{
    ch = ch;
}
#endif
#endif

#if defined (__GNUC__) && !defined (__clang__)
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif

/**
  * @brief  retargets the c library printf function to the usart.
  * @param  none
  * @retval none
  */
PUTCHAR_PROTOTYPE {
    while(usart_flag_get(PRINT_UART, USART_TDBE_FLAG) == RESET);
    usart_data_transmit(PRINT_UART, (uint16_t)ch);
    while(usart_flag_get(PRINT_UART, USART_TDC_FLAG) == RESET);
    return ch;
}

#if (defined (__GNUC__) && !defined (__clang__)) || (defined (__ICCARM__))
#if defined (__GNUC__) && !defined (__clang__)
int _write(int fd, char *pbuffer, int size)
#elif defined ( __ICCARM__ )
#pragma module_name = "?__write"
int __write(int fd, char *pbuffer, int size)
#endif
{
    for(int i = 0; i < size; i ++) {
        while(usart_flag_get(PRINT_UART, USART_TDBE_FLAG) == RESET);
        usart_data_transmit(PRINT_UART, (uint16_t)(*pbuffer++));
        while(usart_flag_get(PRINT_UART, USART_TDC_FLAG) == RESET);
    }

    return size;
}
#endif


/**
  * @brief  initialize delay function
  * @param  none
  * @retval none
  */
void delay_init()
{
    /* configure systick */
    systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV);
    fac_us = system_core_clock / (1000000U);
    fac_ms = fac_us * (1000U);
}

/**
  * @brief  inserts a delay time.
  * @param  nus: specifies the delay time length, in microsecond.
  * @retval none
  */
void delay_us(uint32_t nus)
{
    uint32_t temp = 0;
    SysTick->LOAD = (uint32_t)(nus * fac_us);
    SysTick->VAL = 0x00;
    SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk ;
    do {
        temp = SysTick->CTRL;
    } while((temp & 0x01) && !(temp & (1 << 16)));

    SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
    SysTick->VAL = 0x00;
}

/**
  * @brief  inserts a delay time.
  * @param  nms: specifies the delay time length, in milliseconds.
  * @retval none
  */
void delay_ms(uint16_t nms)
{
    uint32_t temp = 0;
    while(nms) {
        if(nms > STEP_DELAY_MS) {
            SysTick->LOAD = (uint32_t)(STEP_DELAY_MS * fac_ms);
            nms -= STEP_DELAY_MS;
        } else {
            SysTick->LOAD = (uint32_t)(nms * fac_ms);
            nms = 0;
        }
        SysTick->VAL = 0x00;
        SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
        do {
            temp = SysTick->CTRL;
        } while((temp & 0x01) && !(temp & (1 << 16)));

        SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
        SysTick->VAL = 0x00;
    }
}

/**
  * @brief  inserts a delay time.
  * @param  sec: specifies the delay time, in seconds.
  * @retval none
  */
void delay_sec(uint16_t sec)
{
    uint16_t index;
    for(index = 0; index < sec; index++) {
        delay_ms(500);
        delay_ms(500);
    }
}
/* add user code end 0 */

/**
  * @brief main function.
  * @param  none
  * @retval none
  */
int main(void)
{
    /* add user code begin 1 */
    uint32_t TimerUART;
    /* add user code end 1 */

    /* system clock config. */
    wk_system_clock_config();

    /* config periph clock. */
    wk_periph_clock_config();

    /* config systick clock source */
    systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_DIV8);
    /* system tick config */
    /**
     * use systick as time base source and configure 1ms tick.
     * users need add interrupt handler code into the below function in the at32f435_437_int.c file.
     *  --void SystTick_IRQHandler(void)
     */
    systick_interrupt_config(system_core_clock / 8 / 1000);

    /* nvic config. */
    wk_nvic_config();

    /* init usart1 function. */
    wk_usart1_init();

    /* init exint function. */
    wk_exint_config();

    /* init gpio function. */
    wk_gpio_config();

    /* add user code begin 2 */
    TimerUART = HAL_GetTick();
    //	delay_init();
    /* add user code end 2 */

    while(1) {
        /* add user code begin 3 */
        if((HAL_GetTick() - TimerUART) > 3000) {
            /* set GPIO Pin*/
            GPIOA->scr = GPIO_PINS_1;
            /* reset GPIO Pin*/
            GPIOA->clr = GPIO_PINS_1;

            printf("(AT32 Work Bench)AT32F435RG:%d\n", system_core_clock);
            TimerUART = HAL_GetTick();
        }
        /* add user code end 3 */
    }
}
  • 📚测试工程:
    • 🔖AT32F435RGT7
c 复制代码
链接:https://pan.baidu.com/s/1pBSVw7lunsLLMfdQsT_RLw?pwd=j5z7 
提取码:j5z7

📗BSP例程和在线例程

  • 🎉BSP例程在上面的Firmware Library固件包中。(下载地址https://www.arterytek.com/cn/product/AT32F435.jsp#Resource
  • 🥕在线例程补充:https://www.arterytek.com/cn/support/index.jsp?index=2