找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2549|回复: 0
打印 上一主题 下一主题
收起左侧

神舟IV号开发板以太网IAP固件升级功能演示及源代码

[复制链接]
跳转到指定楼层
楼主


单片机源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * @file    main.c
  4.   * @author  MCD Application Team
  5.   * @version V1.0.0
  6.   * @date    07/16/2010
  7.   * @brief   Main program body
  8.   ******************************************************************************
  9.   * @copy
  10.   *
  11.   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12.   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13.   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  14.   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15.   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16.   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17.   *
  18.   * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
  19.   */

  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32_eth.h"
  22. #include "ethernetif.h"
  23. #include "netconf.h"
  24. #include "main.h"
  25. #include "httpserver.h"
  26. #include "tftpserver.h"
  27. #include "flash_if.h"
  28. #include <stdio.h>
  29. #include <usart.h>

  30. /* Private typedef -----------------------------------------------------------*/
  31. typedef  void (*pFunction)(void);

  32. /* Private define ------------------------------------------------------------*/
  33. #define SYSTEMTICK_PERIOD_MS  10

  34. #define ERR_MESSAGE1   " no user application"
  35. #define ERR_MESSAGE2   " Detected, Pls Press"
  36. #define ERR_MESSAGE3   " Key2 while reset to"
  37. #define ERR_MESSAGE4   " Upload application."
  38. /* Private macro -------------------------------------------------------------*/
  39. /* Private variables ---------------------------------------------------------*/
  40. __IO uint32_t LocalTime = 0; /* this variable is used to create a time reference incremented by 10ms */
  41. uint32_t timingdelay;
  42. pFunction Jump_To_Application;
  43. uint32_t JumpAddress;

  44. /* Private function prototypes -----------------------------------------------*/
  45. void System_Periodic_Handle(void);

  46. /* Private functions ---------------------------------------------------------*/

  47. void Show_Msg(void)
  48. {
  49.     printf("\r\n\n\n ================JISHU  %s configured ==============", EVAL_COM1_STR);
  50.     printf("\n\r STM32 Connectivity Line Device\n\r");
  51.     printf("\n\r In-Application Programming (IAP) over Ethernet....\n\r");
  52.     printf("\n\r User Application will be store at addr 0x%x\n\r", USER_FLASH_FIRST_PAGE_ADDRESS);
  53.     //printf("\n\r IP address is: 192.168.1.6\n\r");
  54. }

  55. u16 Show_ETH_PHY(u16 PHYRegAddr)
  56. {
  57.   u16 PHYRegData;
  58.   PHYRegData = ETH_ReadPHYRegister(0,PHYRegAddr);
  59.   printf("\n\rETH_ReadPHYRegister(0,%d):0x%X", PHYRegAddr, PHYRegData);
  60.   return PHYRegData;
  61. }

  62. void Check_ETH_PHY(void)
  63. {
  64.     if(Show_ETH_PHY(17) & 0x3000)
  65.     {  
  66.       /* Set Ethernet speed to 10M following the autonegotiation */   
  67.       printf("\n\r==>ETH_Speed_10M!");
  68.     }
  69.     else
  70.     {   
  71.       /* Set Ethernet speed to 100M following the autonegotiation */
  72.       printf("\n\r==>ETH_Speed_100M!");     
  73.     }
  74.     /* Configure the MAC with the Duplex Mode fixed by the autonegotiation process */
  75.     if((Show_ETH_PHY(17) & 0xA000) != (uint32_t)RESET)
  76.     {
  77.       /* Set Ethernet duplex mode to FullDuplex following the autonegotiation */
  78.       printf("\n\r==>ETH_Mode_FullDuplex!");
  79.             
  80.     }
  81.     else
  82.     {
  83.       /* Set Ethernet duplex mode to HalfDuplex following the autonegotiation */
  84.       printf("\n\r==>ETH_Mode_HalfDuplex!");
  85.     }
  86. }


  87. void Delay_ARMJISHU(__IO uint32_t nCount)
  88. {
  89.   for (; nCount != 0; nCount--);
  90. }


  91. /**
  92.   * @brief  Main program.
  93.   * @param  None
  94.   * @retval None
  95.   */
  96. int main(void)
  97. {
  98.   static uint32_t addr32;
  99.   /* Initialize Key Button mounted on STM3210C-EVAL board */      
  100.   STM_EVAL_PBInit(Button_KEY, Mode_GPIO);   
  101.   
  102.   /* Test if Key push-button on STM3210C-EVAL Board is not pressed */
  103.   if (STM_EVAL_PBGetState(Button_KEY) != 0x00)
  104.   { /* Key push-button not pressed: jump to user application */
  105.   
  106.     /* Check if valid stack address (RAM address) then jump to user application */
  107.     if (((*(__IO uint32_t*)USER_FLASH_FIRST_PAGE_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
  108.     {
  109.       STM_EVAL_LEDInit(LED1);
  110.       STM_EVAL_LEDOn(LED1);
  111.       
  112.       addr32 = USER_FLASH_FIRST_PAGE_ADDRESS;
  113.       
  114.       /* Jump to user application */
  115.       JumpAddress = *(__IO uint32_t*) (USER_FLASH_FIRST_PAGE_ADDRESS + 4);
  116.       Jump_To_Application = (pFunction) JumpAddress;
  117.       /* Initialize user application's Stack Pointer */
  118.       __set_MSP(*(__IO uint32_t*) USER_FLASH_FIRST_PAGE_ADDRESS);
  119.       Jump_To_Application();
  120.     }
  121.     else
  122.     {/* Otherwise, do nothing */
  123.       /* LED3 (RED) ON to indicate bad software (when not valid stack address) */
  124.       STM_EVAL_LEDInit(LED3);
  125.       STM_EVAL_LEDOn(LED3);

  126.       USART_COM1_Init();
  127.       printf("\n\r ==>" ERR_MESSAGE1 ERR_MESSAGE2 ERR_MESSAGE3 ERR_MESSAGE4"<==\n\r");
  128.       #ifdef USE_LCD
  129.         /* Initialize the STM3210C-EVAL's LCD */
  130.         STM3210C_LCD_Init();
  131.       #endif
  132.       LCD_DisplayWelcomeStr(Line2);
  133.       LCD_DisplayStringLine(Line4, ERR_MESSAGE1);   
  134.       LCD_DisplayStringLine(Line5, ERR_MESSAGE2);
  135.       LCD_DisplayStringLine(Line6, ERR_MESSAGE3);
  136.       LCD_DisplayStringLine(Line7, ERR_MESSAGE4);
  137.       /* do nothing */
  138.       while(1);
  139.     }
  140.   }
  141.   /* enter in IAP mode */
  142.   else
  143.   {
  144.     /* Setup STM32 system (clocks, Ethernet, GPIO, NVIC)
  145.                             and STM3210C-EVAL resources */
  146.     System_Setup();

  147.     Show_Msg();
  148.     Check_ETH_PHY();
  149.   
  150.     /* Initilaize the LwIP stack */
  151.     LwIP_Init();
  152.    
  153. #ifdef USE_IAP_HTTP
  154.     /* Initilaize the webserver module */
  155.     IAP_httpd_init();
  156. #endif
  157.   
  158. #ifdef USE_IAP_TFTP   
  159.     /* Initialize the TFTP server */
  160.     IAP_tftpd_init();
  161. #endif   
  162.    
  163.     /* Infinite loop */
  164.     while (1)
  165.     {
  166.       /* check if any packet received */
  167.       if (ETH_GetRxPktSize()!=0)
  168.       {
  169.         /* process received eth packet */
  170.         LwIP_Pkt_Handle();
  171.       }
  172.       /* Periodic tasks */
  173.       System_Periodic_Handle();
  174.     }
  175.   }
  176.   return 0;
  177. }

  178. /**
  179.   * @brief  Inserts a delay time.
  180.   * @param  nCount: number of 10ms periods to wait for.
  181.   * @retval None
  182.   */
  183. void Delay(uint32_t nCount)
  184. {
  185.   /* Capture the current local time */
  186.   timingdelay = LocalTime + nCount;  

  187.   /* wait until the desired delay finish */  
  188.   while(timingdelay > LocalTime)
  189.   {     
  190.   }
  191. }

  192. /**
  193.   * @brief  Updates the system local time
  194.   * @param  None
  195.   * @retval None
  196.   */
  197. void Time_Update(void)
  198. {
  199.   LocalTime += SYSTEMTICK_PERIOD_MS;
  200. }

  201. /**
  202.   * @brief  Handles the periodic tasks of the system
  203.   * @param  None
  204.   * @retval None
  205.   */
  206. void System_Periodic_Handle(void)
  207. {
  208. #ifdef USE_LCD
  209.   
  210.   /* Update the LCD display and the LEDs status */
  211.   /* Manage the IP address setting */
  212.   Display_Periodic_Handle(LocalTime);
  213.   
  214. #endif
  215. ……………………

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

所有资料51hei提供下载:
HTTP-TFTP-V1.1.rar (2.9 MB, 下载次数: 14)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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