日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 單片機 > 單片機
[導(dǎo)讀] 最近把 MDK 升級到了 V5.25 ,發(fā)現(xiàn) Managing Run-Time Environment 中已經(jīng)有好多好多的庫。相比之前已經(jīng)好了太多太多,從底層驅(qū)動,到上層協(xié)議棧,常用的有不常用的也有。發(fā)現(xiàn) ARM 對這套系統(tǒng)的更新速度

最近把 MDK 升級到了 V5.25 ,發(fā)現(xiàn) Managing Run-Time Environment 中已經(jīng)有好多好多的庫。相比之前已經(jīng)好了太多太多,從底層驅(qū)動,到上層協(xié)議棧,常用的有不常用的也有。發(fā)現(xiàn) ARM 對這套系統(tǒng)的更新速度加快了一些,覺得有必要學(xué)習(xí)一下。從驅(qū)動開始學(xué)起,先學(xué) USART API 詳細介紹見CMSIS Driver USART API

USART 把收到的數(shù)據(jù)再發(fā)出去程序

/**

******************************************************************************

* @file main.c

* @author XinLi

* @version v1.0

* @date 20-March-2018

* @brief Main program body.

******************************************************************************

* @attention

*

*

Copyright © 2018 XinLi

*

* This program is free software: you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program. If not, see .

*

******************************************************************************

*/

/* Header includes -----------------------------------------------------------*/

#include "stm32f4xx.h"

#include "Driver_USART.h"

#include

/* Macro definitions ---------------------------------------------------------*/

/* Type definitions ----------------------------------------------------------*/

/* Variable declarations -----------------------------------------------------*/

extern ARM_DRIVER_USART Driver_USART1;

/* Variable definitions ------------------------------------------------------*/

static uint8_t rxBuffer[1024] = {0};

static uint8_t txBuffer[1024] = {0};

/* Function declarations -----------------------------------------------------*/

static void USART1_Callback(uint32_t event);

static void SystemClock_Config(void);

/* Function definitions ------------------------------------------------------*/

/**

* @brief Main program.

* @param None.

* @return None.

*/

int main(void)

{

/* STM32F4xx HAL library initialization:

- Configure the Flash prefetch, instruction and Data caches

- Configure the Systick to generate an interrupt each 1 msec

- Set NVIC Group Priority to 4

- Global MSP (MCU Support Package) initialization

*/

HAL_Init();

/* Configure the system clock to 168 MHz */

SystemClock_Config();

Driver_USART1.Initialize(USART1_Callback);

Driver_USART1.PowerControl(ARM_POWER_FULL);

Driver_USART1.Control(ARM_USART_MODE_ASYNCHRONOUS |

ARM_USART_DATA_BITS_8 |

ARM_USART_PARITY_NONE |

ARM_USART_STOP_BITS_1 |

ARM_USART_FLOW_CONTROL_NONE, 115200);

Driver_USART1.Control(ARM_USART_CONTROL_TX, 1);

Driver_USART1.Control(ARM_USART_CONTROL_RX, 1);

Driver_USART1.Receive(rxBuffer, sizeof(rxBuffer));

for(;;)

{

}

}

/**

* @brief USART1 callback function.

* @param event: USART events notification mask.

* @return None.

*/

static void USART1_Callback(uint32_t event)

{

if(event & ARM_USART_EVENT_RX_TIMEOUT)

{

Driver_USART1.Control(ARM_USART_ABORT_RECEIVE, 1);

uint32_t length = Driver_USART1.GetRxCount();

memcpy(txBuffer, rxBuffer, length);

Driver_USART1.Send(txBuffer, length);

Driver_USART1.Receive(rxBuffer, sizeof(rxBuffer));

}

}

/**

* @brief System Clock Configuration

* The system Clock is configured as follow :

* System Clock source = PLL (HSE)

* SYSCLK(Hz) = 168000000

* HCLK(Hz) = 168000000

* AHB Prescaler = 1

* APB1 Prescaler = 4

* APB2 Prescaler = 2

* HSE Frequency(Hz) = 8000000

* PLL_M = 8

* PLL_N = 336

* PLL_P = 2

* PLL_Q = 7

* VDD(V) = 3.3

* Main regulator output voltage = Scale1 mode

* Flash Latency(WS) = 5

* @param None

* @retval None

*/

static void SystemClock_Config(void)

{

RCC_ClkInitTypeDef RCC_ClkInitStruct;

RCC_OscInitTypeDef RCC_OscInitStruct;

/* Enable Power Control clock */

__HAL_RCC_PWR_CLK_ENABLE();

/* The voltage scaling allows optimizing the power consumption when the device is

clocked below the maximum system frequency, to update the voltage scaling value

regarding system frequency refer to product datasheet. */

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

/* Enable HSE Oscillator and activate PLL with HSE as source */

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

RCC_OscInitStruct.HSEState = RCC_HSE_ON;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

RCC_OscInitStruct.PLL.PLLM = 8;

RCC_OscInitStruct.PLL.PLLN = 336;

RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

RCC_OscInitStruct.PLL.PLLQ = 7;

HAL_RCC_OscConfig(&RCC_OscInitStruct);

/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2

clocks dividers */

RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;

RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);

/* STM32F405x/407x/415x/417x Revision Z devices: prefetch is supported */

if (HAL_GetREVID() == 0x1001)

{

/* Enable the Flash prefetch */

__HAL_FLASH_PREFETCH_BUFFER_ENABLE();

}

}


本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉