本帖最后由 lemonhub 于 2024-5-30 21:48 编辑
极海APM32F411V Tiny开发板评测08 APM32F4xx_DAL_Driver工程模板建立这几天在极海半导体官网逛的时候看到了APM32F4xx_DAL_SDK相关东西比较好奇,所以研究了研究。APM32F4xx_DAL_Driver是APM32F4系列的类似STM32-HAL抽象层的库,国产APM32芯片从标准固件库终于到HAL库了。 1. 准备目标硬件(开发板/芯片/模组)本教程将极海APM32F411 Tiny开发板进行示例移植,其他 ARM Cortex M4系列开发板和芯片移植方法类似。调试ARM Cortex M核还需要仿真器,如果您的开发板或者芯片模组没有板载仿真器,就需要连接外置的仿真器,如J-Link、DAPLink之类的。 2.准备编译器环境本移植指南针对的是Keil编译器,所以我们移植内核前需要先安装Keil编译器,能编译ARM Cortex M核的Keil编译器现在也叫MDK。 下载地址为:https://www.keil.com/demo/eval/arm.htm 3. APM32F4xx_DAL_Driver APM32F4xx_DAL_Driver是极海APM32F4 DAL SDK的一部分,APM32F4xx_DAL_Driver与STM32_HAL_Driver类似,属于抽象层库,同系列的芯片,使用同一套API函数,应用层快速迭代,丰富的组件和驱动抽象层。APM32F4XXDALSDK内容组成: 下载地址APM32F4 DAL SDK https://www.geehy.com/support/online_detail?id=75 APM32F4 DAL SDK组成
\
4. 工程创建文件结构 工程以GPIO例程作为基础创建。 1.Board
Source/board_apm32f411_tiny.c
Include/board_apm32f411_tiny.h
2.Libraries
Libraries/APM32F4xx_DAL_Driver/Include
Libraries/APM32F4xx_DAL_Driver/Source
Libraries/CMSIS
Libraries/Device
3.Middlewares
FreeRTOS/RT-Thread/LwIP/Fat_Fs等
4.Project
Project/MDK Project/IAR Project/GCC
Source/main.c 等
Include/main.h等
Config/Source/apm32f4xx_device_cfg.c等
Config/Include/apm32f4xx_device_cfg.h等
添加文件 Config配置文件(选择性配置)
上面的配置过程中,由于后面我们要开启log功能,我们需要打开 USE_LOG_COMPONENT 和 DAL_UART_MODULE_ENABLED - /* Configuration settings for log component */
- #define USE_LOG_COMPONENT 1U
- /* Include log header file */
- #include "apm32f4xx_dal_log.h"
添加串口驱动 由于在GPIO端口工程中,没有配置UART,因此需要进行配置 添加apm32f4xx_usart_cfg.c apm32f4xx_usart_cfg.h 对串口进行端口,波特率等配置 - /* Includes ***************************************************************/
- #include "apm32f4xx_usart_cfg.h"
-
- /* Private includes *******************************************************/
- #include <stdio.h>
-
- /* Private macro **********************************************************/
-
- /* Private typedef ********************************************************/
-
- /* Private variables ******************************************************/
- UART_HandleTypeDef huart1;
-
- /* Private function prototypes ********************************************/
-
- /* External variables *****************************************************/
-
- /* External functions *****************************************************/
-
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] USART1 configuration
- *
- * @param None
- *
- * @retval None
- */
- void DAL_USART1_Config(void)
- {
- huart1.Instance = USART1;
- huart1.Init.BaudRate = 115200U;
- huart1.Init.WordLength = UART_WORDLENGTH_8B;
- huart1.Init.StopBits = UART_STOPBITS_1;
- huart1.Init.Parity = UART_PARITY_NONE;
- huart1.Init.Mode = UART_MODE_TX_RX;
- huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart1.Init.OverSampling = UART_OVERSAMPLING_16;
- if (DAL_UART_Init(&huart1) != DAL_OK)
- {
- DAL_ErrorHandler();
- }
- }
-
- /**
- * @brief UART MSP Init
- *
- * @param huart Pointer to a UART_HandleTypeDef structure that contains
- * the configuration information for the specified UART module
- *
- * @retval None
- */
- void DAL_UART_MspInit(UART_HandleTypeDef *huart)
- {
- GPIO_InitTypeDef GPIO_InitStruct = {0};
-
- if (huart->Instance == USART1)
- {
- /* Enable USART1 GPIO clock */
- __DAL_RCM_GPIOA_CLK_ENABLE();
-
- /* Enable USART1 clock */
- __DAL_RCM_USART1_CLK_ENABLE();
-
- /* Configure the UART TX and RX pin */
- GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
- GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
-
- DAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- }
- }
-
- /**
- * @brief UART MSP DeInit
- *
- * @param huart Pointer to a UART_HandleTypeDef structure that contains
- * the configuration information for the specified UART module
- *
- * @retval None
- */
- void DAL_UART_MspDeInit(UART_HandleTypeDef *huart)
- {
- if (huart->Instance == USART1)
- {
- /* Reset USART */
- __DAL_RCM_USART1_FORCE_RESET();
- __DAL_RCM_USART1_RELEASE_RESET();
-
- /* Disable USART and GPIO clocks */
- DAL_GPIO_DeInit(GPIOA, GPIO_PIN_9 | GPIO_PIN_10);
-
- /* Disable USART interrupt */
- DAL_NVIC_DisableIRQ(USART1_IRQn);
- }
- }
-
- #if defined (__CC_ARM) || defined (__ICCARM__) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
-
- /*!
- * @brief Redirect C Library function printf to serial port.
- * After Redirection, you can use printf function.
- *
- * @param ch: The characters that need to be send.
- *
- * @param *f: pointer to a FILE that can recording all information
- * needed to control a stream
- *
- * @retval The characters that need to be send.
- *
- * @note
- */
- int fputc(int ch, FILE* f)
- {
- /* send a byte of data to the serial port */
- DAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1U, 1000U);
-
- return (ch);
- }
-
- #elif defined (__GNUC__)
-
- /*!
- * @brief Redirect C Library function printf to serial port.
- * After Redirection, you can use printf function.
- *
- * @param ch: The characters that need to be send.
- *
- * @retval The characters that need to be send.
- *
- * @note
- */
- int __io_putchar(int ch)
- {
- /* send a byte of data to the serial port */
- DAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1U, 1000U);
-
- return ch;
- }
-
- /*!
- * @brief Redirect C Library function printf to serial port.
- * After Redirection, you can use printf function.
- *
- * @param file: Meaningless in this function.
- *
- * @param *ptr: Buffer pointer for data to be sent.
- *
- * @param len: Length of data to be sent.
- *
- * @retval The characters that need to be send.
- *
- * @note
- */
- int _write(int file, char* ptr, int len)
- {
- int i;
- for (i = 0; i < len; i++)
- {
- __io_putchar(*ptr++);
- }
-
- return len;
- }
-
- #else
- #warning Not supported compiler type
- #endif
下载程序 主程序代码 - /* Includes ***************************************************************/
- #include "main.h"
- /* Private includes *******************************************************/
- #include "apm32f4xx_device_cfg.h"
- static const char* tag = "main";//log组件
- /**
- * @brief Main program
- */
- int main(void)
- {
- /* Device configuration */
- DAL_DeviceConfig();
- DAL_LOGE(tag, "Hardware_Init [ok] \r\n");
- DAL_LOGE(tag, "apm32f411tiny board testing 2024-05-30\n");
- DAL_LOGE(tag, "apm32f411tiny-board APM32F4xx_DAL_Driver\n");
- /* Infinite loop */
- while (1)
- {
- DAL_GPIO_TogglePin(GPIOE, GPIO_PIN_6);
- DAL_Delay(500U);
- DAL_LOGE(tag, "DAL_GPIO_TogglePin Testing\r\n");
- }
- }
采用APM32F411-Tiny Board自带的Geehy Link进行下载。
成功点亮。
在apm32f4xx_device_cfg.c中开启log打印组件,调试调试
|