新手上路
- 积分
- 46
- 金钱
- 46
- 注册时间
- 2020-12-17
- 在线时间
- 14 小时
|
我的芯片是stm32f103vct6
我在BootLoader中使用了串口2和串口5
void Uart2Init(void)
{
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
//UART2ê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART2 Rx (PD.06) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;//156250;
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(USART2, &USART_InitStructure);
//ê1Äü½óêÕ·¢ËíÖD¶Ï
USART_Cmd(USART2, ENABLE);
USART_ITConfig(USART2, USART_IT_TC, ENABLE);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
//Çå·¢Ëííê3é±ê¼Çλ
USART_ClearITPendingBit(USART2, USART_IT_TC);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void Uart5Init(void)
{
GPIO_InitTypeDef GPIO_Initstrue2; //¶¨òåGPIO½á11ìå
USART_InitTypeDef USART_Initstrue2; //¶¨òå′®¿ú2½á11ìå
NVIC_InitTypeDef NVIC_Initstrue2; //¶¨òåÖD¶Ï2Îêy
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD, ENABLE); //ê1ÄüA¿úê±Öó
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE); //ê1Äü′®¿ú2ê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_Initstrue2.GPIO_Pin = GPIO_Pin_12; //ÅäÖÃ′®¿ú5μÄtx
GPIO_Initstrue2.GPIO_Mode = GPIO_Mode_AF_PP; //Îa¸′óÃíÆíì
GPIO_Initstrue2.GPIO_Speed = GPIO_Speed_50MHz; //ê±Öó50mhz
GPIO_Init(GPIOC,&GPIO_Initstrue2); //D′èë
GPIO_Initstrue2.GPIO_Pin = GPIO_Pin_2; //ÅäÖÃ′®¿ú5μÄrx
GPIO_Initstrue2.GPIO_Mode = GPIO_Mode_IN_FLOATING; //Îa¸¡¿Õêäèë
GPIO_Init(GPIOD,&GPIO_Initstrue2); //D′èë
USART_Initstrue2.USART_BaudRate = 115200; //2¨ìØÂê115200
USART_Initstrue2.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //ó2¼tá÷¿ØÎT
USART_Initstrue2.USART_Mode = USART_Mode_Rx|USART_Mode_Tx; //·¢Ëí½óêÕê1Äü
USART_Initstrue2.USART_Parity = USART_Parity_No; //ÎTÆæżD£Ñé
USART_Initstrue2.USART_StopBits = USART_StopBits_1; //í£Ö1λ1
USART_Initstrue2.USART_WordLength = USART_WordLength_8b; //óDD§êy¾Y°Ëλ
USART_Init(UART5,&USART_Initstrue2); //′®¿ú3õê¼»ˉ
USART_Cmd(UART5,ENABLE); //
USART_ITConfig(UART5,USART_IT_RXNE,ENABLE); //ê1Äü′®¿ú½óêÕÖD¶Ï
USART_ITConfig(UART5, USART_IT_TC, ENABLE);
USART_ClearITPendingBit(UART5, USART_IT_TC);
NVIC_Initstrue2.NVIC_IRQChannel = UART5_IRQn; //ÖD¶Ïí¨μàéèÖÃÎa′®¿ú5
NVIC_Initstrue2.NVIC_IRQChannelCmd = ENABLE; //¿aÆôÖD¶Ïí¨μà
NVIC_Initstrue2.NVIC_IRQChannelPreemptionPriority = 3;//éèÖÃÖD¶ÏóÅÏ輶Îa1
NVIC_Initstrue2.NVIC_IRQChannelSubPriority = 3; //éèÖÃ×óóÅÏ輶Îa1
NVIC_Init(&NVIC_Initstrue2);
}
void USART2_IRQHandler(void)
{
//RX
if(USART_GetITStatus(USART2, USART_IT_RXNE) == SET)
{
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
ComData2.ucRxBuf[ComData2.uiRxEndIndex] = USART_ReceiveData(USART2);
ComData2.uiRxEndIndex++;
if(ComData2.uiRxEndIndex >= ComRxBufferSize)
{
ComData2.uiRxEndIndex = 0;
}
ComData2.uiRxReadyFlag = 0;
ComData2.uiRxTimeOut = 0;
}
USART_ClearFlag(USART1,USART_FLAG_TC);
//TX
if(USART_GetITStatus(USART2, USART_IT_TC) == SET)
{
USART_ClearITPendingBit(USART2, USART_IT_TC);
//·¢Ëííê±Ïí£Ö1·¢Ëí
if(ComData2.uiTxStartIndex == ComData2.uiTxEndIndex)
{
// USART2->CR1 &= ~USART_Mode_Tx;
ComData2.uiTxReadyFlag = 1;
}
//·¢Ëíêy¾Y
else
{
USART2->DR = ComData2.ucTxBuf[ComData2.uiTxStartIndex];
ComData2.uiTxStartIndex++;
if(ComData2.uiTxStartIndex >= ComTxBufferSize)
{
ComData2.uiTxStartIndex = 0;
}
}
}
//RX over
if (USART_GetFlagStatus(USART2, USART_FLAG_ORE) != RESET)
{
(void)USART_ReceiveData(USART2);
}
}
void UART5_IRQHandler()
{
//RX
if(USART_GetITStatus(UART5, USART_IT_RXNE) == SET)
{
u8 Rxd;
u16 clear=clear;
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
Rxd = USART_ReceiveData(UART5);
if(USART_RX_CNT<USART_REC_LEN)
{
USART_RX_BUF[USART_RX_CNT]=Rxd;
USART_RX_CNT++;
}
ComData5.ucRxBuf[ComData5.uiRxEndIndex] = USART_ReceiveData(UART5);
ComData5.uiRxEndIndex++;
if(ComData5.uiRxEndIndex >= ComRxBufferSize)
{
ComData5.uiRxEndIndex = 0;
}
ComData5.uiRxReadyFlag = 0;
ComData5.uiRxTimeOut = 0;
}
USART_ClearFlag(USART1,USART_FLAG_TC);
//TX
if(USART_GetITStatus(UART5, USART_IT_TC) == SET)
{
USART_ClearITPendingBit(UART5, USART_IT_TC);
//·¢Ëííê±Ïí£Ö1·¢Ëí
if(ComData5.uiTxStartIndex == ComData5.uiTxEndIndex)
{
// USART2->CR1 &= ~USART_Mode_Tx;
ComData5.uiTxReadyFlag = 1;
}
//·¢Ëíêy¾Y
else
{
UART5->DR = ComData5.ucTxBuf[ComData5.uiTxStartIndex];
ComData5.uiTxStartIndex++;
if(ComData5.uiTxStartIndex >= ComTxBufferSize)
{
ComData5.uiTxStartIndex = 0;
}
}
}
//RX over
if (USART_GetFlagStatus(UART5, USART_FLAG_ORE) != RESET)
{
(void)USART_ReceiveData(UART5);
}
}
我在APP中使用了串口123和5,可以跳转到app但是程序会卡在app中的串口初始化处。如果我把app中的串口初始化屏蔽,程序是能都正常执行的,但是不屏蔽程序会卡在串口初始化的位置上。部分主程序
pOS_mbox_Uart1Rx = 0;
QualityDispComm = 1;
UartTaskNum = 0;
MemEdit = 0;
QualitySendFlag = 0;
NVIC_SetVectorTable(FLASH_BASE, 0x10000);中断向流量表
//SCB->VTOR = FLASH_BASE | OffsetAddress; /* Vector Table Relocation in Internal FLASH. *//*system_stm32f10x.c×¢òa*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //ÖD¶ÏóÅÏ輶·Ö×é ·Ö2×é
LED_Init();
OS_CPU_SysTickInit(); // /* Initialize the SysTick.
BSPInit();
我如果把BootLoader和app合在一起烧写入芯片程序是好用的,app正常运行,我发现是我在执行升级的时候,BootLoader会使用串口,然后app就不好使了!希望大神帮我看看
|
|