写了点儿简单的demo,用于STM32F10X的初学者进行参考,包含:
1、LED操作:单纯LED输出、按键控制LED输出(通过主函数while查询按键输入状态、配置按键中断输入状态)
2、USART操作:USART中断输入输出、USART的DMA输出
main.c贴在下面了,代码包见附件
#include "board.h"
#include <rtthread.h>
#include "led.h"
#include "uart.h"
#include "dma.h"
int main(void){
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 点亮一个LED灯的代码,初学者看这部分↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
/*
LED_Periph_Config();
while(1){
//Notes:study level 0: Light up an LED
//LED(ON);
//rt_thread_delay(5);
//LED(OFF);
//Notes:study level 1:The led is controlled by key input
//get_key_status();
//do_led_output();
//Notes:study level 2: Key input is configured in interrupt mode to control led
//Notes:study level 2:In this code implementation, only need to wait for interrupts, and don't need to write code in the loop
//Notes:study level 2:Need to write the key interrupt service function in stm32f10x_it.c
}
*/
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ 点亮一个LED灯的代码,初学者看这部分 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 实现UART串口收发的代码,进阶1 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
/*
//Notes:study level 3: Control the sending and receiving of UART1 through interrupt
//Notes:study level 3:Need to write the uart interrupt service function in stm32f10x_it.c
UART1_Periph_Config();
uint16_t i;
while(1){
UART1_Receive();
if(USART1_RX_LEN){
UART1_Send("["__DATE__" - "__TIME__"] receive times %d",++i);
}
}
//Notes else:if you do not kown about how to send data,read more in usart.c
*/
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ 实现UART串口收发的代码,进阶1 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ DMA实现UART串口发送的代码,进阶2 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
//Notes:study level 4:Control the sending and receiving of UART1 through DMA(TX) && interrupt(RX)
//i need test:DMA RX
/*
uint16_t i;
LED_Periph_Config();
UART1_Periph_Config();
UART1_TX_DMA_Config();
for(i = 0; i < USART1_TX_MAX; i++){
USART1_TX_BUF[i] = 0xaa;
}
USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE); // USART1 向 DMA发出TX请求
LED(ON);
while(1);
*/
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ DMA实现UART串口发送的代码,进阶2 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
}