我做了一个小电路,根据stm32f030f4p6的PA4、PA5、PA6、PA7的输入状态决定从串口写不同的内容。
结果这个程序编完只要用stlinkV2写到CPU里面,stlink就再也连不上CPU了,CPU自己也不工作了,哪位大侠给指点一下问题出在什么地方。
stm32f030f4p6 锁死的现象谁遇到过?
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __initialize_H
#define __initialize_H
/* Includes ------------------------------------------------------------------*/
#include "stm32f0xx.h"
/* Exported functions --------------------------------------------------------*/
//extern uint16_t USART1_BaudRate;
uint32_t USART1_BaudRate = 115200;
#define CON1 GPIO_Pin_4
#define CON2 GPIO_Pin_5
#define CON3 GPIO_Pin_6
#define CON4 GPIO_Pin_7
#define LED GPIO_Pin_3
/******************************************************************************
* Function Name : GPIO_InitConfig
* Description : GPIO配置
* Input : None
* Output : None
* Return : None
* Attention : None
******************************************************************************/
void GPIO_InitConfig(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
GPIO_InitStruct.GPIO_Speed =GPIO_Speed_Level_1;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = CON1 | CON2 | CON3 | CON4;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStruct.GPIO_Speed =GPIO_Speed_Level_3;
GPIO_Init(GPIOA, &GPIO_InitStruct);
}
/******************************************************************************
* Function Name : USART_InitConfig
* Description : USART配置
* Input : None
* Output : None
* Return : None
* Attention : None
******************************************************************************/
void USART_InitConfig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_1);
/*
* USART1_TX -> PA9 , USART1_RX -> PA10
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = USART1_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(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
//USART_DirectionModeCmd(USART1, USART_Mode_Rx, ENABLE);
//USART_RequestCmd(USART1,USART_Request_RXFRQ,ENABLE);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
/*Enable the USART1 Interrupt(使能USART1中断)*/
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 4;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/******************************************************************************
* Function Name : System_InitConfig
* Description : 系统配置
* Input : None
* Output : None
* Return : None
* Attention : None
******************************************************************************/
void System_InitConfig(void)
{
//PLL_InitConfig();
GPIO_InitConfig();
USART_InitConfig();
}
#endif
/* Includes ------------------------------------------------------------------*/
//#include "main.h"
#include "stm32f0xx.h"
#include "initialize.h"
/* Private typedef -----------------------------------------------------------*/
char count = 0;
/* Private define ------------------------------------------------------------*/
uint8_t ID0[10] ={0xEB,0x90,0x04,0x55,0x00,0x00,0x00,0xBD,0x52};
uint8_t ID1[10] ={0xEB,0x90,0x04,0x55,0x01,0x00,0x00,0xEC,0x92};
uint8_t ID2[10] ={0xEB,0x90,0x04,0x55,0x02,0x00,0x00,0x1C,0x52};
uint8_t ID3[10] ={0xEB,0x90,0x04,0x55,0x03,0x00,0x00,0x4D,0x52};
uint8_t ID4[10] ={0xEB,0x90,0x04,0x55,0x04,0x00,0x00,0xFC,0x93};
uint8_t ID5[10] ={0xEB,0x90,0x04,0x55,0x05,0x00,0x00,0xAD,0x53};
uint8_t ID6[10] ={0xEB,0x90,0x04,0x55,0x06,0x00,0x00,0x5D,0x53};
uint8_t ID7[10] ={0xEB,0x90,0x04,0x55,0x07,0x00,0x00,0x0C,0x93};
uint8_t ID8[10] ={0xEB,0x90,0x04,0x55,0x08,0x00,0x00,0x3C,0x90};
uint8_t ID9[10] ={0xEB,0x90,0x04,0x55,0x09,0x00,0x00,0x6D,0x50};
uint16_t temp;
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void Delay_us(__IO uint32_t nCount);
void Delay_ms(__IO uint32_t nCount);
void USART1_TX_Data(uint8_t *pData,uint16_t TX_NumByte);
/* Private functions ---------------------------------------------------------*/
/******************************************************************************
* Function Name : main
* Description : 主程序
* Input : None
* Output : None
* Return : None
* Attention : None
******************************************************************************/
int main(void)
{
System_InitConfig();
Delay_ms(500);
while (1)
{
temp = GPIO_ReadInputData(GPIOA);
temp = temp & 0x00f0;
temp = temp >> 4;
switch(temp)
{
case 0:{ USART1_TX_Data(ID0,9);}break;//USART打印输出
case 1:{ USART1_TX_Data(ID1,9);}break;
case 2:{ USART1_TX_Data(ID2,9);}break;
case 3:{ USART1_TX_Data(ID3,9);}break;
case 4:{ USART1_TX_Data(ID4,9);}break;
case 5:{ USART1_TX_Data(ID5,9);}break;
case 6:{ USART1_TX_Data(ID6,9);}break;
case 7:{ USART1_TX_Data(ID7,9);}break;
case 8:{ USART1_TX_Data(ID8,9);}break;
case 9:{ USART1_TX_Data(ID9,9);}break;
}
if(GPIO_ReadOutputDataBit(GPIOA, LED))
{GPIO_ResetBits(GPIOA, LED);}
else
{GPIO_SetBits(GPIOA, LED);}
/* 延迟100mS */
Delay_ms(100);
}
}
/******************************************************************************
* Function Name : Delay | Delay_us
* Description : 延迟程序
* Input : nCount: 延时长度
* Output : None
* Return : None
* Attention : None
******************************************************************************/
void Delay(__IO uint32_t nCount)
{
/* Decrement nCount value */
while (nCount != 0)
{
nCount--;
}
}
void Delay_us(__IO uint32_t nCount)
{
/* 10uS延迟=>10.8uS,100uS延迟=>104uS*/
while (nCount != 0)
{
nCount--;
Delay(10);
}
}
void Delay_ms(__IO uint32_t nCount)
{
/* 10uS延迟=>10.8uS,100uS延迟=>104uS*/
while (nCount != 0)
{
nCount--;
Delay(11000);
}
}
/******************************************************************************
* Function Name : USART1_TX_Data
* Description : USART1数据发送
* Input : -pData:USART1发送数据
-TX_NumByte:发送数据数
* Output : None
* Return : None
* Attention : None
******************************************************************************/
void USART1_TX_Data(uint8_t *pData,uint16_t TX_NumByte)
{
uint16_t i;
for(i=0;i<TX_NumByte;i++)
{
USART_SendData(USART1,*pData++);
#if(USART1_BaudRate==115200)
Delay_us(90);
#endif
#if(USART1_BaudRate==19200)
Delay_us(500);
#endif
#if(USART1_BaudRate==9600)
Delay_us(1000);
#endif
}//for
}//void
/******************************************************************************
* Function Name : USART1_IRQHandler
* Description : USART1中断接收
* Input : None
* Output : None
* Return : None
* Attention : None
******************************************************************************/
void USART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
USART_SendData(USART1,USART_ReceiveData(USART1));//读取UART1接收到的数据并输出
}
}
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
vscode+cmake搭建雅特力AT32L021开发环境被打赏30分 | |
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 |