历史上的今天
今天是:2025年04月23日(星期三)
2018年04月23日 | ARM CMSIS Driver 学习 之 USART
2018-04-23 来源:eefocus
最近把 MDK 升级到了 V5.25 ,发现 Managing Run-Time Environment 中已经有好多好多的库。相比之前已经好了太多太多,从底层驱动,到上层协议栈,常用的有不常用的也有。发现 ARM 对这套系统的更新速度加快了一些,觉得有必要学习一下。从驱动开始学起,先学 USART API 详细介绍见 CMSIS Driver USART API
USART 把收到的数据再发出去程序
/**
******************************************************************************
* @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();
}
}
史海拾趣
|
Ü 外挂2M~32M的Flash,时间从32—1054秒。掩膜为内置ROM,最长支持400秒(@6K采样)。采样率支持6K~22K Ü DAC输出:13Bit,PWM输出:12Bit Ü 内置0.5W功放,可直接推动0.5W/8Ω扬声器 Ü 支持加载MP3/WAV/WMA三种音频 ...… 查看全部问答> |
|
每次重启电源后开机,cpu、显卡风扇转一下就停了,主板无法上电,主板上的LED灯不亮,再按开机键就没有任何反应了,只能再次重启电源才能复现上述情况。 请问这是怎么回事啊?电源供电不足?还是主板烧了(为什么每次重启电源后风扇都能转一下呢) ...… 查看全部问答> |
|
功能一、 检测充电器的插拔 【我的想法:】可以用中断来做,这个好做 功能二、检测电池的电量: 只能用AD,将电压转成数字信号了, 就不知道怎么实 ...… 查看全部问答> |
|
我在制作启动盘时如果选择bootrom_uncmp image则使用mkboot a: bootrom_uncmp指令时,弹出如下的对话框 D:\\Tornado2.2\\target\\config\\PCPENT~4>mkboot a: bootrom_uncmp VxSys 1.6 (c) Wind River 1993-2002 Boot sector installed OK. obj ...… 查看全部问答> |
|
我用的是2410+wince4.2,flash用的是K9F1208UOM.在wince系统运行时,我能够看到ResidentFlash文件夹,而且好像用属性查看剩于空间也就是出去os镜像的大小.但是好像因为没有指定flash剩于空间的起始位置的原因吧,只要拷东西进这个文件夹,下次wince就别 ...… 查看全部问答> |
|
这款地铁应急灯是为应付地铁突发状况准备的。当地铁突然停运,电源切断的时候,乘客们可以将把手取下,充当应急电筒使用。通过挤按把手上的按钮,就能够轻松将把手与带子分离。当然,只有在地铁熄灯之后才能启动这一按钮。 &n ...… 查看全部问答> |
|
在VHDL中,类属参数可以在不同层次的模块间传递。可以在顶层修改这些参数,下面各层随之改变。 verilog中怎么实现这一功能? 谢谢!… 查看全部问答> |
|
自《电源开关设计秘笈30例》推出以来,得到广大工程师的热烈反响, 已推出的由德仪资深工程师William P. (Bill) Klein 主笔的《信号链基础知识合辑》反响也非常好, 应大家的强烈要求,现隆重推出《信号链基础知识合辑2》   ...… 查看全部问答> |




