[活动] 极海APM32F411V Tiny开发板评测 APM32F4xx_DAL_Driver工程模板建立

[复制链接]
 楼主| lemonhub 发表于 2024-5-30 21:49 | 显示全部楼层 |阅读模式
本帖最后由 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之类的。
apm32.jpg
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内容组成:
hal-00.jpg
  • Application:例程和模板工程
  • 中间件:USB、RTOS、文件系统和网络协议栈
  • IDE支持:Keil-MDK、IAR-EWARM、Eclipse-GCC等
  • 驱动和组件:DAL库、DDL库、CMSIScore设备文件、BSP和Component等

hal-05.jpg
下载地址APM32F4 DAL SDK https://www.geehy.com/support/online_detail?id=75
hal-0.jpg
hal-01.jpg
hal-02.jpg
hal-03.jpg
hal-04.jpg
APM32F4 DAL SDK组成
hal-06.jpg
hal-07.jpg
hal-08.jpg \ hal-09.jpg
hal-12.jpg
hal-13.jpg

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等
       
    hal-15.jpg
  • 添加文件
    hal-16.jpg
    hal-17.jpg
  • Config配置文件(选择性配置)
    1. /**
    2. * [url=home.php?mod=space&uid=288409]@file[/url]       apm32f4xx_dal_cfg.h
    3. *
    4. * [url=home.php?mod=space&uid=247401]@brief[/url]       DAL configuration file
    5. *
    6. * [url=home.php?mod=space&uid=895143]@version[/url]     V1.0.0
    7. *
    8. * [url=home.php?mod=space&uid=212281]@date[/url]       2023-12-01
    9. *
    10. * @attention
    11. *
    12. * Copyright (C) 2023 Geehy Semiconductor
    13. *
    14. * You may not use this file except in compliance with the
    15. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
    16. *
    17. * The program is only for reference, which is distributed in the hope
    18. * that it will be useful and instructional for customers to develop
    19. * their software. Unless required by applicable law or agreed to in
    20. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
    21. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
    22. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
    23. * and limitations under the License.
    24. */


    25. /* Define to prevent recursive inclusion */
    26. #ifndef APM32F4xx_DAL_CFG_H
    27. #define APM32F4xx_DAL_CFG_H

    28. #ifdef __cplusplus
    29. extern "C" {
    30. #endif

    31. /* Configuration settings for log component */
    32. #define USE_LOG_COMPONENT   1U
    33. /* Include log header file */
    34. #include "apm32f4xx_dal_log.h"

    35. /* Configuration settings for assert enable */
    36. /* #define USE_FULL_ASSERT     1U */

    37. /* DAL module configuration */
    38. #define DAL_MODULE_ENABLED
    39. //#define DAL_ADC_MODULE_ENABLED
    40. //#define DAL_CAN_MODULE_ENABLED
    41. //#define DAL_CRC_MODULE_ENABLED
    42. //#define DAL_COMP_MODULE_ENABLED
    43. #define DAL_DMA_MODULE_ENABLED
    44. #define DAL_FLASH_MODULE_ENABLED
    45. //#define DAL_NAND_MODULE_ENABLED
    46. //#define DAL_NOR_MODULE_ENABLED
    47. //#define DAL_PCCARD_MODULE_ENABLED
    48. //#define DAL_SRAM_MODULE_ENABLED
    49. #define DAL_GPIO_MODULE_ENABLED
    50. //#define DAL_EINT_MODULE_ENABLED
    51. //#define DAL_I2C_MODULE_ENABLED
    52. //#define DAL_SMBUS_MODULE_ENABLED
    53. //#define DAL_I2S_MODULE_ENABLED
    54. //#define DAL_IWDT_MODULE_ENABLED
    55. #define DAL_PMU_MODULE_ENABLED
    56. //#define DAL_QSPI_MODULE_ENABLED
    57. #define DAL_RCM_MODULE_ENABLED
    58. //#define DAL_RNG_MODULE_ENABLED
    59. //#define DAL_RTC_MODULE_ENABLED
    60. //#define DAL_SD_MODULE_ENABLED
    61. //#define DAL_SPI_MODULE_ENABLED
    62. //#define DAL_TMR_MODULE_ENABLED
    63. #define DAL_UART_MODULE_ENABLED
    64. #define DAL_USART_MODULE_ENABLED
    65. //#define DAL_IRDA_MODULE_ENABLED
    66. //#define DAL_SMARTCARD_MODULE_ENABLED
    67. //#define DAL_WWDT_MODULE_ENABLED
    68. #define DAL_CORTEX_MODULE_ENABLED
    69. //#define DAL_PCD_MODULE_ENABLED
    70. //#define DAL_HCD_MODULE_ENABLED
    71. //#define DAL_MMC_MODULE_ENABLED

    72. /* Value of the external high speed oscillator in Hz */
    73. #if !defined (HSE_VALUE)
    74. #define HSE_VALUE             8000000U
    75. #endif /* HSE_VALUE */

    76. /* Timeout for external high speed oscillator in ms */
    77. #if !defined (HSE_STARTUP_TIMEOUT)
    78. #define HSE_STARTUP_TIMEOUT   100U
    79. #endif /* HSE_STARTUP_TIMEOUT */

    80. /* Value of the internal high speed oscillator in Hz */
    81. #if !defined (HSI_VALUE)
    82. #define HSI_VALUE             16000000U
    83. #endif /* HSI_VALUE */

    84. /* Value of the internal low speed oscillator in Hz */
    85. #if !defined (LSI_VALUE)
    86. #define LSI_VALUE               32000U
    87. #endif /* LSI_VALUE */

    88. /* Value of the external low speed oscillator in Hz */
    89. #if !defined (LSE_VALUE)
    90. #define LSE_VALUE               32768U
    91. #endif /* LSE_VALUE */

    92. /* Timeout for external low speed oscillator in ms */
    93. #if !defined (LSE_STARTUP_TIMEOUT)
    94. #define LSE_STARTUP_TIMEOUT   5000U
    95. #endif /* LSE_STARTUP_TIMEOUT */

    96. /* Value of the external high speed oscillator in Hz for I2S peripheral */
    97. #if !defined (EXTERNAL_CLOCK_VALUE)
    98. #define EXTERNAL_CLOCK_VALUE     12288000U
    99. #endif /* EXTERNAL_CLOCK_VALUE */

    100. /* System Configuration */
    101. #define VDD_VALUE                   3300U /*!< Value of VDD in mv */
    102. #define TICK_INT_PRIORITY           0x0FU /*!< tick interrupt priority */
    103. #define USE_RTOS                     0U
    104. #define PREFETCH_ENABLE             1U
    105. #define INSTRUCTION_CACHE_ENABLE     1U
    106. #define DATA_CACHE_ENABLE           1U

    107. /* DAL peripheral register callbacks */
    108. #define USE_DAL_ADC_REGISTER_CALLBACKS         0U /* ADC register callback disabled       */
    109. #define USE_DAL_CAN_REGISTER_CALLBACKS         0U /* CAN register callback disabled       */
    110. #define USE_DAL_CRYP_REGISTER_CALLBACKS       0U /* CRYP register callback disabled     */
    111. #define USE_DAL_DAC_REGISTER_CALLBACKS         0U /* DAC register callback disabled       */
    112. #define USE_DAL_DCI_REGISTER_CALLBACKS         0U /* DCI register callback disabled       */
    113. #define USE_DAL_ETH_REGISTER_CALLBACKS         0U /* ETH register callback disabled       */
    114. #define USE_DAL_HASH_REGISTER_CALLBACKS       0U /* HASH register callback disabled     */
    115. #define USE_DAL_HCD_REGISTER_CALLBACKS         0U /* HCD register callback disabled       */
    116. #define USE_DAL_I2C_REGISTER_CALLBACKS         0U /* I2C register callback disabled       */
    117. #define USE_DAL_I2S_REGISTER_CALLBACKS         0U /* I2S register callback disabled       */
    118. #define USE_DAL_IRDA_REGISTER_CALLBACKS       0U /* IRDA register callback disabled     */
    119. #define USE_DAL_MMC_REGISTER_CALLBACKS         0U /* MMC register callback disabled       */
    120. #define USE_DAL_NAND_REGISTER_CALLBACKS       0U /* NAND register callback disabled     */
    121. #define USE_DAL_NOR_REGISTER_CALLBACKS         0U /* NOR register callback disabled       */
    122. #define USE_DAL_PCCARD_REGISTER_CALLBACKS     0U /* PCCARD register callback disabled   */
    123. #define USE_DAL_PCD_REGISTER_CALLBACKS         0U /* PCD register callback disabled       */
    124. #define USE_DAL_RNG_REGISTER_CALLBACKS         0U /* RNG register callback disabled       */
    125. #define USE_DAL_RTC_REGISTER_CALLBACKS         0U /* RTC register callback disabled       */
    126. #define USE_DAL_SD_REGISTER_CALLBACKS         0U /* SD register callback disabled       */
    127. #define USE_DAL_SMARTCARD_REGISTER_CALLBACKS   0U /* SMARTCARD register callback disabled */
    128. #define USE_DAL_SDRAM_REGISTER_CALLBACKS       0U /* SDRAM register callback disabled     */
    129. #define USE_DAL_SRAM_REGISTER_CALLBACKS       0U /* SRAM register callback disabled     */
    130. #define USE_DAL_SMBUS_REGISTER_CALLBACKS       0U /* SMBUS register callback disabled     */
    131. #define USE_DAL_SPI_REGISTER_CALLBACKS         0U /* SPI register callback disabled       */
    132. #define USE_DAL_TMR_REGISTER_CALLBACKS         0U /* TMR register callback disabled       */
    133. #define USE_DAL_UART_REGISTER_CALLBACKS       0U /* UART register callback disabled     */
    134. #define USE_DAL_USART_REGISTER_CALLBACKS       0U /* USART register callback disabled     */
    135. #define USE_DAL_WWDT_REGISTER_CALLBACKS       0U /* WWDT register callback disabled     */

    136. /* Ethernet peripheral configuration */
    137. /* Addr and buffer size */

    138. /* MAC ADDRESS */
    139. #define ETH_MAC_ADDR_0   2U
    140. #define ETH_MAC_ADDR_1   0U
    141. #define ETH_MAC_ADDR_2   0U
    142. #define ETH_MAC_ADDR_3   0U
    143. #define ETH_MAC_ADDR_4   0U
    144. #define ETH_MAC_ADDR_5   0U

    145. /* Ethernet driver buffers size and number */
    146. #define ETH_BUFFER_SIZE_RX             ETH_MAX_PACKET_SIZE /* Buffer size for receive               */
    147. #define ETH_BUFFER_SIZE_TX             ETH_MAX_PACKET_SIZE /* Buffer size for transmit             */
    148. #define ETH_BUFFER_NUMBER_RX           4U                  /* 4 Rx buffers of size ETH_BUFFER_SIZE_RX */
    149. #define ETH_BUFFER_NUMBER_TX           4U                  /* 4 Tx buffers of size ETH_BUFFER_SIZE_TX */

    150. /* Delay and timeout */

    151. /* PHY Reset MAX Delay */
    152. #define EXT_PHY_RESET_MAX_DELAY         0x000000FFU
    153. /* PHY Configuration MAX Delay */
    154. #define EXT_PHY_CONFIG_MAX_DELAY       0x00000FFFU

    155. #define EXT_PHY_READ_TIMEOUT           0x0000FFFFU
    156. #define EXT_PHY_WRITE_TIMEOUT           0x0000FFFFU

    157. /* SPI peripheral configuration */

    158. /* SPI CRC FEATURE */
    159. #define USE_SPI_CRC                     1U

    160. /* Include module's header file */
    161. #ifdef DAL_RCM_MODULE_ENABLED
    162. #include "apm32f4xx_dal_rcm.h"
    163. #endif /* DAL_RCM_MODULE_ENABLED */

    164. #ifdef DAL_GPIO_MODULE_ENABLED
    165. #include "apm32f4xx_dal_gpio.h"
    166. #endif /* DAL_GPIO_MODULE_ENABLED */

    167. #ifdef DAL_EINT_MODULE_ENABLED
    168. #include "apm32f4xx_dal_eint.h"
    169. #endif /* DAL_EINT_MODULE_ENABLED */

    170. #ifdef DAL_DMA_MODULE_ENABLED
    171. #include "apm32f4xx_dal_dma.h"
    172. #endif /* DAL_DMA_MODULE_ENABLED */

    173. #ifdef DAL_CORTEX_MODULE_ENABLED
    174. #include "apm32f4xx_dal_cortex.h"
    175. #endif /* DAL_CORTEX_MODULE_ENABLED */

    176. #ifdef DAL_ADC_MODULE_ENABLED
    177. #include "apm32f4xx_dal_adc.h"
    178. #endif /* DAL_ADC_MODULE_ENABLED */

    179. #ifdef DAL_CAN_MODULE_ENABLED
    180. #include "apm32f4xx_dal_can.h"
    181. #endif /* DAL_CAN_MODULE_ENABLED */

    182. #ifdef DAL_CRC_MODULE_ENABLED
    183. #include "apm32f4xx_dal_crc.h"
    184. #endif /* DAL_CRC_MODULE_ENABLED */

    185. #ifdef DAL_CRYP_MODULE_ENABLED
    186. #include "apm32f4xx_dal_cryp.h"
    187. #endif /* DAL_CRYP_MODULE_ENABLED */

    188. #ifdef DAL_DAC_MODULE_ENABLED
    189. #include "apm32f4xx_dal_dac.h"
    190. #endif /* DAL_DAC_MODULE_ENABLED */

    191. #ifdef DAL_DCI_MODULE_ENABLED
    192. #include "apm32f4xx_dal_dci.h"
    193. #endif /* DAL_DCI_MODULE_ENABLED */

    194. #ifdef DAL_ETH_MODULE_ENABLED
    195. #include "apm32f4xx_dal_eth.h"
    196. #endif /* DAL_ETH_MODULE_ENABLED */

    197. #ifdef DAL_FLASH_MODULE_ENABLED
    198. #include "apm32f4xx_dal_flash.h"
    199. #endif /* DAL_FLASH_MODULE_ENABLED */

    200. #ifdef DAL_HASH_MODULE_ENABLED
    201. #include "apm32f4xx_dal_hash.h"
    202. #endif /* DAL_HASH_MODULE_ENABLED */

    203. #ifdef DAL_HCD_MODULE_ENABLED
    204. #include "apm32f4xx_dal_hcd.h"
    205. #endif /* DAL_HCD_MODULE_ENABLED */

    206. #ifdef DAL_I2C_MODULE_ENABLED
    207. #include "apm32f4xx_dal_i2c.h"
    208. #endif /* DAL_I2C_MODULE_ENABLED */

    209. #ifdef DAL_I2S_MODULE_ENABLED
    210. #include "apm32f4xx_dal_i2s.h"
    211. #endif /* DAL_I2S_MODULE_ENABLED */

    212. #ifdef DAL_IRDA_MODULE_ENABLED
    213. #include "apm32f4xx_dal_irda.h"
    214. #endif /* DAL_IRDA_MODULE_ENABLED */

    215. #ifdef DAL_MMC_MODULE_ENABLED
    216. #include "apm32f4xx_dal_mmc.h"
    217. #endif /* DAL_MMC_MODULE_ENABLED */

    218. #ifdef DAL_NAND_MODULE_ENABLED
    219. #include "apm32f4xx_dal_nand.h"
    220. #endif /* DAL_NAND_MODULE_ENABLED */

    221. #ifdef DAL_NOR_MODULE_ENABLED
    222. #include "apm32f4xx_dal_nor.h"
    223. #endif /* DAL_NOR_MODULE_ENABLED */

    224. #ifdef DAL_PCCARD_MODULE_ENABLED
    225. #include "apm32f4xx_dal_pccard.h"
    226. #endif /* DAL_PCCARD_MODULE_ENABLED */

    227. #ifdef DAL_PCD_MODULE_ENABLED
    228. #include "apm32f4xx_dal_pcd.h"
    229. #endif /* DAL_PCD_MODULE_ENABLED */

    230. #ifdef DAL_PMU_MODULE_ENABLED
    231. #include "apm32f4xx_dal_pmu.h"
    232. #endif /* DAL_PMU_MODULE_ENABLED */

    233. #ifdef DAL_RNG_MODULE_ENABLED
    234. #include "apm32f4xx_dal_rng.h"
    235. #endif /* DAL_RNG_MODULE_ENABLED */

    236. #ifdef DAL_RTC_MODULE_ENABLED
    237. #include "apm32f4xx_dal_rtc.h"
    238. #endif /* DAL_RTC_MODULE_ENABLED */

    239. #ifdef DAL_SRAM_MODULE_ENABLED
    240. #include "apm32f4xx_dal_sram.h"
    241. #endif /* DAL_SRAM_MODULE_ENABLED */

    242. #ifdef DAL_SDRAM_MODULE_ENABLED
    243. #include "apm32f4xx_dal_sdram.h"
    244. #endif /* DAL_SDRAM_MODULE_ENABLED */

    245. #ifdef DAL_SMBUS_MODULE_ENABLED
    246. #include "apm32f4xx_dal_smbus.h"
    247. #endif /* DAL_SMBUS_MODULE_ENABLED */

    248. #ifdef DAL_SD_MODULE_ENABLED
    249. #include "apm32f4xx_dal_sd.h"
    250. #endif /* DAL_SD_MODULE_ENABLED */

    251. #ifdef DAL_SPI_MODULE_ENABLED
    252. #include "apm32f4xx_dal_spi.h"
    253. #endif /* DAL_SPI_MODULE_ENABLED */

    254. #ifdef DAL_SMARTCARD_MODULE_ENABLED
    255. #include "apm32f4xx_dal_smartcard.h"
    256. #endif /* DAL_SMARTCARD_MODULE_ENABLED */

    257. #ifdef DAL_TMR_MODULE_ENABLED
    258. #include "apm32f4xx_dal_tmr.h"
    259. #endif /* DAL_TMR_MODULE_ENABLED */

    260. #ifdef DAL_UART_MODULE_ENABLED
    261. #include "apm32f4xx_dal_uart.h"
    262. #endif /* DAL_UART_MODULE_ENABLED */

    263. #ifdef DAL_USART_MODULE_ENABLED
    264. #include "apm32f4xx_dal_usart.h"
    265. #endif /* DAL_USART_MODULE_ENABLED */

    266. #ifdef DAL_IWDT_MODULE_ENABLED
    267. #include "apm32f4xx_dal_iwdt.h"
    268. #endif /* DAL_IWDT_MODULE_ENABLED */

    269. #ifdef DAL_WWDT_MODULE_ENABLED
    270. #include "apm32f4xx_dal_wwdt.h"
    271. #endif /* DAL_WWDT_MODULE_ENABLED */

    272. /* Assert Component */
    273. #if (USE_FULL_ASSERT == 1U)
    274.    #define ASSERT_PARAM(_PARAM_)                         ((_PARAM_) ? (void)0U : AssertFailedHandler((uint8_t *)__FILE__, __LINE__))
    275.    /* Declaration */
    276.    void AssertFailedHandler(uint8_t *file, uint32_t line);
    277. #else
    278.    #define ASSERT_PARAM(_PARAM_)                         ((void)0U)
    279. #endif /* USE_FULL_ASSERT */

    280. void DAL_ErrorHandler(void);

    281. #ifdef __cplusplus
    282. }
    283. #endif

    284. #endif /* APM32F4xx_DAL_CFG_H */

    上面的配置过程中,由于后面我们要开启log功能,我们需要打开 USE_LOG_COMPONENT  和 DAL_UART_MODULE_ENABLED
    1. /* Configuration settings for log component */
    2. #define USE_LOG_COMPONENT   1U
    3. /* Include log header file */
    4. #include "apm32f4xx_dal_log.h"

  • 添加串口驱动
    由于在GPIO端口工程中,没有配置UART,因此需要进行配置
    添加apm32f4xx_usart_cfg.c apm32f4xx_usart_cfg.h 对串口进行端口,波特率等配置
    1. /* Includes ***************************************************************/
    2. #include "apm32f4xx_usart_cfg.h"

    3. /* Private includes *******************************************************/
    4. #include <stdio.h>

    5. /* Private macro **********************************************************/

    6. /* Private typedef ********************************************************/

    7. /* Private variables ******************************************************/
    8. UART_HandleTypeDef huart1;

    9. /* Private function prototypes ********************************************/

    10. /* External variables *****************************************************/

    11. /* External functions *****************************************************/

    12. /**
    13. * [url=home.php?mod=space&uid=247401]@brief[/url]   USART1 configuration
    14. *
    15. * @param   None
    16. *
    17. * @retval None
    18. */
    19. void DAL_USART1_Config(void)
    20. {
    21.    huart1.Instance             = USART1;
    22.    huart1.Init.BaudRate        = 115200U;
    23.    huart1.Init.WordLength      = UART_WORDLENGTH_8B;
    24.    huart1.Init.StopBits        = UART_STOPBITS_1;
    25.    huart1.Init.Parity          = UART_PARITY_NONE;
    26.    huart1.Init.Mode            = UART_MODE_TX_RX;
    27.    huart1.Init.HwFlowCtl       = UART_HWCONTROL_NONE;
    28.    huart1.Init.OverSampling    = UART_OVERSAMPLING_16;
    29.    if (DAL_UART_Init(&huart1) != DAL_OK)
    30.   {
    31.        DAL_ErrorHandler();
    32.   }
    33. }

    34. /**
    35. * @brief   UART MSP Init
    36. *
    37. * @param   huart Pointer to a UART_HandleTypeDef structure that contains
    38. *               the configuration information for the specified UART module
    39. *
    40. * @retval None
    41. */
    42. void DAL_UART_MspInit(UART_HandleTypeDef *huart)
    43. {
    44.    GPIO_InitTypeDef GPIO_InitStruct = {0};

    45.    if (huart->Instance == USART1)
    46.   {
    47.        /* Enable USART1 GPIO clock */
    48.        __DAL_RCM_GPIOA_CLK_ENABLE();
    49.       
    50.        /* Enable USART1 clock */
    51.        __DAL_RCM_USART1_CLK_ENABLE();

    52.        /* Configure the UART TX and RX pin */
    53.        GPIO_InitStruct.Pin         = GPIO_PIN_9 | GPIO_PIN_10;
    54.        GPIO_InitStruct.Mode        = GPIO_MODE_AF_PP;
    55.        GPIO_InitStruct.Pull        = GPIO_NOPULL;
    56.        GPIO_InitStruct.Speed       = GPIO_SPEED_FAST;
    57.        GPIO_InitStruct.Alternate   = GPIO_AF7_USART1;

    58.        DAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
    59.   }
    60. }

    61. /**
    62. * @brief UART MSP DeInit
    63. *
    64. * @param huart Pointer to a UART_HandleTypeDef structure that contains
    65. *               the configuration information for the specified UART module
    66. *
    67. * @retval None
    68. */
    69. void DAL_UART_MspDeInit(UART_HandleTypeDef *huart)
    70. {
    71.    if (huart->Instance == USART1)
    72.   {
    73.        /* Reset USART */
    74.        __DAL_RCM_USART1_FORCE_RESET();
    75.        __DAL_RCM_USART1_RELEASE_RESET();
    76.       
    77.        /* Disable USART and GPIO clocks */
    78.        DAL_GPIO_DeInit(GPIOA, GPIO_PIN_9 | GPIO_PIN_10);

    79.        /* Disable USART interrupt */
    80.        DAL_NVIC_DisableIRQ(USART1_IRQn);
    81.   }
    82. }

    83. #if defined (__CC_ARM) || defined (__ICCARM__) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))

    84. /*!
    85. * @brief       Redirect C Library function printf to serial port.
    86. *             After Redirection, you can use printf function.
    87. *
    88. * @param       ch: The characters that need to be send.
    89. *
    90. * @param       *f: pointer to a FILE that can recording all information
    91. *             needed to control a stream
    92. *
    93. * @retval     The characters that need to be send.
    94. *
    95. * @note
    96. */
    97. int fputc(int ch, FILE* f)
    98. {
    99.    /* send a byte of data to the serial port */
    100.    DAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1U, 1000U);

    101.    return (ch);
    102. }

    103. #elif defined (__GNUC__)

    104. /*!
    105. * @brief       Redirect C Library function printf to serial port.
    106. *             After Redirection, you can use printf function.
    107. *
    108. * @param       ch: The characters that need to be send.
    109. *
    110. * @retval     The characters that need to be send.
    111. *
    112. * @note
    113. */
    114. int __io_putchar(int ch)
    115. {
    116.    /* send a byte of data to the serial port */
    117.    DAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1U, 1000U);

    118.    return ch;
    119. }

    120. /*!
    121. * @brief       Redirect C Library function printf to serial port.
    122. *             After Redirection, you can use printf function.
    123. *
    124. * @param       file: Meaningless in this function.
    125. *
    126. * @param       *ptr: Buffer pointer for data to be sent.
    127. *
    128. * @param       len: Length of data to be sent.
    129. *
    130. * @retval     The characters that need to be send.
    131. *
    132. * @note
    133. */
    134. int _write(int file, char* ptr, int len)
    135. {
    136.    int i;
    137.    for (i = 0; i < len; i++)
    138.   {
    139.        __io_putchar(*ptr++);
    140.   }

    141.    return len;
    142. }

    143. #else
    144. #warning Not supported compiler type
    145. #endif

  • 下载程序
    主程序代码
    1. /* Includes ***************************************************************/
    2. #include "main.h"
    3. /* Private includes *******************************************************/
    4. #include "apm32f4xx_device_cfg.h"

    5. static const char* tag = "main";//log组件

    6. /**
    7. * @brief   Main program
    8. */
    9. int main(void)
    10. {
    11.     /* Device configuration */
    12.     DAL_DeviceConfig();
    13.           DAL_LOGE(tag, "Hardware_Init [ok] \r\n");
    14.                 DAL_LOGE(tag, "apm32f411tiny board testing 2024-05-30\n");
    15.           DAL_LOGE(tag, "apm32f411tiny-board APM32F4xx_DAL_Driver\n");
    16.     /* Infinite loop */
    17.     while (1)
    18.     {
    19.         DAL_GPIO_TogglePin(GPIOE, GPIO_PIN_6);
    20.         DAL_Delay(500U);
    21.                           DAL_LOGE(tag, "DAL_GPIO_TogglePin Testing\r\n");
    22.     }
    23. }

    采用APM32F411-Tiny Board自带的Geehy Link进行下载。 apm32-led-15-1.jpg 成功点亮。 apm32-led-16.jpg

在apm32f4xx_device_cfg.c中开启log打印组件,调试调试
hal-19.jpg


hal-18.jpg
星辰大海不退缩 发表于 2024-6-22 21:08 | 显示全部楼层
LED灯确实很亮,有时不太好分辨
您需要登录后才可以回帖 登录 | 注册

本版积分规则

20

主题

80

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部

20

主题

80

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部