附IAP远程更新源代码和说明文件
单片机源程序如下:
- /* Includes ------------------------------------------------------------------*/
- #include "stm32_eth.h"
- #include "netconf.h"
- #include "main.h"
- #include "helloworld.h"
- #include "httpd.h"
- #include "tftpserver.h"
- #include "KEY.H"
- #include "stdio.h"
- #include "bkp.h"
- #include "LED.H"
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- #define SYSTEMTICK_PERIOD_MS 10
- #ifdef __GNUC__
- /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
- set to 'Yes') calls __io_putchar() */
- #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
- #else
- #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
- #endif /* __GNUC__ */
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- __IO uint32_t LocalTime = 0; /* this variable is used to create a time reference incremented by 10ms */
- uint32_t timingdelay;
- typedef void (*pFunction)(void);
- pFunction Jump_To_User_Application;
- uint32_t Jump_User_Address;
- /* Private function prototypes -----------------------------------------------*/
- void System_Periodic_Handle(void);
- void IAP_httpd_init(void);
- void IAP_tftpd_init(void);
- void MY_NVIC_Configuration(void);
- void NVIC_DeInit(void);
- void BKP_Configuration(void);
- void MCU_Reset(void);
- void EARES_SRAM(void);
- void NVIC_Configuration(void);
- /* Private functions ---------------------------------------------------------*/
- /**
- * @brief Main program.
- * @param None
- * @retval None
- */
-
- int main(void)
- {
- unsigned int g_bUpdateFlag = 0;
- NVIC_DeInit();
- RCC_DeInit();
- SystemInit();
- BKP_Configuration();
- NVIC_Configuration();
- SEI(); //开全局中断
- g_bUpdateFlag = BKP_ReadBackupRegister(BKP_DR9); //读取更新标志
- //if(!(KEY1 | KEY2 | KEY3 | KEY4)
- if(g_bUpdateFlag == 0x0) //不需要升级,
- {
- /* Check if valid stack address (RAM address) then jump to user application */
- if (((*(__IO uint32_t*)USER_FLASH_FIRST_PAGE_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
- {
- CLI(); //关闭总中断,必须有、
- NVIC_DeInit();
- RCC_DeInit();
- /* Jump to user application */
- Jump_User_Address = *(__IO uint32_t*) (USER_FLASH_FIRST_PAGE_ADDRESS + 4);
- Jump_To_User_Application = (pFunction) Jump_User_Address;
- /* Initialize user application's Stack Pointer */
- __set_MSP(*(__IO uint32_t*) USER_FLASH_FIRST_PAGE_ADDRESS);
- Jump_To_User_Application();
- while (1);
- }
- else
- {
- //printf("非法SRAM\n");
- }
- }
-
- else //初始化网络模块,等待用户远程登录,更新固件
- {
- /* Setup STM32 system (clocks, Ethernet, GPIO, NVIC) and STM3210C-EVAL resources */
- BKP_WriteBackupRegister(BKP_DR9,0x00);// 标志已经下载了程序了
- System_Setup();
- /* Initilaize the LwIP satck ip地址设置,mac设置,*/
- LwIP_Init();
-
- IAP_httpd_init();
- /* Infinite loop */
- while (1)
- {
- /* Periodic tasks */
- System_Periodic_Handle();
- }
- }
- }
- void MCU_Reset(void)
- {
- __disable_fault_irq(); // STM32 软复位
- NVIC_SystemReset();
- }
- PUTCHAR_PROTOTYPE
- {
- /* Place your implementation of fputc here */
- /* e.g. write a character to the USART */
- USART_SendData(USART2, (uint8_t) ch);
- /* Loop until the end of transmission */
- while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET)
- {}
- return ch;
- }
- /**
- * @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)
- {
- /* Update the LCD display and the LEDs status */
- /* Manage the IP address setting */
- Display_Periodic_Handle(LocalTime);
-
- /* LwIP periodic services are done here */
- LwIP_Periodic_Handle(LocalTime);
- }
- #ifdef USE_FULL_ASSERT
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
智嵌以太网远程更新.7z
(6.42 MB, 下载次数: 176)
|