本帖最后由 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配置文件(选择性配置) /**
* [url=home.php?mod=space&uid=288409]@file[/url] apm32f4xx_dal_cfg.h
*
* [url=home.php?mod=space&uid=247401]@brief[/url] DAL configuration file
*
* [url=home.php?mod=space&uid=895143]@version[/url] V1.0.0
*
* [url=home.php?mod=space&uid=212281]@date[/url] 2023-12-01
*
* @attention
*
* Copyright (C) 2023 Geehy Semiconductor
*
* You may not use this file except in compliance with the
* GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
*
* The program is only for reference, which is distributed in the hope
* that it will be useful and instructional for customers to develop
* their software. Unless required by applicable law or agreed to in
* writing, the program is distributed on an "AS IS" BASIS, WITHOUT
* ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
* See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
* and limitations under the License.
*/
/* Define to prevent recursive inclusion */
#ifndef APM32F4xx_DAL_CFG_H
#define APM32F4xx_DAL_CFG_H
#ifdef __cplusplus
extern "C" {
#endif
/* Configuration settings for log component */
#define USE_LOG_COMPONENT 1U
/* Include log header file */
#include "apm32f4xx_dal_log.h"
/* Configuration settings for assert enable */
/* #define USE_FULL_ASSERT 1U */
/* DAL module configuration */
#define DAL_MODULE_ENABLED
//#define DAL_ADC_MODULE_ENABLED
//#define DAL_CAN_MODULE_ENABLED
//#define DAL_CRC_MODULE_ENABLED
//#define DAL_COMP_MODULE_ENABLED
#define DAL_DMA_MODULE_ENABLED
#define DAL_FLASH_MODULE_ENABLED
//#define DAL_NAND_MODULE_ENABLED
//#define DAL_NOR_MODULE_ENABLED
//#define DAL_PCCARD_MODULE_ENABLED
//#define DAL_SRAM_MODULE_ENABLED
#define DAL_GPIO_MODULE_ENABLED
//#define DAL_EINT_MODULE_ENABLED
//#define DAL_I2C_MODULE_ENABLED
//#define DAL_SMBUS_MODULE_ENABLED
//#define DAL_I2S_MODULE_ENABLED
//#define DAL_IWDT_MODULE_ENABLED
#define DAL_PMU_MODULE_ENABLED
//#define DAL_QSPI_MODULE_ENABLED
#define DAL_RCM_MODULE_ENABLED
//#define DAL_RNG_MODULE_ENABLED
//#define DAL_RTC_MODULE_ENABLED
//#define DAL_SD_MODULE_ENABLED
//#define DAL_SPI_MODULE_ENABLED
//#define DAL_TMR_MODULE_ENABLED
#define DAL_UART_MODULE_ENABLED
#define DAL_USART_MODULE_ENABLED
//#define DAL_IRDA_MODULE_ENABLED
//#define DAL_SMARTCARD_MODULE_ENABLED
//#define DAL_WWDT_MODULE_ENABLED
#define DAL_CORTEX_MODULE_ENABLED
//#define DAL_PCD_MODULE_ENABLED
//#define DAL_HCD_MODULE_ENABLED
//#define DAL_MMC_MODULE_ENABLED
/* Value of the external high speed oscillator in Hz */
#if !defined (HSE_VALUE)
#define HSE_VALUE 8000000U
#endif /* HSE_VALUE */
/* Timeout for external high speed oscillator in ms */
#if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT 100U
#endif /* HSE_STARTUP_TIMEOUT */
/* Value of the internal high speed oscillator in Hz */
#if !defined (HSI_VALUE)
#define HSI_VALUE 16000000U
#endif /* HSI_VALUE */
/* Value of the internal low speed oscillator in Hz */
#if !defined (LSI_VALUE)
#define LSI_VALUE 32000U
#endif /* LSI_VALUE */
/* Value of the external low speed oscillator in Hz */
#if !defined (LSE_VALUE)
#define LSE_VALUE 32768U
#endif /* LSE_VALUE */
/* Timeout for external low speed oscillator in ms */
#if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT 5000U
#endif /* LSE_STARTUP_TIMEOUT */
/* Value of the external high speed oscillator in Hz for I2S peripheral */
#if !defined (EXTERNAL_CLOCK_VALUE)
#define EXTERNAL_CLOCK_VALUE 12288000U
#endif /* EXTERNAL_CLOCK_VALUE */
/* System Configuration */
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY 0x0FU /*!< tick interrupt priority */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 1U
#define INSTRUCTION_CACHE_ENABLE 1U
#define DATA_CACHE_ENABLE 1U
/* DAL peripheral register callbacks */
#define USE_DAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */
#define USE_DAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */
#define USE_DAL_CRYP_REGISTER_CALLBACKS 0U /* CRYP register callback disabled */
#define USE_DAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */
#define USE_DAL_DCI_REGISTER_CALLBACKS 0U /* DCI register callback disabled */
#define USE_DAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */
#define USE_DAL_HASH_REGISTER_CALLBACKS 0U /* HASH register callback disabled */
#define USE_DAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */
#define USE_DAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */
#define USE_DAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */
#define USE_DAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */
#define USE_DAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */
#define USE_DAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */
#define USE_DAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */
#define USE_DAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */
#define USE_DAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */
#define USE_DAL_RNG_REGISTER_CALLBACKS 0U /* RNG register callback disabled */
#define USE_DAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */
#define USE_DAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */
#define USE_DAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */
#define USE_DAL_SDRAM_REGISTER_CALLBACKS 0U /* SDRAM register callback disabled */
#define USE_DAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */
#define USE_DAL_SMBUS_REGISTER_CALLBACKS 0U /* SMBUS register callback disabled */
#define USE_DAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */
#define USE_DAL_TMR_REGISTER_CALLBACKS 0U /* TMR register callback disabled */
#define USE_DAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */
#define USE_DAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */
#define USE_DAL_WWDT_REGISTER_CALLBACKS 0U /* WWDT register callback disabled */
/* Ethernet peripheral configuration */
/* Addr and buffer size */
/* MAC ADDRESS */
#define ETH_MAC_ADDR_0 2U
#define ETH_MAC_ADDR_1 0U
#define ETH_MAC_ADDR_2 0U
#define ETH_MAC_ADDR_3 0U
#define ETH_MAC_ADDR_4 0U
#define ETH_MAC_ADDR_5 0U
/* Ethernet driver buffers size and number */
#define ETH_BUFFER_SIZE_RX ETH_MAX_PACKET_SIZE /* Buffer size for receive */
#define ETH_BUFFER_SIZE_TX ETH_MAX_PACKET_SIZE /* Buffer size for transmit */
#define ETH_BUFFER_NUMBER_RX 4U /* 4 Rx buffers of size ETH_BUFFER_SIZE_RX */
#define ETH_BUFFER_NUMBER_TX 4U /* 4 Tx buffers of size ETH_BUFFER_SIZE_TX */
/* Delay and timeout */
/* PHY Reset MAX Delay */
#define EXT_PHY_RESET_MAX_DELAY 0x000000FFU
/* PHY Configuration MAX Delay */
#define EXT_PHY_CONFIG_MAX_DELAY 0x00000FFFU
#define EXT_PHY_READ_TIMEOUT 0x0000FFFFU
#define EXT_PHY_WRITE_TIMEOUT 0x0000FFFFU
/* SPI peripheral configuration */
/* SPI CRC FEATURE */
#define USE_SPI_CRC 1U
/* Include module's header file */
#ifdef DAL_RCM_MODULE_ENABLED
#include "apm32f4xx_dal_rcm.h"
#endif /* DAL_RCM_MODULE_ENABLED */
#ifdef DAL_GPIO_MODULE_ENABLED
#include "apm32f4xx_dal_gpio.h"
#endif /* DAL_GPIO_MODULE_ENABLED */
#ifdef DAL_EINT_MODULE_ENABLED
#include "apm32f4xx_dal_eint.h"
#endif /* DAL_EINT_MODULE_ENABLED */
#ifdef DAL_DMA_MODULE_ENABLED
#include "apm32f4xx_dal_dma.h"
#endif /* DAL_DMA_MODULE_ENABLED */
#ifdef DAL_CORTEX_MODULE_ENABLED
#include "apm32f4xx_dal_cortex.h"
#endif /* DAL_CORTEX_MODULE_ENABLED */
#ifdef DAL_ADC_MODULE_ENABLED
#include "apm32f4xx_dal_adc.h"
#endif /* DAL_ADC_MODULE_ENABLED */
#ifdef DAL_CAN_MODULE_ENABLED
#include "apm32f4xx_dal_can.h"
#endif /* DAL_CAN_MODULE_ENABLED */
#ifdef DAL_CRC_MODULE_ENABLED
#include "apm32f4xx_dal_crc.h"
#endif /* DAL_CRC_MODULE_ENABLED */
#ifdef DAL_CRYP_MODULE_ENABLED
#include "apm32f4xx_dal_cryp.h"
#endif /* DAL_CRYP_MODULE_ENABLED */
#ifdef DAL_DAC_MODULE_ENABLED
#include "apm32f4xx_dal_dac.h"
#endif /* DAL_DAC_MODULE_ENABLED */
#ifdef DAL_DCI_MODULE_ENABLED
#include "apm32f4xx_dal_dci.h"
#endif /* DAL_DCI_MODULE_ENABLED */
#ifdef DAL_ETH_MODULE_ENABLED
#include "apm32f4xx_dal_eth.h"
#endif /* DAL_ETH_MODULE_ENABLED */
#ifdef DAL_FLASH_MODULE_ENABLED
#include "apm32f4xx_dal_flash.h"
#endif /* DAL_FLASH_MODULE_ENABLED */
#ifdef DAL_HASH_MODULE_ENABLED
#include "apm32f4xx_dal_hash.h"
#endif /* DAL_HASH_MODULE_ENABLED */
#ifdef DAL_HCD_MODULE_ENABLED
#include "apm32f4xx_dal_hcd.h"
#endif /* DAL_HCD_MODULE_ENABLED */
#ifdef DAL_I2C_MODULE_ENABLED
#include "apm32f4xx_dal_i2c.h"
#endif /* DAL_I2C_MODULE_ENABLED */
#ifdef DAL_I2S_MODULE_ENABLED
#include "apm32f4xx_dal_i2s.h"
#endif /* DAL_I2S_MODULE_ENABLED */
#ifdef DAL_IRDA_MODULE_ENABLED
#include "apm32f4xx_dal_irda.h"
#endif /* DAL_IRDA_MODULE_ENABLED */
#ifdef DAL_MMC_MODULE_ENABLED
#include "apm32f4xx_dal_mmc.h"
#endif /* DAL_MMC_MODULE_ENABLED */
#ifdef DAL_NAND_MODULE_ENABLED
#include "apm32f4xx_dal_nand.h"
#endif /* DAL_NAND_MODULE_ENABLED */
#ifdef DAL_NOR_MODULE_ENABLED
#include "apm32f4xx_dal_nor.h"
#endif /* DAL_NOR_MODULE_ENABLED */
#ifdef DAL_PCCARD_MODULE_ENABLED
#include "apm32f4xx_dal_pccard.h"
#endif /* DAL_PCCARD_MODULE_ENABLED */
#ifdef DAL_PCD_MODULE_ENABLED
#include "apm32f4xx_dal_pcd.h"
#endif /* DAL_PCD_MODULE_ENABLED */
#ifdef DAL_PMU_MODULE_ENABLED
#include "apm32f4xx_dal_pmu.h"
#endif /* DAL_PMU_MODULE_ENABLED */
#ifdef DAL_RNG_MODULE_ENABLED
#include "apm32f4xx_dal_rng.h"
#endif /* DAL_RNG_MODULE_ENABLED */
#ifdef DAL_RTC_MODULE_ENABLED
#include "apm32f4xx_dal_rtc.h"
#endif /* DAL_RTC_MODULE_ENABLED */
#ifdef DAL_SRAM_MODULE_ENABLED
#include "apm32f4xx_dal_sram.h"
#endif /* DAL_SRAM_MODULE_ENABLED */
#ifdef DAL_SDRAM_MODULE_ENABLED
#include "apm32f4xx_dal_sdram.h"
#endif /* DAL_SDRAM_MODULE_ENABLED */
#ifdef DAL_SMBUS_MODULE_ENABLED
#include "apm32f4xx_dal_smbus.h"
#endif /* DAL_SMBUS_MODULE_ENABLED */
#ifdef DAL_SD_MODULE_ENABLED
#include "apm32f4xx_dal_sd.h"
#endif /* DAL_SD_MODULE_ENABLED */
#ifdef DAL_SPI_MODULE_ENABLED
#include "apm32f4xx_dal_spi.h"
#endif /* DAL_SPI_MODULE_ENABLED */
#ifdef DAL_SMARTCARD_MODULE_ENABLED
#include "apm32f4xx_dal_smartcard.h"
#endif /* DAL_SMARTCARD_MODULE_ENABLED */
#ifdef DAL_TMR_MODULE_ENABLED
#include "apm32f4xx_dal_tmr.h"
#endif /* DAL_TMR_MODULE_ENABLED */
#ifdef DAL_UART_MODULE_ENABLED
#include "apm32f4xx_dal_uart.h"
#endif /* DAL_UART_MODULE_ENABLED */
#ifdef DAL_USART_MODULE_ENABLED
#include "apm32f4xx_dal_usart.h"
#endif /* DAL_USART_MODULE_ENABLED */
#ifdef DAL_IWDT_MODULE_ENABLED
#include "apm32f4xx_dal_iwdt.h"
#endif /* DAL_IWDT_MODULE_ENABLED */
#ifdef DAL_WWDT_MODULE_ENABLED
#include "apm32f4xx_dal_wwdt.h"
#endif /* DAL_WWDT_MODULE_ENABLED */
/* Assert Component */
#if (USE_FULL_ASSERT == 1U)
#define ASSERT_PARAM(_PARAM_) ((_PARAM_) ? (void)0U : AssertFailedHandler((uint8_t *)__FILE__, __LINE__))
/* Declaration */
void AssertFailedHandler(uint8_t *file, uint32_t line);
#else
#define ASSERT_PARAM(_PARAM_) ((void)0U)
#endif /* USE_FULL_ASSERT */
void DAL_ErrorHandler(void);
#ifdef __cplusplus
}
#endif
#endif /* APM32F4xx_DAL_CFG_H */
上面的配置过程中,由于后面我们要开启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打印组件,调试调试
|