12.1 初学者重要提示
学习使用HAL库前,有必要对他们的基本设计框架有所了解,然后深入学习,效果更好。
为了方便调用,HAL库为各种外设基本都配了三套API,查询,中断和DMA。
12.2 HAL库的配置文件
HAL库有一个专门的配置文件叫stm32f4xx_hal_conf.h,这个文件里面有一个很重要的参数,就是HSE_VALUE,大家所设计板子使用的实际晶振大小一定要与这个数值一致。比如V6的外置晶振是8MHz,那么这里就务必配置宏定义为:
#define HSE_VALUE ((uint32_t)8000000)
完整的代码如下:
1. /* ########################## Module Selection ############################## */
2. /**
3. * @brief This is the list of modules to be used in the HAL driver
4. */
5. #define HAL_MODULE_ENABLED
6. #define HAL_ADC_MODULE_ENABLED
7. #define HAL_CAN_MODULE_ENABLED
8. #define HAL_HCD_MODULE_ENABLED
9.
10. /* 省略未写 */
11.
12. /* ########################## HSE/HSI Values adaptation ##################### */
13. /**
14. * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
15. * This value is used by the RCC HAL module to compute the system frequency
16. * (when HSE is used as system clock source, directly or through the PLL).
17. */
18. #if !defined (HSE_VALUE)
19. #define HSE_VALUE (8000000U) /*!< Value of the External oscillator in Hz */
20. #endif /* HSE_VALUE */
21.
22. #if !defined (HSE_STARTUP_TIMEOUT)
23. #define HSE_STARTUP_TIMEOUT (100U) /*!< Time out for HSE start up, in ms */
24. #endif /* HSE_STARTUP_TIMEOUT */
25.
26. /**
27. * @brief Internal High Speed oscillator (HSI) value.
28. * This value is used by the RCC HAL module to compute the system frequency
29. * (when HSI is used as system clock source, directly or through the PLL).
30. */
31. #if !defined (HSI_VALUE)
32. #define HSI_VALUE (16000000U) /*!< Value of the Internal oscillator in Hz*/
33. #endif /* HSI_VALUE */
34.
35. /**
36. * @brief Internal Low Speed oscillator (LSI) value.
37. */
38. #if !defined (LSI_VALUE)
39. #define LSI_VALUE (32000U)
40. #endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
41. The real value may vary depending on the variations
42. in voltage and temperature. */
43. /**
44. * @brief External Low Speed oscillator (LSE) value.
45. */
46. #if !defined (LSE_VALUE)
47. #define LSE_VALUE (32768U) /*!< Value of the External Low Speed oscillator in Hz */
48. #endif /* LSE_VALUE */
49.
50. #if !defined (LSE_STARTUP_TIMEOUT)
51. #define LSE_STARTUP_TIMEOUT (5000U) /*!< Time out for LSE start up, in ms */
52. #endif /* LSE_STARTUP_TIMEOUT */
53.
54. /**
55. * @brief External clock source for I2S peripheral
56. * This value is used by the I2S HAL module to compute the I2S clock source
57. * frequency, this source is inserted directly through I2S_CKIN pad.
58. */
59. #if !defined (EXTERNAL_CLOCK_VALUE)
60. #define EXTERNAL_CLOCK_VALUE (12288000U) /*!< Value of the External oscillator in Hz*/
61. #endif /* EXTERNAL_CLOCK_VALUE */
62.
63. /* Tip: To avoid modifying this file each time you need to use different HSE,
64. === you can define the HSE value in your toolchain compiler preprocessor. */
65.
66. /* ########################### System Configuration ######################### */
67. /**
68. * @brief This is the HAL system configuration section
69. */
70. #define VDD_VALUE (3300U) /*!< Value of VDD in mv */
71. #define TICK_INT_PRIORITY (0x0FU) /*!< tick interrupt priority */
72. #define USE_RTOS 0U
73. #define PREFETCH_ENABLE 1U
74. #define INSTRUCTION_CACHE_ENABLE 1U
75. #define DATA_CACHE_ENABLE 1U
76.
77. #define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */
78. #define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */
79. #define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */
80. /* 省略未写 */
81. #define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */
82. #define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */
83. #define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */
84.
85. /* ########################## Assert Selection ############################## */
86. /**
87. * @brief Uncomment the line below to expanse the "assert_param" macro in the
88. * HAL drivers code
89. */
90. /* #define USE_FULL_ASSERT 1U */
91.
92. /* ################## Ethernet peripheral configuration ##################### */
93.
94. /* Section 1 : Ethernet peripheral configuration */
95.
96. /* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
97. #define MAC_ADDR0 2U
98. #define MAC_ADDR1 0U
99. #define MAC_ADDR2 0U
100. #define MAC_ADDR3 0U
101. #define MAC_ADDR4 0U
102. #define MAC_ADDR5 0U
103.
104. /* Definition of the Ethernet driver buffers size and count */
105. #define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
106. #define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
107. #define ETH_RXBUFNB (4U) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
108. #define ETH_TXBUFNB (4U) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
109.
110. /* Section 2: PHY configuration section */
111.
112. /* DP83848 PHY Address*/
113. #define DP83848_PHY_ADDRESS 0x01U
114. /* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
115. #define PHY_RESET_DELAY (0x000000FFU)
116. /* PHY Configuration delay */
117. #define PHY_CONFIG_DELAY (0x00000FFFU)
118.
119. #define PHY_READ_TO (0x0000FFFFU)
120. #define PHY_WRITE_TO (0x0000FFFFU)
121.
122. /* Section 3: Common PHY Registers */
123.
124. #define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
125. #define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
上一篇:第13章 STM32F429启动过程详解
下一篇:第11章 STM32F429移植SEGGER的硬件异常分析
推荐阅读最新更新时间:2024-11-22 12:24