/******************************************************************************
* 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;
如果你需要一个小体积 JTAG 或 SWD 接口,可以参考 ARM 的 1.27 间距 CMSIS-DAP 接口,4 线 JTAG 和复位都有接出来的。
评分
查看全部评分
用什么命令可能会关闭SWD呢,我的程序里面一共就用了5个io和1个串口,我的程序也就是初始化一下这5个IO和串口
这程序全贴出来也没多少行啊
/* 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接收到的数据并输出
}
}
#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
评分
查看全部评分
我这里没用代码生成器,用的是厂家的固件库。
你说的 Cube是厂家的固件库吗?
Cube 和 SPL 都是。
楼上正解!后来发现是这样的