486 lines
13 KiB
C
486 lines
13 KiB
C
|
/*******************************************************************************
|
|||
|
** <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>: common.c
|
|||
|
** <EFBFBD>汾<EFBFBD><EFBFBD> 1.0
|
|||
|
** <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: RealView MDK-ARM 4.14
|
|||
|
** <EFBFBD><EFBFBD><EFBFBD><EFBFBD>: wuguoyana
|
|||
|
** <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 2011-04-29
|
|||
|
** <EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾһϵ<EFBFBD>в<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
ִ<EFBFBD><EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD>ֹд<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Flash<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<EFBFBD><EFBFBD>
|
|||
|
** <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>: common.h<EFBFBD><EFBFBD>ymodem.h
|
|||
|
** <EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><EFBFBD> 2011-04-29 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD> *****************************************************************/
|
|||
|
#include "common.h"
|
|||
|
#include "stm32f10x_flash.h"
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD> ----------------------------------------------------------------------*/
|
|||
|
pFunction Jump_To_Application;
|
|||
|
uint32_t JumpAddress;
|
|||
|
uint32_t BlockNbr = 0, UserMemoryMask = 0;
|
|||
|
__IO uint32_t FlashProtection = 0;
|
|||
|
uint32_t FlashDestination;
|
|||
|
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Int2Str
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> intnum:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> str<EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
void Int2Str(uint8_t* str, int32_t intnum)
|
|||
|
{
|
|||
|
uint32_t i, Div = 1000000000, j = 0, Status = 0;
|
|||
|
|
|||
|
for (i = 0; i < 10; i++)
|
|||
|
{
|
|||
|
str[j++] = (intnum / Div) + 48;
|
|||
|
|
|||
|
intnum = intnum % Div;
|
|||
|
Div /= 10;
|
|||
|
if ((str[j-1] == '0') & (Status == 0))
|
|||
|
{
|
|||
|
j = 0;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Status++;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Int2Str
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD> <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> inputstr:<EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> intnum<EFBFBD><EFBFBD>ת<EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD> ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ
|
|||
|
0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
uint32_t Str2Int(uint8_t *inputstr, int32_t *intnum)
|
|||
|
{
|
|||
|
uint32_t i = 0, res = 0;
|
|||
|
uint32_t val = 0;
|
|||
|
|
|||
|
if (inputstr[0] == '0' && (inputstr[1] == 'x' || inputstr[1] == 'X'))
|
|||
|
{
|
|||
|
if (inputstr[2] == '\0')
|
|||
|
{
|
|||
|
return 0;
|
|||
|
}
|
|||
|
for (i = 2; i < 11; i++)
|
|||
|
{
|
|||
|
if (inputstr[i] == '\0')
|
|||
|
{
|
|||
|
*intnum = val;
|
|||
|
//<2F><><EFBFBD><EFBFBD>1
|
|||
|
res = 1;
|
|||
|
break;
|
|||
|
}
|
|||
|
if (ISVALIDHEX(inputstr[i]))
|
|||
|
{
|
|||
|
val = (val << 4) + CONVERTHEX(inputstr[i]);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//<2F><>Ч<EFBFBD><D0A7><EFBFBD>뷵<EFBFBD><EBB7B5>0
|
|||
|
res = 0;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (i >= 11)
|
|||
|
{
|
|||
|
res = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
else//<2F><><EFBFBD><EFBFBD>10Ϊ2<CEAA><32><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
for (i = 0; i < 11; i++)
|
|||
|
{
|
|||
|
if (inputstr[i] == '\0')
|
|||
|
{
|
|||
|
*intnum = val;
|
|||
|
//<2F><><EFBFBD><EFBFBD>1
|
|||
|
res = 1;
|
|||
|
break;
|
|||
|
}
|
|||
|
else if ((inputstr[i] == 'k' || inputstr[i] == 'K') && (i > 0))
|
|||
|
{
|
|||
|
val = val << 10;
|
|||
|
*intnum = val;
|
|||
|
res = 1;
|
|||
|
break;
|
|||
|
}
|
|||
|
else if ((inputstr[i] == 'm' || inputstr[i] == 'M') && (i > 0))
|
|||
|
{
|
|||
|
val = val << 20;
|
|||
|
*intnum = val;
|
|||
|
res = 1;
|
|||
|
break;
|
|||
|
}
|
|||
|
else if (ISVALIDDEC(inputstr[i]))
|
|||
|
{
|
|||
|
val = val * 10 + CONVERTDEC(inputstr[i]);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//<2F><>Ч<EFBFBD><D0A7><EFBFBD>뷵<EFBFBD><EBB7B5>0
|
|||
|
res = 0;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F><><EFBFBD><EFBFBD>10λ<30><CEBB>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
|||
|
if (i >= 11)
|
|||
|
{
|
|||
|
res = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return res;
|
|||
|
}
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Int2Str
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD> <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> inputstr:<EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> intnum<EFBFBD><EFBFBD>ת<EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD> ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ
|
|||
|
0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
/**
|
|||
|
* @brief Get an integer from the HyperTerminal
|
|||
|
* @param num: The inetger
|
|||
|
* @retval 1: Correct
|
|||
|
* 0: Error
|
|||
|
*/
|
|||
|
uint32_t GetIntegerInput(int32_t * num)
|
|||
|
{
|
|||
|
uint8_t inputstr[16];
|
|||
|
|
|||
|
while (1)
|
|||
|
{
|
|||
|
GetInputString(inputstr);
|
|||
|
if (inputstr[0] == '\0') continue;
|
|||
|
if ((inputstr[0] == 'a' || inputstr[0] == 'A') && inputstr[1] == '\0')
|
|||
|
{
|
|||
|
SerialPutString("User Cancelled \r\n");
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
if (Str2Int(inputstr, num) == 0)
|
|||
|
{
|
|||
|
SerialPutString("Error, Input again: \r\n");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return 1;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> SerialKeyPressed
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>Գ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ն<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>а<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> key:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD> 1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ
|
|||
|
0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
uint32_t SerialKeyPressed(uint8_t *key)
|
|||
|
{
|
|||
|
|
|||
|
if ( USART_GetFlagStatus(USART1, USART_FLAG_RXNE) != RESET)
|
|||
|
{
|
|||
|
*key = (uint8_t)USART1->DR;
|
|||
|
return 1;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GetKey
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD> ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϻ<EFBFBD>ȥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>µļ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
uint8_t GetKey(void)
|
|||
|
{
|
|||
|
uint8_t key = 0;
|
|||
|
|
|||
|
//<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
while (1)
|
|||
|
{
|
|||
|
if (SerialKeyPressed((uint8_t*)&key)) break;
|
|||
|
}
|
|||
|
return key;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> SerialPutChar
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> C:<EFBFBD>跢<EFBFBD>͵<EFBFBD><EFBFBD>ַ<EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> i<EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
void SerialPutChar(uint8_t c)
|
|||
|
{
|
|||
|
USART_SendData(USART1, c);
|
|||
|
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
|
|||
|
{
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> SerialPutChar
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *s:<EFBFBD>跢<EFBFBD>͵<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
void Serial_PutString(uint8_t *s)
|
|||
|
{
|
|||
|
while (*s != '\0')
|
|||
|
{
|
|||
|
SerialPutChar(*s);
|
|||
|
s++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GetInputString
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD> <EFBFBD>Ӵ<EFBFBD><EFBFBD>ڻ<EFBFBD>ȡһ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *s:<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ַ
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
void GetInputString (uint8_t * buffP)
|
|||
|
{
|
|||
|
uint32_t bytes_read = 0;
|
|||
|
uint8_t c = 0;
|
|||
|
do
|
|||
|
{
|
|||
|
c = GetKey();
|
|||
|
if (c == '\r')
|
|||
|
break;
|
|||
|
if (c == '\b')// Backspace <20><><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
if (bytes_read > 0)
|
|||
|
{
|
|||
|
SerialPutString("\b \b");
|
|||
|
bytes_read --;
|
|||
|
}
|
|||
|
continue;
|
|||
|
}
|
|||
|
if (bytes_read >= CMD_STRING_SIZE )
|
|||
|
{
|
|||
|
SerialPutString("Command string size overflow\r\n");
|
|||
|
bytes_read = 0;
|
|||
|
continue;
|
|||
|
}
|
|||
|
if (c >= 0x20 && c <= 0x7E)
|
|||
|
{
|
|||
|
buffP[bytes_read++] = c;
|
|||
|
SerialPutChar(c);
|
|||
|
}
|
|||
|
}
|
|||
|
while (1);
|
|||
|
SerialPutString(("\n\r"));
|
|||
|
buffP[bytes_read] = '\0';
|
|||
|
}
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> FLASH_PagesMask
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Falshҳ
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Size:<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD> ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
uint32_t FLASH_PagesMask(__IO uint32_t Size)
|
|||
|
{
|
|||
|
uint32_t pagenumber = 0x0;
|
|||
|
uint32_t size = Size;
|
|||
|
|
|||
|
if ((size % PAGE_SIZE) != 0)
|
|||
|
{
|
|||
|
pagenumber = (size / PAGE_SIZE) + 1;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
pagenumber = size / PAGE_SIZE;
|
|||
|
}
|
|||
|
return pagenumber;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> FLASH_DisableWriteProtectionPages
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD> <EFBFBD>Ӵ<EFBFBD>Flashд<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
|
|||
|
void FLASH_DisableWriteProtectionPages(void)
|
|||
|
{
|
|||
|
uint32_t useroptionbyte = 0, WRPR = 0;
|
|||
|
uint16_t var1 = OB_IWDG_SW, var2 = OB_STOP_NoRST, var3 = OB_STDBY_NoRST;
|
|||
|
FLASH_Status status = FLASH_BUSY;
|
|||
|
|
|||
|
WRPR = FLASH_GetWriteProtectionOptionByte();
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
|||
|
if ((WRPR & UserMemoryMask) != UserMemoryMask)
|
|||
|
{
|
|||
|
useroptionbyte = FLASH_GetUserOptionByte();
|
|||
|
|
|||
|
UserMemoryMask |= WRPR;
|
|||
|
|
|||
|
status = FLASH_EraseOptionBytes();
|
|||
|
|
|||
|
if (UserMemoryMask != 0xFFFFFFFF)
|
|||
|
{
|
|||
|
status = FLASH_EnableWriteProtection((uint32_t)~UserMemoryMask);
|
|||
|
}
|
|||
|
//<2F>ô<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>б<EFBFBD><D0B1><EFBFBD>
|
|||
|
if ((useroptionbyte & 0x07) != 0x07)
|
|||
|
{
|
|||
|
//<2F><><EFBFBD>±<EFBFBD><C2B1><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>
|
|||
|
if ((useroptionbyte & 0x01) == 0x0)
|
|||
|
{
|
|||
|
var1 = OB_IWDG_HW;
|
|||
|
}
|
|||
|
if ((useroptionbyte & 0x02) == 0x0)
|
|||
|
{
|
|||
|
var2 = OB_STOP_RST;
|
|||
|
}
|
|||
|
if ((useroptionbyte & 0x04) == 0x0)
|
|||
|
{
|
|||
|
var3 = OB_STDBY_RST;
|
|||
|
}
|
|||
|
|
|||
|
FLASH_UserOptionByteConfig(var1, var2, var3);
|
|||
|
}
|
|||
|
|
|||
|
if (status == FLASH_COMPLETE)
|
|||
|
{
|
|||
|
SerialPutString("Write Protection disabled...\r\n");
|
|||
|
|
|||
|
SerialPutString("...and a System Reset will be generated to re-load the new option bytes\r\n");
|
|||
|
//ϵͳ<CFB5><CDB3>λ<EFBFBD><CEBB><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>
|
|||
|
NVIC_SystemReset();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SerialPutString("Error: Flash write unprotection failed...\r\n");
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SerialPutString("Flash memory not write protected\r\n");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Main_Menu
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ʾ<EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ն<EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* @<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
void Main_Menu(void)
|
|||
|
{
|
|||
|
uint8_t key = 0;
|
|||
|
BlockNbr = (FlashDestination - 0x08000000) >> 12;
|
|||
|
|
|||
|
|
|||
|
#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) */
|
|||
|
|
|||
|
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)
|
|||
|
{
|
|||
|
//<2F><><EFBFBD>س<EFBFBD><D8B3><EFBFBD>
|
|||
|
// SerialDownload();
|
|||
|
}
|
|||
|
else if (key == 0x32)
|
|||
|
{
|
|||
|
//<2F>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// SerialUpload();
|
|||
|
}
|
|||
|
else if (key == 0x33)
|
|||
|
{
|
|||
|
SerialPutString("Execute user Program\r\n\n");
|
|||
|
JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
|
|||
|
|
|||
|
//<2F><>ת<EFBFBD><D7AA><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
Jump_To_Application = (pFunction) JumpAddress;
|
|||
|
//<2F><>ʼ<EFBFBD><CABC><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD>ջָ<D5BB><D6B8>
|
|||
|
__set_MSP(*(__IO uint32_t*) ApplicationAddress);
|
|||
|
Jump_To_Application();
|
|||
|
}
|
|||
|
else if ((key == 0x34) && (FlashProtection == 1))
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
|||
|
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");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*******************************<2A>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>***************************************/
|