STM32
直播中

王强

7年用户 1320经验值
私信 关注
[问答]

如何在stm32上去实现IAP功能呢

如何在STM32上去实现IAP功能呢?
怎样去解决stm32 IAP程序跳转后串口不能发送的问题?

回帖(1)

李维嘉

2021-9-26 10:48:47
  问题描述
  在stm32上实现了IAP功能,当IAP程序与APP程序都使用Keil编译工具进行编译链接时,APP程序能够正常工作。但是IAP程序使用Keil编译,APP程序使用gcc-arm-none-eabi交叉编译工具链进行编译时,下载下去后GPIO能正常工作,但是串口发送时总是卡在这一句:
  void USART3_putchar(char data)
  {
  while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET); //卡在这里
  USART_SendData(USART3, (uint16_t)data);
  }
  解决办法
  在APP串口初始化开始前先DeInit一次,将串口恢复到默认的状态,然后再进行初始化。不管IAP程序对串口做了什么设置,都不会影响到APP的设置。
  void USART3_Configuration( unsigned int BaudRate)
  {
  GPIO_InitTypeDef GPIO_InitStructure;
  USART_InitTypeDef USART_InitStructure;
  USART_ClockInitTypeDef USART_ClockInitStructure;
  USART_DeInit(USART3); //在这里增加
  // USART3
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; // USART3 TX
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; // USART3 RX
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  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(USART3, &USART_InitStructure);
  USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
  USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
  USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
  USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
  USART_ClockInit(USART3,&USART_ClockInitStructure);
  USART_ITConfig(USART3, USART_IT_RXNE , ENABLE);
  USART_ClearFlag(USART3, USART_FLAG_TC);
  USART_ClearITPendingBit(USART3, USART_IT_TXE);
  USART_Cmd(USART3, ENABLE);
  }
  编译下载后运行,一切OK!
举报

更多回帖

发帖
×
20
完善资料,
赚取积分