[STM32F4] 【STM32F469I试用】+ 外围接口测试---GPIO 和 USART

[复制链接]
2399|7
 楼主| songchenping 发表于 2015-12-30 15:49 | 显示全部楼层 |阅读模式
第五篇  外围接口测试----GPIO USART
第四篇简单介绍了开发环境IDE的安装以及项目工程建立。用户可以非常方便的进行自己的软件开发。
由于测试串口是从扩展接口引出,且电平为TTL电平。因此我打算使用USB-TTL线缆,FTDI公司产品:TTL-232R-3V3
线缆实物图如下:
1.JPG
GPIO 测试,我打算针对4个用户指示LED灯来做测试,低电平点亮LED灯,高电平熄灭。
4.JPG

串口连接图:
2.JPG


利用扩展接口上的USART6进行串口测试,发送OK字符。检验串口功能。
串口接收图:
3.JPG
功能比较简单,相信大部分用户都可以理解和应用。
  








捉虫天师 发表于 2015-12-30 20:49 | 显示全部楼层
据我说只Discovery系列都有虚拟串口啊,怎么还单独搞了个串口线。
dongnanxibei 发表于 2015-12-30 22:06 | 显示全部楼层
  1. /**
  2.   ******************************************************************************
  3.   * [url=home.php?mod=space&uid=288409]@file[/url]    GPIO/GPIO_EXTI/Src/main.c
  4.   * [url=home.php?mod=space&uid=187600]@author[/url]  MCD Application Team
  5.   * [url=home.php?mod=space&uid=895143]@version[/url] V1.0.0
  6.   * [url=home.php?mod=space&uid=212281]@date[/url]    14-August-2015
  7.   * [url=home.php?mod=space&uid=247401]@brief[/url]   This example describes how to configure and use GPIOs through
  8.   *          the STM32F4xx HAL API.
  9.   ******************************************************************************
  10.   * @attention
  11.   *
  12.   * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  13.   *
  14.   * Redistribution and use in source and binary forms, with or without modification,
  15.   * are permitted provided that the following conditions are met:
  16.   *   1. Redistributions of source code must retain the above copyright notice,
  17.   *      this list of conditions and the following disclaimer.
  18.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  19.   *      this list of conditions and the following disclaimer in the documentation
  20.   *      and/or other materials provided with the distribution.
  21.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  22.   *      may be used to endorse or promote products derived from this software
  23.   *      without specific prior written permission.
  24.   *
  25.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  29.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35.   *
  36.   ******************************************************************************
  37.   */

  38. /* Includes ------------------------------------------------------------------*/
  39. #include "main.h"

  40. /** @addtogroup STM32F4xx_HAL_Examples
  41.   * @{
  42.   */

  43. /** @addtogroup GPIO_EXTI
  44.   * @{
  45.   */

  46. /* Private typedef -----------------------------------------------------------*/
  47. /* Private define ------------------------------------------------------------*/
  48. /* Private macro -------------------------------------------------------------*/
  49. /* Private variables ---------------------------------------------------------*/
  50. /* Private function prototypes -----------------------------------------------*/
  51. static void SystemClock_Config(void);
  52. static void EXTI0_IRQHandler_Config(void);
  53. /* Private functions ---------------------------------------------------------*/

  54. /**
  55.   * @brief  Main program
  56.   * @param  None
  57.   * @retval None
  58.   */
  59. int main(void)
  60. {
  61.   /* STM32F4xx HAL library initialization:
  62.        - Configure the Flash prefetch, instruction and Data caches
  63.        - Systick timer is configured by default as source of time base, but user
  64.          can eventually implement his proper time base source (a general purpose
  65.          timer for example or other time source), keeping in mind that Time base
  66.          duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
  67.          handled in milliseconds basis.
  68.        - Set NVIC Group Priority to 4
  69.        - Low Level Initialization: global MSP (MCU Support Package) initialization
  70.      */
  71.   HAL_Init();

  72.   /* Configure the system clock to 180 MHz */
  73.   SystemClock_Config();

  74.   /* -1- Initialize LEDs mounted on STM32469I-DISCOVERY board */
  75.   BSP_LED_Init(LED1);

  76.   /* -2- Configure EXTI0 (connected to PA.00 pin) in interrupt mode */
  77.   EXTI0_IRQHandler_Config();

  78.   /* Infinite loop */
  79.   while (1)
  80.   {
  81.   }
  82. }

  83. /**
  84.   * @brief  System Clock Configuration
  85.   *         The system Clock is configured as follow :
  86.   *            System Clock source            = PLL (HSE)
  87.   *            SYSCLK(Hz)                     = 180000000
  88.   *            HCLK(Hz)                       = 180000000
  89.   *            AHB Prescaler                  = 1
  90.   *            APB1 Prescaler                 = 4
  91.   *            APB2 Prescaler                 = 2
  92.   *            HSE Frequency(Hz)              = 8000000
  93.   *            PLL_M                          = 8
  94.   *            PLL_N                          = 360
  95.   *            PLL_P                          = 2
  96.   *            PLL_Q                          = 7
  97.   *            PLL_R                          = 6
  98.   *            VDD(V)                         = 3.3
  99.   *            Main regulator output voltage  = Scale1 mode
  100.   *            Flash Latency(WS)              = 5
  101.   * @param  None
  102.   * @retval None
  103.   */
  104. static void SystemClock_Config(void)
  105. {
  106.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  107.   RCC_OscInitTypeDef RCC_OscInitStruct;
  108.   HAL_StatusTypeDef ret = HAL_OK;

  109.   /* Enable Power Control clock */
  110.   __HAL_RCC_PWR_CLK_ENABLE();

  111.   /* The voltage scaling allows optimizing the power consumption when the device is
  112.      clocked below the maximum system frequency, to update the voltage scaling value
  113.      regarding system frequency refer to product datasheet.  */
  114.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  115.   /* Enable HSE Oscillator and activate PLL with HSE as source */
  116.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  117.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  118.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  119.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  120. #if defined(USE_STM32469I_DISCO_REVA)
  121.   RCC_OscInitStruct.PLL.PLLM = 25;
  122. #else
  123.   RCC_OscInitStruct.PLL.PLLM = 8;
  124. #endif /* USE_STM32469I_DISCO_REVA */
  125.   RCC_OscInitStruct.PLL.PLLN = 360;
  126.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  127.   RCC_OscInitStruct.PLL.PLLQ = 7;
  128.   RCC_OscInitStruct.PLL.PLLR = 6;
  129.   
  130.   ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
  131.   if(ret != HAL_OK)
  132.   {
  133.     while(1) { ; }
  134.   }
  135.   
  136.   /* Activate the OverDrive to reach the 180 MHz Frequency */  
  137.   ret = HAL_PWREx_EnableOverDrive();
  138.   if(ret != HAL_OK)
  139.   {
  140.     while(1) { ; }
  141.   }
  142.   
  143.   /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
  144.   RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  145.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  146.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  147.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;  
  148.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;  
  149.   
  150.   ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
  151.   if(ret != HAL_OK)
  152.   {
  153.     while(1) { ; }
  154.   }
  155. }

  156. /**
  157.   * @brief  Configures EXTI line 0 (connected to PA.00 pin) in interrupt mode
  158.   * @param  None
  159.   * @retval None
  160.   */
  161. static void EXTI0_IRQHandler_Config(void)
  162. {
  163.   GPIO_InitTypeDef   GPIO_InitStructure;

  164.   /* Enable GPIOA clock */
  165.   __HAL_RCC_GPIOA_CLK_ENABLE();

  166.   /* Configure PA.00 pin as input floating */
  167.   GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
  168.   GPIO_InitStructure.Pull = GPIO_NOPULL;
  169.   GPIO_InitStructure.Pin = GPIO_PIN_0;
  170.   HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);

  171.   /* Enable and set EXTI line 0 Interrupt to the lowest priority */
  172.   HAL_NVIC_SetPriority(EXTI0_IRQn, 2, 0);
  173.   HAL_NVIC_EnableIRQ(EXTI0_IRQn);
  174. }

  175. /**
  176.   * @brief EXTI line detection callbacks
  177.   * @param GPIO_Pin: Specifies the pins connected EXTI line
  178.   * @retval None
  179.   */
  180. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
  181. {
  182.   if (GPIO_Pin == GPIO_PIN_0)
  183.   {
  184.     /* Toggle LED1 */
  185.     BSP_LED_Toggle(LED1);
  186.   }
  187. }

  188. #ifdef  USE_FULL_ASSERT

  189. /**
  190.   * @brief  Reports the name of the source file and the source line number
  191.   *         where the assert_param error has occurred.
  192.   * @param  file: pointer to the source file name
  193.   * @param  line: assert_param error line source number
  194.   * @retval None
  195.   */
  196. void assert_failed(uint8_t *file, uint32_t line)
  197. {
  198.   /* User can add his own implementation to report the file name and line number,
  199.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  200.   /* Infinite loop */
  201.   while (1)
  202.   {
  203.   }
  204. }
  205. #endif

  206. /**
  207.   * @}
  208.   */

  209. /**
  210.   * @}
  211.   */

  212. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/


dongnanxibei 发表于 2015-12-30 22:07 | 显示全部楼层
看了上面的例程,官方提供的,发现好复杂啊,要配置那么多东西。
 楼主| songchenping 发表于 2015-12-31 07:34 | 显示全部楼层
捉虫天师 发表于 2015-12-30 20:49
据我说只Discovery系列都有虚拟串口啊,怎么还单独搞了个串口线。

主要是想利用扩展接口来进行测试。
 楼主| songchenping 发表于 2015-12-31 07:34 | 显示全部楼层
dongnanxibei 发表于 2015-12-30 22:07
看了上面的例程,官方提供的,发现好复杂啊,要配置那么多东西。

一项一项来。
捉虫天师 发表于 2016-1-11 19:08 | 显示全部楼层
不管用库函数还是寄存器直接操作,这种功能越强大,配置越复杂。学习成本越高。
 楼主| songchenping 发表于 2016-1-12 08:08 | 显示全部楼层
捉虫天师 发表于 2016-1-11 19:08
不管用库函数还是寄存器直接操作,这种功能越强大,配置越复杂。学习成本越高。 ...

确实如此啊。得看好多资料的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:技术合作可以通过以下方式: QQ:745995275 非技术合作恕不回复。

318

主题

12007

帖子

80

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