你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

nucleo 072上手

[复制链接]
netlhx 提问时间:2014-12-20 09:06 /
本帖最后由 netlhx 于 2014-12-20 09:15 编辑

收到STM32NUCLEO F072,感谢沐紫!
简单试用,发现几个要注意的地方,分享一下。


1. 板子上的外部晶振是没有焊接的,所以就不要去配置外部时钟了,配了也是白配。手头虽然也有8M的晶振,只是那几个小电容实在看着汗颜……,只好做罢,老老实实用HSI吧。

2. 使用VCP虚拟串口做串口通讯实验的筒子们注意了,MCU使用的是USART2,所以配置的时候还是选USART2吧,使用其它的UART口得自己连线,呵呵!

3. LSE倒是焊接好了,应该做RTC实验没问题。

4. HAL库比老库更好用了,复用GPIO外设口都不用配置了

也发个DMA发送信息到串口的代码,简单代码,不值一笑



  1. /**
  2.   ******************************************************************************
  3.   * File Name          : main.c
  4.   * Date               : 20/12/2014 08:55:52
  5.   * Description        : Main program body
  6.   ******************************************************************************
  7.   *
  8.   * COPYRIGHT(c) 2014 STMicroelectronics
  9.   *
  10.   * Redistribution and use in source and binary forms, with or without modification,
  11.   * are permitted provided that the following conditions are met:
  12.   *   1. Redistributions of source code must retain the above copyright notice,
  13.   *      this list of conditions and the following disclaimer.
  14.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  15.   *      this list of conditions and the following disclaimer in the documentation
  16.   *      and/or other materials provided with the distribution.
  17.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  18.   *      may be used to endorse or promote products derived from this software
  19.   *      without specific prior written permission.
  20.   *
  21.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  25.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31.   *
  32.   ******************************************************************************
  33.   */

  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f0xx_hal.h"

  36. /* USER CODE BEGIN Includes */
  37. #include "string.h"

  38. /* USER CODE END Includes */

  39. /* Private variables ---------------------------------------------------------*/
  40. UART_HandleTypeDef huart2;
  41. DMA_HandleTypeDef hdma_usart2_tx;

  42. /* USER CODE BEGIN PV */

  43. /* USER CODE END PV */

  44. /* Private function prototypes -----------------------------------------------*/
  45. void SystemClock_Config(void);
  46. static void MX_GPIO_Init(void);
  47. static void MX_DMA_Init(void);
  48. static void MX_USART2_UART_Init(void);

  49. /* USER CODE BEGIN PFP */

  50. /* USER CODE END PFP */

  51. /* USER CODE BEGIN 0 */

  52. /* USER CODE END 0 */

  53. int main(void)
  54. {

  55.   /* USER CODE BEGIN 1 */
  56.         uint8_t msg[] = "Hello, world";
  57.       

  58.   /* USER CODE END 1 */

  59.   /* MCU Configuration----------------------------------------------------------*/

  60.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  61.   HAL_Init();

  62.   /* Configure the system clock */
  63.   SystemClock_Config();

  64.   /* Initialize all configured peripherals */
  65.   MX_GPIO_Init();
  66.   MX_DMA_Init();
  67.   MX_USART2_UART_Init();

  68.   /* USER CODE BEGIN 2 */
  69.         
  70.         //HAL_UART_Transmit(&huart2, msg, sizeof(msg), 5);
  71.         HAL_UART_Transmit_DMA(&huart2, msg, sizeof(msg) - 1);
  72.   /* USER CODE END 2 */

  73.   /* USER CODE BEGIN 3 */
  74.   /* Infinite loop */
  75.   while (1)
  76.   {

  77.   }
  78.   /* USER CODE END 3 */

  79. }

  80. /** System Clock Configuration
  81. */
  82. void SystemClock_Config(void)
  83. {

  84.   RCC_OscInitTypeDef RCC_OscInitStruct;
  85.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  86.   RCC_PeriphCLKInitTypeDef PeriphClkInit;

  87.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  88.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  89.   RCC_OscInitStruct.HSICalibrationValue = 16;
  90.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  91.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  92.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
  93.   RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV2;
  94.   HAL_RCC_OscConfig(&RCC_OscInitStruct);

  95.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
  96.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  97.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  98.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  99.   HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);

  100.   PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
  101.   PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
  102.   HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);

  103.   __SYSCFG_CLK_ENABLE();

  104. }

  105. /* USART2 init function */
  106. void MX_USART2_UART_Init(void)
  107. {

  108.   huart2.Instance = USART2;
  109.   huart2.Init.BaudRate = 38400;
  110.   huart2.Init.WordLength = UART_WORDLENGTH_8B;
  111.   huart2.Init.StopBits = UART_STOPBITS_1;
  112.   huart2.Init.Parity = UART_PARITY_NONE;
  113.   huart2.Init.Mode = UART_MODE_TX_RX;
  114.   huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  115.   huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  116.   huart2.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED ;
  117.   huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  118.   HAL_UART_Init(&huart2);

  119. }

  120. /**
  121.   * Enable DMA controller clock
  122.   */
  123. void MX_DMA_Init(void)
  124. {
  125.   /* DMA controller clock enable */
  126.   __DMA1_CLK_ENABLE();

  127.   /* DMA interrupt init */

  128. }

  129. /** Configure pins as
  130.         * Analog
  131.         * Input
  132.         * Output
  133.         * EVENT_OUT
  134.         * EXTI
  135. */
  136. void MX_GPIO_Init(void)
  137. {

  138.   GPIO_InitTypeDef GPIO_InitStruct;

  139.   /* GPIO Ports Clock Enable */
  140.   __GPIOC_CLK_ENABLE();
  141.   __GPIOA_CLK_ENABLE();

  142.   /*Configure GPIO pin : PC13 */
  143.   GPIO_InitStruct.Pin = GPIO_PIN_13;
  144.   GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  145.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  146.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  147.   /*Configure GPIO pin : PA5 */
  148.   GPIO_InitStruct.Pin = GPIO_PIN_5;
  149.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  150.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  151.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  152.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  153. }

  154. /* USER CODE BEGIN 4 */

  155. /* USER CODE END 4 */

  156. #ifdef USE_FULL_ASSERT

  157. /**
  158.    * @brief Reports the name of the source file and the source line number
  159.    * where the assert_param error has occurred.
  160.    * @param file: pointer to the source file name
  161.    * @param line: assert_param error line source number
  162.    * @retval None
  163.    */
  164. void assert_failed(uint8_t* file, uint32_t line)
  165. {
  166.   /* USER CODE BEGIN 6 */
  167.   /* User can add his own implementation to report the file name and line number,
  168.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  169.   /* USER CODE END 6 */

  170. }

  171. #endif

  172. /**
  173.   * @}
  174.   */

  175. /**
  176.   * @}
  177. */

  178. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码

CUBEMX写代码如此简单

下面是终端结果
hterm.png



收藏 1 评论6 发布时间:2014-12-20 09:06

举报

6个回答
沐紫 回答时间:2014-12-22 09:25:24
谢谢
巅峰残狼 回答时间:2014-12-22 09:43:53
相当不错,谢谢分享
foxglove 回答时间:2015-2-11 17:08:55
嗯,啊可能可能
zhangdaijin 回答时间:2015-5-2 20:03:13
不错不错!
hooke 回答时间:2015-5-3 13:40:47
趁着劳动节学学板子
党国特派员 回答时间:2015-5-3 21:47:03
楼主多分享点。。。 nothing.png nothing.png nothing.png nothing.png nothing.png nothing.png nothing.png nothing.png nothing.png nothing.png

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版