forked from minixalpha/StrayBirds
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.add 2016-11-17-stm32-usart; 2.add 2016-12-18-java-faceted-project-m…
…etadata-file-could-not-be-read.
- Loading branch information
Showing
2 changed files
with
349 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,333 @@ | ||
--- | ||
layout: post | ||
title: STM32105-USART | ||
comments: true | ||
category: C/C++ | ||
tags: [STM32, 单片机, USART] | ||
--- | ||
|
||
|
||
global.h | ||
|
||
```c | ||
|
||
#ifndef _GLOBAL_H | ||
#define _GLOBAL_H | ||
|
||
#define CFG_PLATFORM_CONSOLE_UARTA | ||
#define BPSTOMS(bps) (1000 / bps) | ||
#define BPSTOUS(bps) (1000000 / bps) | ||
|
||
#define NOP __no_operation | ||
|
||
#include "stdbool.h" | ||
#include "stdint.h" | ||
#include "stdarg.h" | ||
#include "string.h" | ||
#include "stdio.h" | ||
#include "math.h" | ||
#include "stm32f10x.h" | ||
#include "stm32f10x_it.h" | ||
|
||
#define DLC_BUFFER_MAX_LEN (512) | ||
|
||
/** | ||
* 放前面int16_t未定义 | ||
* 放后面usart要用,所以放这里 | ||
*/ | ||
struct DLC_BufferStruDef | ||
{ | ||
int16_t StartPos; //起始位置偏移量 | ||
int16_t EndPos; //结束位置偏移量 | ||
int16_t Length; //有效数据长度,读数据后长度减,写数据后长度加 | ||
uint8_t Buffer[DLC_BUFFER_MAX_LEN]; | ||
}; | ||
|
||
#define STACK_FRAME_BUFFER_MAX_SIZE (1024) | ||
|
||
struct STACK_FRAME_BufferStruDef | ||
{ | ||
int16_t StartPos; //读数据的起始偏移量 | ||
int16_t EndPos; //写入数据的结束偏移量 | ||
int16_t Length; //实际帧长度 | ||
uint8_t Buffer[STACK_FRAME_BUFFER_MAX_SIZE]; //帧缓冲区大小 | ||
}; | ||
|
||
``` | ||
usart.h | ||
```c | ||
/************************************************************ | ||
* @FileName : usart.h | ||
* @Vsersion : V1.0.0 | ||
* @DateTime : 2016-05-21 19:55:02 | ||
* @Description: 串口初始化、收发数据等 | ||
************************************************************/ | ||
#ifndef _USART_H | ||
#define _USART_H | ||
#include "global.h" | ||
#define USART_BAUDRATE_115200 115200 | ||
#define USART_BAUDRATE_19200 19200 | ||
#define USART_BAUDRATE_9600 9600 | ||
void DLC_USART_GPIOInit(USART_TypeDef* USARTx); | ||
void DLC_USART_InitStructure(USART_TypeDef* USARTx, uint32_t BaudRate); | ||
void DLC_USART_Init(USART_TypeDef* USARTx, uint32_t BaudRate); | ||
void DLC_USART_NVICInit(USART_TypeDef* USARTx, uint8_t IRQChannel, uint32_t PriorityGroup, uint8_t IRQChannelPreemptionPriority, uint8_t IRQChannelSubPriority); | ||
void DLC_USART_ReceiveData(USART_TypeDef* USARTx); | ||
void DLC_USART_SendUint8(USART_TypeDef *USARTx, uint8_t Data); | ||
void DLC_USART_SendString(USART_TypeDef* USARTx, const uint8_t *Data); | ||
void DLC_USART_SendData(USART_TypeDef* USARTx, const uint8_t *Data, uint16_t Length); | ||
void USART1_IRQHandler(void); | ||
void USART2_IRQHandler(void); | ||
void USART3_IRQHandler(void); | ||
void UART4_IRQHandler(void); | ||
void UART5_IRQHandler(void); | ||
#endif | ||
``` | ||
|
||
usart.c | ||
|
||
```c | ||
|
||
/************************************************************ | ||
* @FileName : usart.c | ||
* @Vsersion : V1.0.0 | ||
* @DateTime : 2016-05-21 19:55:50 | ||
* @Description: 串口初始化、收发数据等 | ||
************************************************************/ | ||
#include "usart.h" | ||
|
||
struct DLC_BufferStruDef USART1Buffer; | ||
struct DLC_BufferStruDef USART3Buffer; | ||
struct DLC_BufferStruDef USART5Buffer; | ||
|
||
void DLC_USART_GPIOInit(USART_TypeDef* USARTx) | ||
{ | ||
uint32_t RCC_APB1Periph = 0; | ||
uint32_t RCC_APB2Periph = 0; | ||
uint32_t GPIO_Remap = 0; | ||
|
||
RCC_APB2Periph |= RCC_APB2Periph_AFIO; | ||
|
||
if (USARTx == USART1) | ||
{ | ||
RCC_APB2Periph |= RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA; | ||
GPIO_Remap |= GPIO_Remap_USART1; | ||
} | ||
if (USARTx == USART3) | ||
{ | ||
RCC_APB1Periph |= RCC_APB1Periph_USART3; | ||
RCC_APB2Periph |= RCC_APB2Periph_GPIOB; | ||
GPIO_Remap |= GPIO_PartialRemap_USART3; | ||
} | ||
if (USARTx == UART5) | ||
{ | ||
RCC_APB1Periph |= RCC_APB1Periph_UART5; | ||
RCC_APB2Periph |= RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD; | ||
} | ||
|
||
RCC_APB1PeriphClockCmd(RCC_APB1Periph, ENABLE); | ||
|
||
/* config USART clock */ | ||
RCC_APB2PeriphClockCmd(RCC_APB2Periph, ENABLE); | ||
// GPIO_PinRemapConfig(GPIO_Remap, ENABLE); | ||
|
||
GPIO_InitTypeDef GPIO_InitStructure; | ||
|
||
/* Configure USARTx Rx as input floating */ | ||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; | ||
if (USARTx == USART1) | ||
{ | ||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; // PA.10 | ||
GPIO_Init(GPIOA, &GPIO_InitStructure); | ||
} | ||
if (USARTx == USART3) | ||
{ | ||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; // PB.11 | ||
GPIO_Init(GPIOB, &GPIO_InitStructure); | ||
} | ||
if (USARTx == UART5) | ||
{ | ||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // PD.02 | ||
GPIO_Init(GPIOD, &GPIO_InitStructure); | ||
} | ||
|
||
/* Configure USARTx Tx as alternate function push-pull */ | ||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; | ||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | ||
if (USARTx == USART1) | ||
{ | ||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; // PA.09 | ||
GPIO_Init(GPIOA, &GPIO_InitStructure); | ||
} | ||
if (USARTx == USART3) | ||
{ | ||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; // PB.10 | ||
GPIO_Init(GPIOB, &GPIO_InitStructure); | ||
} | ||
if (USARTx == UART5) | ||
{ | ||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; // PC.12 | ||
GPIO_Init(GPIOC, &GPIO_InitStructure); | ||
} | ||
} | ||
|
||
void DLC_USART_InitStructure(USART_TypeDef* USARTx, uint32_t BaudRate) | ||
{ | ||
USART_InitTypeDef USART_InitStructure; | ||
|
||
/* USARTx mode config */ | ||
USART_InitStructure.USART_BaudRate = BaudRate; | ||
USART_InitStructure.USART_WordLength = USART_WordLength_8b; | ||
USART_InitStructure.USART_StopBits = USART_StopBits_1; | ||
USART_InitStructure.USART_Parity = USART_Parity_No; | ||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; | ||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; | ||
USART_Init(USARTx, &USART_InitStructure); | ||
USART_ITConfig(USARTx, USART_IT_RXNE, ENABLE); | ||
USART_Cmd(USARTx, ENABLE); | ||
} | ||
|
||
void DLC_USART_Init(USART_TypeDef* USARTx, uint32_t BaudRate) | ||
{ | ||
DLC_USART_GPIOInit(USARTx); | ||
DLC_USART_InitStructure(USARTx, BaudRate); | ||
if (USARTx == USART1) | ||
{ | ||
DLC_USART_NVICInit(USARTx, USART1_IRQn, NVIC_PriorityGroup_1, 0x01, 0x04); | ||
} | ||
if (USARTx == USART3) | ||
{ | ||
DLC_USART_NVICInit(USARTx, USART3_IRQn, NVIC_PriorityGroup_1, 0x01, 0x04); | ||
} | ||
if (USARTx == UART5) | ||
{ | ||
DLC_USART_NVICInit(USARTx, UART5_IRQn, NVIC_PriorityGroup_1, 0x01, 0x07); | ||
} | ||
} | ||
|
||
/*--------------------------------------------------------------------------------- | ||
【函数说明】: 中断回调注册以及优先级配置 | ||
【函数参数】: USART_TypeDef* USARTx 串口编号 | ||
uint8_t IRQChannel 中断回调注册 | ||
uint32_t PriorityGroup 中断优先级分组,分为四组,第0组可以看做是抢占式优先级为0 | ||
uint8_t IRQChannelPreemptionPriority 抢占式优先级,数值越小优先级越高,并且高于响应优先级 | ||
uint8_t IRQChannelSubPriority 响应优先级,数值越小优先级越高 | ||
【函数返回】: 无 | ||
-----------------------------------------------------------------------------------*/ | ||
void DLC_USART_NVICInit(USART_TypeDef* USARTx, uint8_t IRQChannel, uint32_t PriorityGroup, uint8_t IRQChannelPreemptionPriority, uint8_t IRQChannelSubPriority) | ||
{ | ||
NVIC_InitTypeDef NVIC_InitStructure; | ||
NVIC_PriorityGroupConfig(PriorityGroup); | ||
|
||
/* Enable the USART1 Interrupt */ | ||
NVIC_InitStructure.NVIC_IRQChannel = IRQChannel; | ||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = IRQChannelPreemptionPriority; | ||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = IRQChannelSubPriority; | ||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; | ||
NVIC_Init(&NVIC_InitStructure); | ||
} | ||
|
||
uint16_t RecvValue = 0; //测试接收数据变量 | ||
|
||
/************************************************************* | ||
** 函数名 :DLC_USART_ReceiveData | ||
** 输入 : | ||
** 输出 :无 | ||
** 说明 :这个中断函数内尽量不要打印,因为打印会调 | ||
* 用发送函数,而发送也会产生中断,当前中断 | ||
* 未处理完又产生中断,会有冲突 | ||
*************************************************************/ | ||
void DLC_USART_ReceiveData(USART_TypeDef *USARTx) | ||
{ | ||
//DEBUG_D("-- DLC_USART_ReceiveData() --"); | ||
if (USART_GetFlagStatus(USARTx, USART_IT_RXNE) != RESET) // 中断产生 | ||
{ | ||
USART_ClearITPendingBit(USARTx, USART_IT_RXNE); //清除中断 | ||
uint16_t value = USART_ReceiveData(USARTx); | ||
if (USARTx == USART1) | ||
{ | ||
Util_WriteUint8ToBuffer(&USART1Buffer, (uint8_t)value); | ||
// RecvValue = Value; | ||
} | ||
else if (USARTx == USART3) | ||
{ | ||
Util_WriteUint8ToBuffer(&USART3Buffer, (uint8_t)value); | ||
} | ||
else if (USARTx == UART5) | ||
{ | ||
Util_WriteUint8ToBuffer(&USART5Buffer, (uint8_t)value); | ||
} | ||
} | ||
if (USART_GetFlagStatus(USARTx, USART_FLAG_ORE) == SET) | ||
{ | ||
USART_ClearFlag(USARTx, USART_FLAG_ORE); | ||
} | ||
} | ||
|
||
void DLC_USART_SendUint8(USART_TypeDef *USARTx, uint8_t Data) | ||
{ | ||
while(USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET); | ||
USART_SendData(USARTx, Data); | ||
} | ||
|
||
void DLC_USART_SendString(USART_TypeDef* USARTx, const uint8_t *Data) | ||
{ | ||
if (Data) | ||
{ | ||
while(*Data) | ||
{ | ||
DLC_USART_SendUint8(USARTx, *(Data++)); | ||
} | ||
} | ||
} | ||
|
||
void DLC_USART_SendData(USART_TypeDef *USARTx, const uint8_t *Data, uint16_t Length) | ||
{ | ||
// DEBUG_D("-- DLC_USART_SendData() --"); | ||
if (Data) | ||
{ | ||
while(Length--) | ||
{ | ||
DLC_USART_SendUint8(USARTx, *(Data++)); | ||
} | ||
} | ||
} | ||
|
||
void USART1_IRQHandler(void) | ||
{ | ||
DLC_USART_ReceiveData(USART1); | ||
} | ||
|
||
void USART2_IRQHandler(void) | ||
{ | ||
DLC_USART_ReceiveData(USART2); | ||
} | ||
|
||
void USART3_IRQHandler(void) | ||
{ | ||
DLC_USART_ReceiveData(USART3); | ||
} | ||
|
||
void UART4_IRQHandler(void) | ||
{ | ||
DLC_USART_ReceiveData(UART4); | ||
} | ||
|
||
void UART5_IRQHandler(void) | ||
{ | ||
DLC_USART_ReceiveData(UART5); | ||
} | ||
|
||
``` | ||
## 参考资料 | ||
16 changes: 16 additions & 0 deletions
16
_posts/2016-12-18-java-faceted-project-metadata-file-could-not-be-read..md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
layout: post | ||
title: Faceted project metadata file "..." could not be read. | ||
comments: true | ||
category: Java | ||
tags: [Faceted, metadata] | ||
--- | ||
|
||
之前导入过的工程报这错 | ||
|
||
> "Faceted project metadata file "/AutoLogistics/.settings/org.eclipse.wst.common.project.facet.core.xml" could not be read." | ||
解决方法是重新import即可 | ||
|
||
## 参考资料 | ||
|