This post was last edited by ¤ß¤º¤¸ on 2024-2-7 17:02 ### 03 The official graphical configuration tool Work Bench for the evaluation of the Ateli AT32A403 development board uses the complete code. For the complete record, see the repository (the markdown of the forum always feels a bit problematic, so I back it up on Gitee) [AT32_Baord Gitee](https://gitee.com/End-ING/embedded-arterytek32-board/blob/master/note/03%20%E9%9B%85%E7%89%B9%E5%8A%9BAT32A403%E5%BC%80%E5%8F%91%E6%9D%BF%E8%AF%84%E6%B5%8B%2003 %20%E5%AE%98%E6%96%B9%E5%9B%BE%E5%BD%A2%E5%8C%96%E9%85%8D%E7%BD%AE%E5%B7%A5%E5%85%B7Work%20Bench%E4%BD%BF%E7%94%A8.md "AT32_Baord") ### 1. Hardware and software platform 1. AT32A403A Board development board 2. MDK-ARM Keil 3. Work Bench
Experimental phenomenon
at32
at321
### 2. AT32 Work Bench In order to facilitate developers to quickly develop chips, foreign manufacturers have developed microcontroller graphical configuration tools to generate initialization configuration codes. The most widely used ones are STMicroelectronics' STM32CubeMX and Renesas Electronics' e2stuio development tool FSP. In recent years, domestic MCU development manufacturers have also developed rapidly, but there are still relatively few graphical configuration tools. I know only Arteli's AT32 Work Bench and Xiaohua Semiconductor's XHCode, and another 8-bit MCU manufacturer, Saiyuan Electronics.
AT32 Work Bench has the following main features: 1. Support peripheral initialization configuration 2. Support PIN MUX configuration, and can customize PIN foot labels 3. Support system clock automatic configuration 4. Support online code preview, WYSIWYG 5. Support add user code function (customer existing code will not be overwritten by the newly generated project) 6. Support Keil, IAR, AT32 IDE and other common IDE project automatic generation 7. Support recently edited design records 8. Support configuration PDF report generation 9. Support Chinese and English switching 10. Support Windows, Linux and other platforms 11. Support online software upgrade, as well as online download of MCU firmware Download address https://www.arterytek.com/cn/support/index.jsp?index=0
Supports Windows and Linux system development. Windows system does not require installation and can be directly opened for use.
### 3. AT32 Work Bench creates a project test 1. Open the AT32 Work Bench software, select the development chip, simply configure the chip type, and create a configuration project. Take the AT32A403 chip as a test case and perform all the following operations.
2. Configure the onboard LED, configure the GPIO port mode, and the output mode GPIO_Output.
3. Serial port printing configuration, configure USART1 use PA9, PA10 select asynchronous mode, baud rate and other specific configurations are as follows
4. Generate project template click Generate Code, set the generated code path, set the chip driver library version. Set the project name, project location, tool chain used (MDK-KEIL), select the MCU firmware package version, if not, you need to add it yourself, click Firmware Package Management, select the corresponding chip, and download it.
Open the generated KEIL project to view the generated code.
GPIO port configuration function
USART1 serial port configuration function
Clock enable configuration function
5. Add personal files and make modifications. 1. Add the bsp_delay.c bsp_delay.h file to improve the delay_us, delay_ms functions ```c /* delay variable */ static __IO uint32_t fac_us; static __IO uint32_t fac_ms; /** * @brief initialize delay function * @param none * @retval none */ void delay_init() { /* configure systick */ systick_clock_source_config(SYSTI CK_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) { temp uint32_t = 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 &= ~S ysTick_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; } } ``` 2. Add bsp_uart.c bsp_uart.h files to improve the serial port printing function. The serial port 1 configuration code used here is generated by the tool. I created independent c and h files, so it is necessary to comment at32a403a_wk_config. c and wk_usart1_init function definition and declaration in at32a403a_wk_config.h file. (The purpose of this is just a personal habit) ```c /* 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(USART1, USART_TDBE_FLAG) == RESET); usart_data_transmit(USART1, (uint16_t)ch); while(usart_flag_get(USART1, 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
void wk_usart1_init(void)
{
/* add user code begin usart1_init 0 */
/* add user code end usart1_init 0 */
gpio_init_type gpio_init_struct;
gpio_default_para_init(&gpio_init_struct);
/* add user code begin usart1_init 1 */
/* add user code end usart1_init 1 */
/* configure the TX pin */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_pins = GPIO_PINS_9;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_init_struct);
/* configure the RX pin */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_10;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_init_struct);
/* configure param */
usart_init(USART1, 115200, USART_DATA_8BITS, USART_STOP_1_BIT);
usart_transmitter_enable(USART1, TRUE);
usart_receiver_enable(USART1, TRUE);
usart_parity_selection_config(USART1, USART_PARITY_NONE);
usart_hardware_flow_control_set(USART1, USART_HARDWARE_FLOW_NONE);
usart_enable(USART1, TRUE);
/* add user code begin usart1_init 2 */
/* add user code end usart1_init 2 */
}
```
ÏÂÔØ´úÂë
°åÔØAT-LinkÏÂÔسÌÐò£¬Ö§³ÖÐéÄâ´®¿Ú£¬²¢¶Ô½Óµ½PA9,PA10¡£ÕâÀïÎÒÑ¡ÔñÁËAT-Link-EZ CMSIS-DAP,֮ǰÎÒÖ±½ÓÏÂÔصŤ³Ì£¬È´ÏÔʾÎÞ·ÇÏÂÔØ£¬µ«ÊÇÏÂÔرðÈ˵Ť³ÌȴûÓÐÎÊÌ⣬²»ÖªµÀɶ×ÓÇé¿ö£¬È»ºóÉèÖóÉÕâ¸öģʽ£¬ÏÂÔØ´úÂë¾ÍûÓÐÎÊÌâÁË£¬¾ßÌåÔÒò¿ÉÄܲ»ÊÇÕâ¸ö¡£
gpio_mode = GPIO_MODE_INPUT; gpio_init_struct.gpio_pins = GPIO_PINS_10; gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOA, &gpio_init_struct); /* configure param */ usart_init(USART1, 115200, USART_DATA_8BITS, USART_STOP_1_BIT); usart_transmitter_enable(USART1, TRUE); usart_receiver_enable(USART1 , TRUE); usart_parity_selection_config(USART1, USART_PARITY_NONE); usart_hardware_flow_control_set(USART1, USART_HARDWARE_FLOW_NONE); usart_enable(USART1, TRUE); /* add user code begin usart1_init 2 */ /* add user code end usart1_init 2 */ } ``` Download code The onboard AT-Link downloader supports virtual serial ports and can be connected to PA9 and PA10. Here I chose AT-Link-EZ CMSIS-DAP. The project I downloaded directly showed that it was not downloading, but there was no problem downloading other people's projects. I don't know what happened. Then I set it to this mode and there was no problem downloading the code. The specific reason may not be this. [attach]785519[/attach ]gpio_mode = GPIO_MODE_INPUT; gpio_init_struct.gpio_pins = GPIO_PINS_10; gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOA, &gpio_init_struct); /* configure param */ usart_init(USART1, 115200, USART_DATA_8BITS, USART_STOP_1_BIT); usart_transmitter_enable(USART1, TRUE); usart_receiver_enable(USART1 , TRUE); usart_parity_selection_config(USART1, USART_PARITY_NONE); usart_hardware_flow_control_set(USART1, USART_HARDWARE_FLOW_NONE); usart_enable(USART1, TRUE); /* add user code begin usart1_init 2 */ /* add user code end usart1_init 2 */ } ``` Download code The onboard AT-Link downloader supports virtual serial ports and can be connected to PA9 and PA10. Here I chose AT-Link-EZ CMSIS-DAP. The project I downloaded directly showed that it was not downloading, but there was no problem downloading other people's projects. I don't know what happened. Then I set it to this mode and there was no problem downloading the code. The specific reason may not be this. [attach]785519[/attach ]