找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5457|回复: 2
收起左侧

stm32f107智嵌以太网IAP远程更新附源代码和说明文件

[复制链接]
ID:140253 发表于 2018-3-12 19:04 | 显示全部楼层 |阅读模式
附IAP远程更新源代码和说明文件
0.png

0.jpg 0.png

单片机源程序如下:

  1. /* Includes ------------------------------------------------------------------*/
  2. #include "stm32_eth.h"
  3. #include "netconf.h"
  4. #include "main.h"
  5. #include "helloworld.h"
  6. #include "httpd.h"
  7. #include "tftpserver.h"
  8. #include "KEY.H"
  9. #include "stdio.h"
  10. #include "bkp.h"
  11. #include "LED.H"

  12. /* Private typedef -----------------------------------------------------------*/
  13. /* Private define ------------------------------------------------------------*/
  14. #define SYSTEMTICK_PERIOD_MS  10

  15. #ifdef __GNUC__
  16.   /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
  17.      set to 'Yes') calls __io_putchar() */
  18.   #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  19. #else
  20.   #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
  21. #endif /* __GNUC__ */

  22. /* Private macro -------------------------------------------------------------*/
  23. /* Private variables ---------------------------------------------------------*/
  24. __IO uint32_t LocalTime = 0; /* this variable is used to create a time reference incremented by 10ms */
  25. uint32_t timingdelay;

  26. typedef  void (*pFunction)(void);
  27. pFunction Jump_To_User_Application;
  28. uint32_t Jump_User_Address;

  29. /* Private function prototypes -----------------------------------------------*/
  30. void System_Periodic_Handle(void);
  31. void IAP_httpd_init(void);
  32. void IAP_tftpd_init(void);
  33. void MY_NVIC_Configuration(void);
  34. void NVIC_DeInit(void);
  35. void BKP_Configuration(void);
  36. void MCU_Reset(void);
  37. void EARES_SRAM(void);
  38. void NVIC_Configuration(void);
  39. /* Private functions ---------------------------------------------------------*/

  40. /**
  41.   * @brief  Main program.
  42.   * @param  None
  43.   * @retval None
  44.   */

  45.         
  46. int main(void)
  47. {
  48.         unsigned int g_bUpdateFlag = 0;

  49.         NVIC_DeInit();
  50.         RCC_DeInit();        
  51.         SystemInit();
  52.         BKP_Configuration();
  53.         NVIC_Configuration();

  54.         SEI(); //开全局中断

  55.         g_bUpdateFlag = BKP_ReadBackupRegister(BKP_DR9);  //读取更新标志
  56.         //if(!(KEY1 | KEY2 | KEY3 | KEY4)
  57.         if(g_bUpdateFlag  == 0x0)     //不需要升级,
  58.         {  
  59.                 /* Check if valid stack address (RAM address) then jump to user application */
  60.                 if (((*(__IO uint32_t*)USER_FLASH_FIRST_PAGE_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
  61.                 {
  62.                         CLI();                        //关闭总中断,必须有、
  63.                         NVIC_DeInit();
  64.                         RCC_DeInit();
  65.                         /* Jump to user application */
  66.                         Jump_User_Address = *(__IO uint32_t*) (USER_FLASH_FIRST_PAGE_ADDRESS + 4);
  67.                         Jump_To_User_Application = (pFunction) Jump_User_Address;
  68.                         /* Initialize user application's Stack Pointer */
  69.                         __set_MSP(*(__IO uint32_t*) USER_FLASH_FIRST_PAGE_ADDRESS);
  70.                         Jump_To_User_Application();
  71.                         while (1);
  72.                 }
  73.                 else
  74.                 {
  75.                         //printf("非法SRAM\n");
  76.                 }
  77.         }
  78.    
  79.    else         //初始化网络模块,等待用户远程登录,更新固件
  80.    {
  81.                 /* Setup STM32 system (clocks, Ethernet, GPIO, NVIC) and STM3210C-EVAL resources */
  82.                 BKP_WriteBackupRegister(BKP_DR9,0x00);// 标志已经下载了程序了
  83.                 System_Setup();
  84.                 /* Initilaize the LwIP satck ip地址设置,mac设置,*/

  85.                 LwIP_Init();
  86.                
  87.                 IAP_httpd_init();
  88.                 /* Infinite loop */
  89.                 while (1)
  90.                 {   
  91.                       /* Periodic tasks */
  92.                     System_Periodic_Handle();
  93.                 }
  94.         }
  95. }

  96. void MCU_Reset(void)
  97. {
  98.         __disable_fault_irq();      // STM32 软复位  
  99.         NVIC_SystemReset();
  100. }

  101. PUTCHAR_PROTOTYPE
  102. {
  103.   /* Place your implementation of fputc here */
  104.   /* e.g. write a character to the USART */
  105.   USART_SendData(USART2, (uint8_t) ch);

  106.   /* Loop until the end of transmission */
  107.   while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET)
  108.   {}

  109.   return ch;
  110. }
  111. /**
  112.   * @brief  Inserts a delay time.
  113.   * @param  nCount: number of 10ms periods to wait for.
  114.   * @retval None
  115.   */
  116. void Delay(uint32_t nCount)
  117. {
  118.   /* Capture the current local time */
  119.   timingdelay = LocalTime + nCount;  

  120.   /* wait until the desired delay finish */  
  121.   while(timingdelay > LocalTime)
  122.   {     
  123.   }
  124. }

  125. /**
  126.   * @brief  Updates the system local time
  127.   * @param  None
  128.   * @retval None
  129.   */
  130. void Time_Update(void)
  131. {
  132.   LocalTime += SYSTEMTICK_PERIOD_MS;
  133. }


  134. /**
  135.   * @brief  Handles the periodic tasks of the system
  136.   * @param  None
  137.   * @retval None
  138.   */
  139. void System_Periodic_Handle(void)
  140. {
  141.   /* Update the LCD display and the LEDs status */
  142.   /* Manage the IP address setting */
  143.   Display_Periodic_Handle(LocalTime);
  144.   
  145.   /* LwIP periodic services are done here */
  146.   LwIP_Periodic_Handle(LocalTime);
  147. }


  148. #ifdef  USE_FULL_ASSERT
  149. ……………………

  150. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
智嵌以太网远程更新.7z (6.42 MB, 下载次数: 176)
回复

使用道具 举报

ID:319585 发表于 2018-12-9 14:10 | 显示全部楼层
这个不错的,需要的,我还需要串口通信的例子
回复

使用道具 举报

ID:272158 发表于 2021-8-9 14:57 | 显示全部楼层
我这里油串口通讯的》,智嵌
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表