单片机源程序如下:
- /**
- ******************************************************************************
- * @file main.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 07/16/2010
- * @brief Main program body
- ******************************************************************************
- * @copy
- *
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm32_eth.h"
- #include "ethernetif.h"
- #include "netconf.h"
- #include "main.h"
- #include "httpserver.h"
- #include "tftpserver.h"
- #include "flash_if.h"
- #include <stdio.h>
- #include <usart.h>
- /* Private typedef -----------------------------------------------------------*/
- typedef void (*pFunction)(void);
- /* Private define ------------------------------------------------------------*/
- #define SYSTEMTICK_PERIOD_MS 10
- #define ERR_MESSAGE1 " no user application"
- #define ERR_MESSAGE2 " Detected, Pls Press"
- #define ERR_MESSAGE3 " Key2 while reset to"
- #define ERR_MESSAGE4 " Upload application."
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- __IO uint32_t LocalTime = 0; /* this variable is used to create a time reference incremented by 10ms */
- uint32_t timingdelay;
- pFunction Jump_To_Application;
- uint32_t JumpAddress;
- /* Private function prototypes -----------------------------------------------*/
- void System_Periodic_Handle(void);
- /* Private functions ---------------------------------------------------------*/
- void Show_Msg(void)
- {
- printf("\r\n\n\n ================JISHU %s configured ==============", EVAL_COM1_STR);
- printf("\n\r STM32 Connectivity Line Device\n\r");
- printf("\n\r In-Application Programming (IAP) over Ethernet....\n\r");
- printf("\n\r User Application will be store at addr 0x%x\n\r", USER_FLASH_FIRST_PAGE_ADDRESS);
- //printf("\n\r IP address is: 192.168.1.6\n\r");
- }
- u16 Show_ETH_PHY(u16 PHYRegAddr)
- {
- u16 PHYRegData;
- PHYRegData = ETH_ReadPHYRegister(0,PHYRegAddr);
- printf("\n\rETH_ReadPHYRegister(0,%d):0x%X", PHYRegAddr, PHYRegData);
- return PHYRegData;
- }
- void Check_ETH_PHY(void)
- {
- if(Show_ETH_PHY(17) & 0x3000)
- {
- /* Set Ethernet speed to 10M following the autonegotiation */
- printf("\n\r==>ETH_Speed_10M!");
- }
- else
- {
- /* Set Ethernet speed to 100M following the autonegotiation */
- printf("\n\r==>ETH_Speed_100M!");
- }
- /* Configure the MAC with the Duplex Mode fixed by the autonegotiation process */
- if((Show_ETH_PHY(17) & 0xA000) != (uint32_t)RESET)
- {
- /* Set Ethernet duplex mode to FullDuplex following the autonegotiation */
- printf("\n\r==>ETH_Mode_FullDuplex!");
-
- }
- else
- {
- /* Set Ethernet duplex mode to HalfDuplex following the autonegotiation */
- printf("\n\r==>ETH_Mode_HalfDuplex!");
- }
- }
- void Delay_ARMJISHU(__IO uint32_t nCount)
- {
- for (; nCount != 0; nCount--);
- }
- /**
- * @brief Main program.
- * @param None
- * @retval None
- */
- int main(void)
- {
- static uint32_t addr32;
- /* Initialize Key Button mounted on STM3210C-EVAL board */
- STM_EVAL_PBInit(Button_KEY, Mode_GPIO);
-
- /* Test if Key push-button on STM3210C-EVAL Board is not pressed */
- if (STM_EVAL_PBGetState(Button_KEY) != 0x00)
- { /* Key push-button not pressed: jump to user application */
-
- /* Check if valid stack address (RAM address) then jump to user application */
- if (((*(__IO uint32_t*)USER_FLASH_FIRST_PAGE_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
- {
- STM_EVAL_LEDInit(LED1);
- STM_EVAL_LEDOn(LED1);
-
- addr32 = USER_FLASH_FIRST_PAGE_ADDRESS;
-
- /* Jump to user application */
- JumpAddress = *(__IO uint32_t*) (USER_FLASH_FIRST_PAGE_ADDRESS + 4);
- Jump_To_Application = (pFunction) JumpAddress;
- /* Initialize user application's Stack Pointer */
- __set_MSP(*(__IO uint32_t*) USER_FLASH_FIRST_PAGE_ADDRESS);
- Jump_To_Application();
- }
- else
- {/* Otherwise, do nothing */
- /* LED3 (RED) ON to indicate bad software (when not valid stack address) */
- STM_EVAL_LEDInit(LED3);
- STM_EVAL_LEDOn(LED3);
- USART_COM1_Init();
- printf("\n\r ==>" ERR_MESSAGE1 ERR_MESSAGE2 ERR_MESSAGE3 ERR_MESSAGE4"<==\n\r");
- #ifdef USE_LCD
- /* Initialize the STM3210C-EVAL's LCD */
- STM3210C_LCD_Init();
- #endif
- LCD_DisplayWelcomeStr(Line2);
- LCD_DisplayStringLine(Line4, ERR_MESSAGE1);
- LCD_DisplayStringLine(Line5, ERR_MESSAGE2);
- LCD_DisplayStringLine(Line6, ERR_MESSAGE3);
- LCD_DisplayStringLine(Line7, ERR_MESSAGE4);
- /* do nothing */
- while(1);
- }
- }
- /* enter in IAP mode */
- else
- {
- /* Setup STM32 system (clocks, Ethernet, GPIO, NVIC)
- and STM3210C-EVAL resources */
- System_Setup();
- Show_Msg();
- Check_ETH_PHY();
-
- /* Initilaize the LwIP stack */
- LwIP_Init();
-
- #ifdef USE_IAP_HTTP
- /* Initilaize the webserver module */
- IAP_httpd_init();
- #endif
-
- #ifdef USE_IAP_TFTP
- /* Initialize the TFTP server */
- IAP_tftpd_init();
- #endif
-
- /* Infinite loop */
- while (1)
- {
- /* check if any packet received */
- if (ETH_GetRxPktSize()!=0)
- {
- /* process received eth packet */
- LwIP_Pkt_Handle();
- }
- /* Periodic tasks */
- System_Periodic_Handle();
- }
- }
- return 0;
- }
- /**
- * @brief Inserts a delay time.
- * @param nCount: number of 10ms periods to wait for.
- * @retval None
- */
- void Delay(uint32_t nCount)
- {
- /* Capture the current local time */
- timingdelay = LocalTime + nCount;
- /* wait until the desired delay finish */
- while(timingdelay > LocalTime)
- {
- }
- }
- /**
- * @brief Updates the system local time
- * @param None
- * @retval None
- */
- void Time_Update(void)
- {
- LocalTime += SYSTEMTICK_PERIOD_MS;
- }
- /**
- * @brief Handles the periodic tasks of the system
- * @param None
- * @retval None
- */
- void System_Periodic_Handle(void)
- {
- #ifdef USE_LCD
-
- /* Update the LCD display and the LEDs status */
- /* Manage the IP address setting */
- Display_Periodic_Handle(LocalTime);
-
- #endif
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
HTTP-TFTP-V1.1.rar
(2.9 MB, 下载次数: 14)
|