/** * @brief Display the Main Menu on to HyperTerminal * @param None * @retval None */ void Main_Menu(void) { uint8_t key = 0; /* Get the number of block (4 or 2 pages) from where the user program will be loaded */ BlockNbr = (FlashDestination - 0x08000000) >> 12; /* Compute the mask to test if the Flash memory, where the user program will be loaded, is write protected */ #if defined (STM32F10X_MD) || defined (STM32F10X_MD_VL) UserMemoryMask = ((uint32_t)~((1 << BlockNbr) - 1)); #else /* USE_STM3210E_EVAL */ if (BlockNbr < 62) { UserMemoryMask = ((uint32_t)~((1 << BlockNbr) - 1)); } else { UserMemoryMask = ((uint32_t)0x80000000); } #endif /* (STM32F10X_MD) || (STM32F10X_MD_VL) */ /* Test if any page of Flash memory where program user will be loaded is write protected */ if ((FLASH_GetWriteProtectionOptionByte() & UserMemoryMask) != UserMemoryMask) { FlashProtection = 1; } else { FlashProtection = 0; } while (1) { SerialPutString("\r\n================== Main Menu ============================\r\n\n"); SerialPutString(" Download Image To the STM32F10x Internal Flash ------- 1\r\n\n"); SerialPutString(" Upload Image From the STM32F10x Internal Flash ------- 2\r\n\n"); SerialPutString(" Execute The New Program ------------------------------ 3\r\n\n"); if(FlashProtection != 0) { SerialPutString(" Disable the write protection ------------------------- 4\r\n\n"); } SerialPutString("==========================================================\r\n\n"); key = GetKey(); if (key == 0x31) { /* Download user application in the Flash */ SerialPutString(" File --> Transfer --> YMODEM --> Send... \r\n\n"); SerialDownload(); } else if (key == 0x32) { /* Upload user application from the Flash */ SerialUpload(); } else if (key == 0x33) { JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4); /* Jump to user application */ Jump_To_Application = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ __set_MSP(*(__IO uint32_t*) ApplicationAddress); Jump_To_Application(); } else if ((key == 0x34) && (FlashProtection == 1)) { /* Disable the write protection of desired pages */ FLASH_DisableWriteProtectionPages(); } else { if (FlashProtection == 0) { SerialPutString("Invalid Number ! ==> The number should be either 1, 2 or 3\r"); } else { SerialPutString("Invalid Number ! ==> The number should be either 1, 2, 3 or 4\r"); } } } }
/******************************************************************************* * Function Name : Main_Menu * Description : Display the Main Menu on to HyperTerminal * Input : None * Output : None * Return : None *******************************************************************************/ void Main_Menu(void) { u8 key = 0; /* Get the number of block (4 pages) from where the user program will be loaded */ BlockNbr = (FlashDestination - 0x08000000) >> 12; /* Compute the mask to test if the Flash memory, where the user program will be loaded, is write protected */ UserMemoryMask = ((u32)~((1<<BlockNbr)-1)); /* Test if any page of Flash memory where program user will be loaded is write protected */ if ((FLASH_GetWriteProtectionOptionByte() & UserMemoryMask) != UserMemoryMask) { FlashProtection = TRUE; SerialPutString("\r\n================== Main Menu ============================\r\n\n"); SerialPutString(" Download Image To the STM32F10x Internal Flash ------- 1\r\n\n"); SerialPutString(" Execute The New Program ------------------------------ 2\r\n\n"); SerialPutString(" Disable the write protection ------------------------- 3\r\n\n"); SerialPutString("==========================================================\r\n\n"); } else { FlashProtection = FALSE; SerialPutString("\r\n================== Main Menu ============================\r\n\n"); SerialPutString(" Download Image To the STM32F10x Internal Flash ------- 1\r\n\n"); SerialPutString(" Execute The New Program ------------------------------ 2\r\n\n"); SerialPutString("==========================================================\r\n\n"); } while (1) { // SerialPutString("ready to get choice\r\n"); key = GetKey(); // SerialPutString("\r\n"); // SerialPutChar(key); // SerialPutString("\r\nget choice\r\n"); if (key == 0x31) { /* Download user application in the Flash */ SerialDownload(); } else if (key == 0x32) { JumpAddress = *(vu32*) (ApplicationAddress + 4); //the address value /* Jump to user application */ Jump_To_Application = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ __set_MSP(*(vu32*) ApplicationAddress); Jump_To_Application(); } else if ((key == 0x33)&& (FlashProtection == TRUE)) { /* Disable the write protection of desired pages */ FLASH_DisableWriteProtectionPages(); } else { if(FlashProtection == FALSE) { SerialPutString("Invalid Number ! ==> The number should be either 1 or 2\r\n"); } else { SerialPutString("Invalid Number ! ==> The number should be either 1, 2 or 3\r\n"); } } } }