久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 5203|回復(fù): 5
打印 上一主題 下一主題
收起左側(cè)

STM32 IAP之bootloader源碼協(xié)議采用YMODEM

  [復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:393904 發(fā)表于 2018-9-5 10:50 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
STM32 IAP之bootloader  協(xié)議采用YMODEM:
分bootloader工程和IAP工程代碼。


* 本例程在 奮斗版STM32開(kāi)發(fā)板V2,V2.1,V3,V5,MINI上調(diào)試通過(guò)           
*
* 文件名: main.c
* 內(nèi)容簡(jiǎn)述:   
*      
*    演示通過(guò)串口1顯示ADC1的11通道的測(cè)量結(jié)果
*    輔助軟件:PC機(jī)上需要運(yùn)行串口調(diào)試助手軟件。
   
    基于MDK版本:        3.8
    基于官方外設(shè)庫(kù)版本: 3.5   
*
* 文件歷史:
* 版本號(hào)  日期       作者    說(shuō)明
*
*/

1設(shè)計(jì)要求
利用ADC的第11通道對(duì)開(kāi)發(fā)板輸入的電壓值作AD轉(zhuǎn)換,采用連續(xù)轉(zhuǎn)換模式,轉(zhuǎn)換結(jié)果通過(guò)DMA通
道1讀取。ADC轉(zhuǎn)換的結(jié)果,每間隔1秒鐘向串口發(fā)送一次。

2 硬件電路設(shè)計(jì)                                       

            
在開(kāi)發(fā)板上通用I/O口PC.01與XS8的14腳相連,將PC.01映射到ADC第11通道,即可實(shí)現(xiàn)利用

ADC_IN11
對(duì)輸入電壓作AD轉(zhuǎn)換。

3軟件程序設(shè)計(jì)
    根據(jù)設(shè)計(jì)任務(wù)要求,軟件程序主要包括:
    (1)    配置GPIO口,將PC.01配置為ADC的第11采樣通道;將配置GPIO中PA.09和PA.10根

引腳為串口輸入輸出。
    (2)    設(shè)置ADC,將ADC_IN11設(shè)置為連續(xù)轉(zhuǎn)換模式;
    (3)    配置DMA通道1用于ADC_IN14傳輸轉(zhuǎn)換的結(jié)果;
    (4)    配置串口及相關(guān)發(fā)送功能;
    (5)    每隔1S向串口輸出AD轉(zhuǎn)換結(jié)果。

4 運(yùn)行過(guò)程
(1)    使用Keil uVision3 通過(guò)JLINK仿真器連接開(kāi)發(fā)板,使用串口線,連接實(shí)驗(yàn)板
上的UART1(XS5)和PC機(jī)的串口,打開(kāi)實(shí)驗(yàn)例程目錄下的STM32-FD-ADC.Uv2例程,編譯鏈接工程;
(2)    在PC機(jī)上運(yùn)行windows自帶的超級(jí)終端串口通信程序(波特率115200、1位停止位、無(wú)校驗(yàn)

位、無(wú)硬件流
控制);或者使用其它串口通信程序;
(3)    點(diǎn)擊MDK 的Debug菜單,點(diǎn)擊Start/Stop Debug Session;
(4)    可以看到串口輸出數(shù)值不斷變化,正常顯示結(jié)果如下所示。

usart1 print AD_value --------------------------
The current AD value = 2096
The current AD value = 2096
The current AD value = 2048
The current AD value = 2087
The current AD value = 2112
The current AD value = 2112
The current AD value = 2003
The current AD value = 1998
The current AD value = 1999
The current AD value = 2092
The current AD value = 2048
The current AD value = 2051
The current AD value = 2056
The current AD value = 2048
The current AD value = 2048
The current AD value = 2096
The current AD value = 2001
....
....
  1. #include "stm32f10x.h"          
  2. #include "stm32f10x_adc.h"
  3. #include "stm32f10x_dma.h"
  4. #include "stm32f10x_rcc.h"
  5. #include "stm32f10x_gpio.h"
  6. #include "stm32f10x_usart.h"         
  7. #include "stm32f10x_flash.h"
  8. #include "misc.h"                 
  9. #include  <stdarg.h>

  10. #define ADC1_DR_Address    ((u32)0x4001244C)         
  11. #define FLASH_IAP_ADDR                0x08000000          //iap程序起始地址(存放在FLASH)

  12. #define LED1   GPIO_Pin_5
  13. #define LED2   GPIO_Pin_6
  14. #define LED3   GPIO_Pin_3

  15. static unsigned long ticks;
  16. unsigned char Clock1s;


  17. vu16 ADC_ConvertedValue;

  18. typedef  void (*iapfun)(void);
  19. iapfun jump2iap;

  20. void RCC_Configuration(void);  
  21. void ADC_Configuration(void);
  22. void Usart1_Init(void);
  23. void USART_OUT(USART_TypeDef* USARTx, uint8_t *Data,...);
  24. void LED_Configuration(void);
  25. void KEY_Configuration(void);
  26. void iap_jump(u32 iapxaddr);

  27. /****************************************************************************
  28. * 名    稱:int main(void)
  29. * 功    能:主函數(shù)
  30. * 入口參數(shù):無(wú)
  31. * 出口參數(shù):無(wú)
  32. * 說(shuō)    明:
  33. * 調(diào)用方法:
  34. ****************************************************************************/
  35. int main(void)
  36. {       
  37.         static  _Bool flag_ledtoogle=0;
  38.   RCC_Configuration();                     //設(shè)置內(nèi)部時(shí)鐘及外設(shè)時(shí)鐘使能
  39.         LED_Configuration();
  40.         KEY_Configuration();
  41.   Usart1_Init();                             //串口1初始化  
  42.   ADC_Configuration();                                 //ADC初始化
  43.   USART_OUT(USART1,"\r\n USART1 print AD_value -------------------------- \r\n");
  44.   while(1)
  45.   {
  46.            if (ticks++ >= 900000)
  47.                 {        //間隔時(shí)間顯示轉(zhuǎn)換結(jié)果
  48.                         ticks   = 0;
  49.                         Clock1s = 1;
  50.                         flag_ledtoogle^=1;
  51.                 }
  52.                 if(flag_ledtoogle)
  53.                 {
  54.                                 GPIO_ResetBits(GPIOB, LED1);  //熄滅LED0-3       
  55.                 }               
  56.                 else
  57.                 {
  58.                                 GPIO_SetBits(GPIOB, LED1);  //熄滅LED0-3       
  59.                 }
  60.          if (Clock1s)
  61.                  {
  62.                                 Clock1s = 0;   
  63.                                          
  64.                                 USART_OUT(USART1,"The current AD value = %d \r\n", ADC_ConvertedValue);
  65.      }  
  66.                  
  67.                  if (GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_5)  == 0x00)
  68.                  {
  69.                                 iap_jump(FLASH_IAP_ADDR);
  70.                  }
  71.   }
  72. }
  73. //=============================================================================================
  74. //函數(shù)名稱: void iap_jump(u32 iapxaddr)
  75. //輸入?yún)?shù): appxaddr:用戶代碼起始地址.
  76. //輸出參數(shù):
  77. //返回值  :
  78. //功能描述: 跳轉(zhuǎn)到IAP
  79. //注意事項(xiàng): void
  80. //=============================================================================================
  81. void iap_jump(u32 iapxaddr)
  82. {
  83.         if(((*(vu32*)iapxaddr)&0x2FFE0000)==0x20000000)        //檢查棧頂?shù)刂肥欠窈戏?0x20000000是sram的起始地址,也是程序的棧頂?shù)刂?br />
  84.         {
  85. //                printf("ok\r\n");
  86.                 //Delay_Ms(10);
  87.                 jump2iap=(iapfun)*(vu32*)(iapxaddr+4);                //用戶代碼區(qū)第二個(gè)字為程序開(kāi)始地址(復(fù)位地址)               
  88.         //        MSR_MSP(*(vu32*)iapxaddr);                                        //初始化APP堆棧指針(用戶代碼區(qū)的第一個(gè)字用于存放棧頂?shù)刂?
  89.                 __set_MSP(*(__IO uint32_t*) iapxaddr);
  90.                 jump2iap();                                                                        //跳轉(zhuǎn)到APP.
  91.         }
  92.         else
  93.         {
  94. //                printf("iap program loss,please check\r\n");
  95.         }
  96. }
  97. /*******************************************************************************
  98.   * @函數(shù)名稱        KEY_Configuration
  99.   * @函數(shù)說(shuō)明   按鍵初始化
  100.   * @輸入?yún)?shù)   無(wú)
  101.   * @輸出參數(shù)   無(wú)
  102.   * @返回參數(shù)   無(wú)
  103. *******************************************************************************/
  104. void KEY_Configuration(void)
  105. {
  106.     GPIO_InitTypeDef GPIO_InitStructure;
  107.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

  108.     //配置按鍵
  109.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  110.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  111.     GPIO_Init(GPIOC, &GPIO_InitStructure);
  112. }
  113. /*******************************************************************************
  114.   * @函數(shù)名稱        LED_Configuration
  115.   * @函數(shù)說(shuō)明   配置使用LED
  116.   * @輸入?yún)?shù)   無(wú)
  117.   * @輸出參數(shù)   無(wú)
  118.   * @返回參數(shù)   無(wú)
  119. *******************************************************************************/
  120. void LED_Configuration(void)
  121. {
  122.     GPIO_InitTypeDef GPIO_InitStructure;
  123.     //使能LED所在GPIO的時(shí)鐘
  124.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);
  125.     //初始化LED的GPIO
  126.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  127.                 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         
  128.                 GPIO_InitStructure.GPIO_Pin =  LED1;
  129.           GPIO_Init(GPIOB, &GPIO_InitStructure);       
  130.                 GPIO_SetBits(GPIOB, LED1);  //熄滅LED0-3
  131.        
  132.                 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD , ENABLE);       
  133.           //初始化LED的GPIO
  134.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  135.                 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  136.                 GPIO_InitStructure.GPIO_Pin =  LED2 | LED3;         
  137.                 GPIO_Init(GPIOD, &GPIO_InitStructure);                       
  138.   
  139.     GPIO_SetBits(GPIOD, LED2 | LED3);  //熄滅LED0-3
  140. }

  141. /****************************************************************************
  142. * 名    稱:void ADC_Configuration(void)
  143. * 功    能:ADC 配置函數(shù)
  144. * 入口參數(shù):無(wú)
  145. * 出口參數(shù):無(wú)
  146. * 說(shuō)    明:
  147. * 調(diào)用方法:
  148. ****************************************************************************/
  149. void ADC_Configuration(void)
  150. {
  151.         ADC_InitTypeDef ADC_InitStructure;
  152.         GPIO_InitTypeDef GPIO_InitStructure;
  153.         DMA_InitTypeDef DMA_InitStructure;

  154.     //設(shè)置AD模擬輸入端口為輸入 1路AD 規(guī)則通道
  155.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  156.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  157.           GPIO_Init(GPIOC, &GPIO_InitStructure);
  158.         /* Enable DMA clock */
  159.     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

  160.    /* Enable ADC1 and GPIOC clock */
  161.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE);

  162.           /* DMA channel1 configuration ----------------------------------------------*/
  163.         //使能DMA
  164.         DMA_DeInit(DMA1_Channel1);
  165.         DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;                                    //DMA通道1的地址
  166.         DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue;                    //DMA傳送地址
  167.         DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;                                                    //傳送方向
  168.         DMA_InitStructure.DMA_BufferSize = 1;                                                                            //傳送內(nèi)存大小,1個(gè)16位
  169.         DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;         
  170.         DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;                                            //傳送內(nèi)存地址遞增
  171.         DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;                //ADC1轉(zhuǎn)換的數(shù)據(jù)是16位
  172.         DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;                                //傳送的目的地址是16位寬度
  173.         DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;                                                                        //循環(huán)
  174.         DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  175.         DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  176.         DMA_Init(DMA1_Channel1, &DMA_InitStructure);
  177.    
  178.         /* 允許DMA1通道1傳輸結(jié)束中斷 */
  179.         //DMA_ITConfig(DMA1_Channel1,DMA_IT_TC, ENABLE);


  180.         //使能DMA通道1
  181.         DMA_Cmd(DMA1_Channel1, ENABLE);
  182.   
  183.   
  184.         //ADC配置
  185.         /* ADC轉(zhuǎn)換時(shí)間: ─ STM32F103xx增強(qiáng)型產(chǎn)品:時(shí)鐘為56MHz時(shí)為1μs(時(shí)鐘為72MHz為1.17μs)
  186.         ADC采樣范圍0-3.3V    */
  187.         RCC_ADCCLKConfig(RCC_PCLK2_Div6);                   //設(shè)置ADC的時(shí)鐘為72MHZ/6=12M

  188.         ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;        //ADC1工作在獨(dú)立模式
  189.         ADC_InitStructure.ADC_ScanConvMode = ENABLE;                //模數(shù)轉(zhuǎn)換工作在掃描模式(多通道)還是單次(單通道)模式
  190.         ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;        //模數(shù)轉(zhuǎn)換工作在連續(xù)模式,還是單次模式
  191.         ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;//轉(zhuǎn)換由軟件而不是外部觸發(fā)啟動(dòng)
  192.         ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//ADC數(shù)據(jù)右對(duì)齊
  193.         ADC_InitStructure.ADC_NbrOfChannel = 1;               //規(guī)定了順序進(jìn)行規(guī)則轉(zhuǎn)換的ADC通道的數(shù)目。這個(gè)數(shù)目的取值范圍是1到16
  194.         ADC_Init(ADC1, &ADC_InitStructure);
  195.        
  196.         /* ADC1 regular channels configuration [規(guī)則模式通道配置]*/

  197.         //ADC1 規(guī)則通道配置
  198.           ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_55Cycles5);          //通道11采樣時(shí)間 55.5周期
  199.          

  200.         //使能ADC1 DMA
  201.         ADC_DMACmd(ADC1, ENABLE);
  202.         //使能ADC1
  203.         ADC_Cmd(ADC1, ENABLE);       
  204.        
  205.         // 初始化ADC1校準(zhǔn)寄存器
  206.         ADC_ResetCalibration(ADC1);
  207.         //檢測(cè)ADC1校準(zhǔn)寄存器初始化是否完成
  208.         while(ADC_GetResetCalibrationStatus(ADC1));
  209.        
  210.         //開(kāi)始校準(zhǔn)ADC1
  211.         ADC_StartCalibration(ADC1);
  212.         //檢測(cè)是否完成校準(zhǔn)
  213.         while(ADC_GetCalibrationStatus(ADC1));
  214.        
  215.         //ADC1轉(zhuǎn)換啟動(dòng)
  216.         ADC_SoftwareStartConvCmd(ADC1, ENABLE);         
  217. }
  218. /****************************************************************************
  219. * 名    稱:void RCC_Configuration(void)
  220. * 功    能:系統(tǒng)時(shí)鐘配置為72MHZ, 外設(shè)時(shí)鐘配置
  221. * 入口參數(shù):無(wú)
  222. * 出口參數(shù):無(wú)
  223. * 說(shuō)    明:
  224. * 調(diào)用方法:無(wú)
  225. ****************************************************************************/
  226. void RCC_Configuration(void){

  227.   SystemInit();
  228.   RCC_ADCCLKConfig(RCC_PCLK2_Div6);
  229.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  230.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
  231.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE);
  232.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC
  233.                                                   | RCC_APB2Periph_GPIOD| RCC_APB2Periph_GPIOE , ENABLE);
  234. }

  235. /****************************************************************************
  236. * 名    稱:void Usart1_Init(void)
  237. * 功    能:串口1初始化函數(shù)
  238. * 入口參數(shù):無(wú)
  239. * 出口參數(shù):無(wú)
  240. * 說(shuō)    明:
  241. * 調(diào)用方法:無(wú)
  242. ****************************************************************************/
  243. void Usart1_Init(void)
  244. {
  245.   GPIO_InitTypeDef GPIO_InitStructure;
  246.   USART_InitTypeDef USART_InitStructure;

  247.   RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1 , ENABLE);         //使能串口1時(shí)鐘

  248.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;                               //LCD背光控制
  249.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  250.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  251.   GPIO_Init(GPIOD, &GPIO_InitStructure);
  252.   GPIO_ResetBits(GPIOD, GPIO_Pin_13);                                      //LCD背光關(guān)閉       

  253.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;                                  //USART1 TX
  254.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  255.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;                     //復(fù)用推挽輸出
  256.   GPIO_Init(GPIOA, &GPIO_InitStructure);                                     //A端口

  257.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;                          //USART1 RX
  258.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;            //復(fù)用開(kāi)漏輸入
  259.   GPIO_Init(GPIOA, &GPIO_InitStructure);                                  //A端口

  260.   USART_InitStructure.USART_BaudRate = 9600;                                                //速率115200bps
  261.   USART_InitStructure.USART_WordLength = USART_WordLength_8b;                //數(shù)據(jù)位8位
  262.   USART_InitStructure.USART_StopBits = USART_StopBits_1;                        //停止位1位
  263.   USART_InitStructure.USART_Parity = USART_Parity_No;                                //無(wú)校驗(yàn)位
  264.   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;   //無(wú)硬件流控
  265.   USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;                                        //收發(fā)模式

  266.   /* Configure USART1 */
  267.   USART_Init(USART1, &USART_InitStructure);                                                        //配置串口參數(shù)函數(shù)   
  268.    /* Enable the USART1 */
  269.   USART_Cmd(USART1, ENABLE);       
  270.   
  271. }
  272. /******************************************************
  273.                 整形數(shù)據(jù)轉(zhuǎn)字符串函數(shù)
  274.         char *itoa(int value, char *string, int radix)
  275.                 radix=10 標(biāo)示是10進(jìn)制        非十進(jìn)制,轉(zhuǎn)換結(jié)果為0;  

  276.             例:d=-379;
  277.                 執(zhí)行        itoa(d, buf, 10); 后
  278.                
  279.                 buf="-379"                                                                                     
  280. **********************************************************/
  281. char *itoa(int value, char *string, int radix)
  282. {
  283.     int     i, d;
  284.     int     flag = 0;
  285.     char    *ptr = string;

  286.     /* This implementation only works for decimal numbers. */
  287.     if (radix != 10)
  288.     {
  289.         *ptr = 0;
  290.         return string;
  291.     }

  292.     if (!value)
  293.     {
  294.         *ptr++ = 0x30;
  295.         *ptr = 0;
  296.         return string;
  297.     }

  298.     /* if this is a negative value insert the minus sign. */
  299.     if (value < 0)
  300.     {
  301.         *ptr++ = '-';

  302.         /* Make the value positive. */
  303.         value *= -1;
  304.     }

  305.     for (i = 10000; i > 0; i /= 10)
  306.     {
  307.         d = value / i;

  308.         if (d || flag)
  309.         {
  310.             *ptr++ = (char)(d + 0x30);
  311.             value -= (d * i);
  312.             flag = 1;
  313.         }
  314.     }

  315.     /* Null terminate the string. */
  316.     *ptr = 0;

  317.     return string;

  318. } /* NCL_Itoa */
  319. /****************************************************************************
  320. * 名    稱:void USART_OUT(USART_TypeDef* USARTx, uint8_t *Data,...)
  321. * 功    能:格式化串口輸出函數(shù)
  322. * 入口參數(shù):USARTx:  指定串口
  323.                         Data:   發(fā)送數(shù)組
  324.                         ...:     不定參數(shù)
  325. * 出口參數(shù):無(wú)
  326. * 說(shuō)    明:格式化串口輸出函數(shù)
  327.                 "\r"        回車(chē)符           USART_OUT(USART1, "abcdefg\r")   
  328.                         "\n"        換行符           USART_OUT(USART1, "abcdefg\r\n")
  329.                         "%s"        字符串           USART_OUT(USART1, "字符串是:%s","abcdefg")
  330.                         "%d"        十進(jìn)制           USART_OUT(USART1, "a=%d",10)
  331. * 調(diào)用方法:無(wú)
  332. ****************************************************************************/
  333. void USART_OUT(USART_TypeDef* USARTx, uint8_t *Data,...){

  334.         const char *s;
  335.     int d;
  336.    
  337.     char buf[16];
  338.     va_list ap;
  339.     va_start(ap, Data);

  340.         while(*Data!=0){                                                          //判斷是否到達(dá)字符串結(jié)束符
  341.                 if(*Data==0x5c){                                                                          //'\'
  342.                         switch (*++Data){
  343.                                 case 'r':                                                                  //回車(chē)符
  344.                                         USART_SendData(USARTx, 0x0d);          

  345.                                         Data++;
  346.                                         break;
  347.                                 case 'n':                                                                  //換行符
  348.                                         USART_SendData(USARTx, 0x0a);       
  349.                                         Data++;
  350.                                         break;
  351.                                
  352.                                 default:
  353.                                         Data++;
  354.                                     break;
  355.                         }
  356.                        
  357.                          
  358.                 }
  359.                 else if(*Data=='%'){                                                                          //
  360.                         switch (*++Data){                               
  361.                                 case 's':                                                                                  //字符串
  362.                         s = va_arg(ap, const char *);
  363.                         for ( ; *s; s++) {
  364.                             USART_SendData(USARTx,*s);
  365.                                                 while(USART_GetFlagStatus(USARTx, USART_FLAG_TC)==RESET);
  366.                         }
  367.                                         Data++;
  368.                         break;
  369.                     case 'd':                                                                                  //十進(jìn)制
  370.                         d = va_arg(ap, int);
  371.                         itoa(d, buf, 10);
  372.                         for (s = buf; *s; s++) {
  373.                             USART_SendData(USARTx,*s);
  374.                                                 while(USART_GetFlagStatus(USARTx, USART_FLAG_TC)==RESET);
  375.                         }
  376.                                         Data++;
  377.                         break;
  378.                                 default:
  379.                                         Data++;
  380.                                     break;
  381.                         }                 
  382.                 }
  383.                 else USART_SendData(USARTx, *Data++);
  384.                 while(USART_GetFlagStatus(USARTx, USART_FLAG_TC)==RESET);
  385.         }
  386. }
  387. /******************* (C) COPYRIGHT 2013 奮斗STM32 *****END OF FILE****/
復(fù)制代碼
  1. //=======================================Copyright(c)===========================================
  2. //                                                                                         Auto Code Making Company
  3. //                                                                                        Auto Code Department
  4. //                                                                                                CopyRight Private
  5. //-------------------------------------------------FileMessage------------------------------------
  6. //FileName          main.c
  7. //Author         yanggang
  8. //Creation Time
  9.           
  10. //Description
  11. //-----------------------------------------------當(dāng)前版本修訂----------------------------------
  12. //修改人       
  13. //版        本         
  14. //修改日期       
  15. //Description       
  16. //=============================================================================================


  17. /*******************************************************************************
  18. ** 文件名:                 mian.c
  19. ** 功能:                USART初始化和RCC設(shè)置,然后從common.c中執(zhí)行主菜單
  20. ** 相關(guān)文件:        stm32f10x.h
  21. *******************************************************************************/

  22. /* 包含頭文件 *****************************************************************/
  23. #include "common.h"
  24. /* 類(lèi)型聲明 ------------------------------------------------------------------*/
  25. /* 宏 ------------------------------------------------------------------------*/
  26. #define LED0   GPIO_Pin_0
  27. #define LED1   GPIO_Pin_1
  28. #define LED2   GPIO_Pin_2
  29. #define LED3   GPIO_Pin_3
  30. /* 變量 ----------------------------------------------------------------------*/
  31. extern pFunction Jump_To_Application;
  32. extern uint32_t JumpAddress;

  33. /* 函數(shù)聲明 ------------------------------------------------------------------*/
  34. void Delay(__IO uint32_t nCount);
  35. void LED_Configuration(void);
  36. static void IAP_Init(void);
  37. void KEY_Configuration(void);
  38. void GPIO_Configuration(void);
  39. void USART_Configuration(void);
  40. /* 函數(shù)功能 ------------------------------------------------------------------*/

  41. /*******************************************************************************
  42.   * @函數(shù)名稱        main
  43.   * @函數(shù)說(shuō)明   主函數(shù)
  44.   * @輸入?yún)?shù)   無(wú)
  45.   * @輸出參數(shù)   無(wú)
  46.   * @返回參數(shù)   無(wú)
  47. *******************************************************************************/
  48. int main(void)
  49. {
  50.     //Flash 解鎖
  51.     FLASH_Unlock();
  52.     LED_Configuration();
  53.     //配置按鍵
  54.     KEY_Configuration() ;
  55.     IAP_Init();
  56.     //按鍵是否按下
  57.     if (GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_5)  == 0x00)
  58.     {
  59.         //假如USER1按鍵按下
  60.         //執(zhí)行IAP驅(qū)動(dòng)程序更新Flash程序

  61.         SerialPutString("\r\n======================================================================");
  62.         SerialPutString("\r\n=                                                                    =");
  63.         SerialPutString("\r\n=     In-Application Programming Application  (Version 1.0.0)        =");
  64.         SerialPutString("\r\n=                                                                    =");
  65.         SerialPutString("\r\n======================================================================");
  66.         SerialPutString("\r\n\r\n");
  67.         Main_Menu ();
  68.     }
  69.     //否則執(zhí)行用戶程序
  70.     else
  71.     {
  72.         //判斷用戶是否已經(jīng)下載程序,因?yàn)檎G闆r下此地址是棧地址。
  73.         //若沒(méi)有這一句的話,即使沒(méi)有下載程序也會(huì)進(jìn)入而導(dǎo)致跑飛。
  74.         if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)
  75.         {
  76.             SerialPutString("Execute user Program\r\n\n");
  77.             //跳轉(zhuǎn)至用戶代碼
  78.             JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
  79.             Jump_To_Application = (pFunction) JumpAddress;

  80.             //初始化用戶程序的堆棧指針
  81.             __set_MSP(*(__IO uint32_t*) ApplicationAddress);
  82.             Jump_To_Application();
  83.         }
  84.         else
  85.         {
  86.             SerialPutString("no user Program\r\n\n");
  87.         }
  88.     }

  89.     while (1)
  90.     {
  91.     }
  92. }


  93. /*******************************************************************************
  94.   * @函數(shù)名稱        LED_Configuration
  95.   * @函數(shù)說(shuō)明   配置使用LED
  96.   * @輸入?yún)?shù)   無(wú)
  97.   * @輸出參數(shù)   無(wú)
  98.   * @返回參數(shù)   無(wú)
  99. *******************************************************************************/
  100. void LED_Configuration(void)
  101. {
  102.     GPIO_InitTypeDef GPIO_InitStructure;
  103.     //使能LED所在GPIO的時(shí)鐘
  104.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE , ENABLE);
  105.     //初始化LED的GPIO
  106.     GPIO_InitStructure.GPIO_Pin = LED0 | LED1 | LED2 | LED3;
  107.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  108.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  109.     GPIO_Init(GPIOE, &GPIO_InitStructure);
  110.     GPIO_SetBits(GPIOE,  LED2 | LED3);  //熄滅LED0-3
  111.        
  112. }

  113. /*******************************************************************************
  114.   * @函數(shù)名稱        KEY_Configuration
  115.   * @函數(shù)說(shuō)明   按鍵初始化
  116.   * @輸入?yún)?shù)   無(wú)
  117.   * @輸出參數(shù)   無(wú)
  118.   * @返回參數(shù)   無(wú)
  119. *******************************************************************************/
  120. void KEY_Configuration(void)
  121. {
  122.     GPIO_InitTypeDef GPIO_InitStructure;
  123.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

  124.     //配置按鍵
  125.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  126.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  127.     GPIO_Init(GPIOC, &GPIO_InitStructure);
  128. }

  129. /*******************************************************************************
  130.   * @函數(shù)名稱        GPIO_Configuration
  131.   * @函數(shù)說(shuō)明   配置使用USART1的相關(guān)IO管腳
  132.   * @輸入?yún)?shù)   無(wú)
  133.   * @輸出參數(shù)   無(wú)
  134.   * @返回參數(shù)   無(wú)
  135. *******************************************************************************/
  136. void GPIO_Configuration(void)
  137. {
  138.     GPIO_InitTypeDef GPIO_InitStructure;

  139.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
  140.     // 配置 USART1 Tx (PA.09) 作為功能引腳并上拉輸出模式
  141.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  142.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  143.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  144.     GPIO_Init(GPIOA, &GPIO_InitStructure);

  145.     //配置 USART1 Tx (PA.10) 作為功能引腳并是浮空輸入模式
  146.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  147.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  148.     GPIO_Init(GPIOA, &GPIO_InitStructure);
  149. }

  150. /*******************************************************************************
  151.   * @函數(shù)名稱        IAP_Init
  152.   * @函數(shù)說(shuō)明   配置使用IAP
  153.   * @輸入?yún)?shù)   無(wú)
  154.   * @輸出參數(shù)   無(wú)
  155.   * @返回參數(shù)   無(wú)
  156. *******************************************************************************/
  157. void IAP_Init(void)
  158. {
  159.     USART_InitTypeDef USART_InitStructure;

  160.     /* USART1 配置 ------------------------------------------------------------
  161.          USART1 配置如下:
  162.           - 波特率      = 115200 baud
  163.           - 字長(zhǎng)        = 8 Bits
  164.           - 一個(gè)停止位
  165.           - 無(wú)校驗(yàn)
  166.           - 無(wú)硬件流控制
  167.           - 接受和發(fā)送使能
  168.     --------------------------------------------------------------------------*/
  169.     USART_InitStructure.USART_BaudRate = 9600;
  170.     USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  171.     USART_InitStructure.USART_StopBits = USART_StopBits_1;
  172.     USART_InitStructure.USART_Parity = USART_Parity_No;
  173.     USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  174.     USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  175.     GPIO_Configuration();
  176.     USART_Init(USART1, &USART_InitStructure);
  177.     // 使能 USART1
  178.     USART_Cmd(USART1, ENABLE);
  179. }

  180. /*******************************************************************************
  181.   * @函數(shù)名稱        Delay
  182.   * @函數(shù)說(shuō)明   插入一段延時(shí)時(shí)間
  183.   * @輸入?yún)?shù)   nCount: 指定延時(shí)時(shí)間長(zhǎng)度
  184.   * @輸出參數(shù)   無(wú)
  185.   * @返回參數(shù)   無(wú)
  186. *******************************************************************************/
  187. void Delay(__IO uint32_t nCount)
  188. {
  189.     for (; nCount != 0; nCount--);
  190. }

  191. #ifdef  USE_FULL_ASSERT

  192. /*******************************************************************************
  193.   * @函數(shù)名稱        assert_failed
  194.   * @函數(shù)說(shuō)明   報(bào)告在檢查參數(shù)發(fā)生錯(cuò)誤時(shí)的源文件名和錯(cuò)誤行數(shù)
  195.   * @輸入?yún)?shù)   file: 源文件名
  196.                                   line: 錯(cuò)誤所在行數(shù)
  197.   * @輸出參數(shù)   無(wú)
  198.   * @返回參數(shù)   無(wú)
  199. *******************************************************************************/
  200. void assert_failed(uint8_t* file, uint32_t line)
  201. {
  202.     /* 用戶可以增加自己的代碼用于報(bào)告錯(cuò)誤的文件名和所在行數(shù),
  203.        例如:printf("錯(cuò)誤參數(shù)值: 文件名 %s 在 %d行\(zhòng)r\n", file, line) */

  204.     //死循環(huán)
  205.     while (1)
  206.     {
  207.     }
  208. }
  209. #endif

  210. /*******************************文件結(jié)束***************************************/
復(fù)制代碼

全部資料51hei下載地址:
STM32 IAP之bootloader 協(xié)議采用YMODEM.rar (3.78 MB, 下載次數(shù): 148)

評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏3 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:490150 發(fā)表于 2019-3-15 16:56 | 只看該作者
下載看看,看著不錯(cuò)
回復(fù)

使用道具 舉報(bào)

板凳
ID:447445 發(fā)表于 2019-8-27 09:19 | 只看該作者
參考一下。
回復(fù)

使用道具 舉報(bào)

地板
ID:20672 發(fā)表于 2019-11-5 15:10 | 只看該作者
x謝謝分享~~
回復(fù)

使用道具 舉報(bào)

5#
ID:439102 發(fā)表于 2020-2-26 13:55 | 只看該作者
謝謝分享,參考一下
回復(fù)

使用道具 舉報(bào)

6#
ID:248019 發(fā)表于 2020-3-10 13:59 | 只看該作者
正在學(xué)習(xí),感謝分享
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 中文字幕在线一区 | 男人的天堂一级片 | 免费精品一区 | 日韩视频中文字幕 | 一区二区三区四区在线视频 | 一级a性色生活片久久毛片波多野 | 欧美精品第三页 | 欧美日韩不卡在线 | 亚洲精品在线免费播放 | 国产精品一区二区三区在线 | 精品视频在线观看 | 亚洲免费一区二区 | 欧美一区二区三区,视频 | 成人av电影天堂 | 成人影音 | 精品国产乱码久久久久久牛牛 | 午夜午夜精品一区二区三区文 | 久久久久久国产精品 | 亚洲国产精品自拍 | 国产一伦一伦一伦 | av色站| 好姑娘影视在线观看高清 | 在线观看亚洲精品视频 | 久久国产精品99久久久久 | 欧美在线一区二区三区四区 | 女同久久| 亚洲区一区二区 | 91福利在线观看视频 | 在线免费观看黄色 | 久久欧美精品 | 成人在线视频网站 | 日本精品视频在线 | 国产精品视频yy9299一区 | 夜夜撸av | 午夜影院视频 | 色综合av | 日本免费小视频 | 国产91久久精品一区二区 | 亚洲综合首页 | 在线观看国产视频 | 亚洲不卡在线观看 |