学前班
最后登录1970-1-1
在线时间 小时
注册时间2015-6-8
|
请问一下下列程序中的cal_flag==0xcc是什么意思??怎么得到的??
/**
******************************************************************************
* @file main.c
* @author fire
* @version V1.0
* @date 2013-xx-xx
* @brief »a°î 2M′®DDflash2aêÔ£¬2¢½«2aêÔDÅÏ¢í¨1y′®¿ú1ÔúμçÄÔμÄ3¬¼¶ÖÕ¶ËÖD′òó¡3öà′
******************************************************************************
* @attention
*
* êμÑéƽì¨:ò°»e iSO-MINI STM32 ¿a·¢°å
* ÂÛì3 :http://www.firebbs.cn
* ìÔ±| :http://firestm32.taobao.com
*
******************************************************************************
*/
#include "stm32f10x.h"
#include "bsp_usart1.h"
#include "bsp_spi_flash.h"
typedef enum { FAILED = 0, PASSED = !FAILED} TestStatus;
/* »ñè¡»o3åÇøμÄ3¤¶è */
#define TxBufferSize1 (countof(TxBuffer1) - 1)
#define RxBufferSize1 (countof(TxBuffer1) - 1)
#define countof(a) (sizeof(a) / sizeof(*(a)))
#define BufferSize (countof(Tx_Buffer)-1)
#define FLASH_WriteAddress 0x00000
#define FLASH_ReadAddress FLASH_WriteAddress
#define FLASH_SectorToErase FLASH_WriteAddress
//#define sFLASH_ID 0xEF3015 //W25X16
//#define sFLASH_ID 0xEF4015 //W25Q16
#define sFLASH_ID 0xEF4017 //W25Q64
/* ·¢Ëí»o3åÇø3õê¼»ˉ */
//uint8_t Tx_Buffer[] = " ¸DD»ÄúÑ¡óÃò°»estm32¿a·¢°å\r\n http://firestm32.taobao.com";
//uint8_t Rx_Buffer[BufferSize];
long double Tx_Buffer[7] = {0};
long double Rx_Buffer[7] = {0};
uint8_t cal_flag = 0;
uint8_t cal_f = 0;
__IO uint32_t DeviceID = 0;
__IO uint32_t FlashID = 0;
__IO TestStatus TransferStatus1 = FAILED;
// oˉêyÔ-DíéùÃ÷
void Delay(__IO uint32_t nCount);
TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength);
/*
* oˉêyÃû£omain
* Ãèêö £oÖ÷oˉêy
* êäèë £oÎT
* êä3ö £oÎT
*/
int main(void)
{
uint8_t k;
/* ÅäÖÃ′®¿ú1Îa£o115200 8-N-1 */
USART1_Config();
printf("\r\n ÕaêÇò»¸ö8M′®DDflash(W25Q64)êμÑé \r\n");
/* 8M′®DDflash W25X643õê¼»ˉ */
SPI_FLASH_Init();
/* Get SPI Flash Device ID */
DeviceID = SPI_FLASH_ReadDeviceID();
Delay( 200 );
/* Get SPI Flash ID */
FlashID = SPI_FLASH_ReadID();
printf("\r\n FlashID is 0x%X, Manufacturer Device ID is 0x%X\r\n", FlashID, DeviceID);
/* Check the SPI Flash ID */
if (FlashID == sFLASH_ID) /* #define sFLASH_ID 0xEF4017 */
{
printf("\r\n ¼ì2aμ½»a°î′®DDflash W25Q64 !\r\n");
#if 0
/* ½«·¢Ëí»o3åÇøμÄêy¾YD′μ½flashÖD */
SPI_FLASH_BufferWrite((void*)Tx_Buffer, FLASH_WriteAddress, sizeof(Tx_Buffer));
for( k=0; k<7; k++ )
printf("\r\n D′èëμÄêy¾YÎa£o%LF \r\n", Tx_Buffer[k]);
/* ½«¸Õ¸ÕD′èëμÄêy¾Y¶á3öà′·Åμ½½óêÕ»o3åÇøÖD */
SPI_FLASH_BufferRead((void*)Rx_Buffer, FLASH_ReadAddress, sizeof(Rx_Buffer));
for( k=0; k<7; k++ )
printf("\r\n ¶á3öμÄêy¾YÎa£o%LF \r\n", Rx_Buffer[k]);
#elif 1
SPI_FLASH_BufferRead(&cal_flag, 0, 1);
if( cal_flag == 0xCC )
{
// SPI_FLASH_BufferRead((void*)Rx_Buffer, 1, sizeof(Rx_Buffer));
// for( k=0; k<7; k++ )
// printf("\r\n rx = %LF \r\n",Rx_Buffer[k]);
SPI_FLASH_BufferRead((void*)Tx_Buffer, 1, sizeof(Tx_Buffer));
for( k=0; k<7; k++ )
printf("\r\n rx = %LF \r\n",Tx_Buffer[k]);
}
else
{
cal_flag = 0xCC;
SPI_FLASH_SectorErase(0);
SPI_FLASH_BufferWrite(&cal_flag, 0, 1);
for( k=0; k<7; k++ )
Tx_Buffer[k] = k +0.1;
SPI_FLASH_BufferWrite((void*)Tx_Buffer, 1, sizeof(Tx_Buffer));
for( k=0; k<7; k++ )
printf("\r\n tx = %LF \r\n",Tx_Buffer[k]);
}
#endif
#if 0
/* ¼ì2éD′èëμÄêy¾Yóë¶á3öμÄêy¾YêÇ·ñÏàμè */
TransferStatus1 = Buffercmp((void*)Tx_Buffer, (void*)Rx_Buffer, BufferSize);
if( PASSED == TransferStatus1 )
{
printf("\r\n 8M′®DDflash(W25Q64)2aêÔ3é1|!\n\r");
}
else
{
printf("\r\n 8M′®DDflash(W25Q64)2aêÔ꧰ü!\n\r");
}
#endif
}// if (FlashID == sFLASH_ID)
else
{
printf("\r\n »ñè¡2»μ½ W25Q64 ID!\n\r");
}
SPI_Flash_PowerDown();
while(1);
}
/*
* oˉêyÃû£oBuffercmp
* Ãèêö £o±è½Ïὸö»o3åÇøÖDμÄêy¾YêÇ·ñÏàμè
* êäèë £o-pBuffer1 src»o3åÇøÖ¸Õë
* -pBuffer2 dst»o3åÇøÖ¸Õë
* -BufferLength »o3åÇø3¤¶è
* êä3ö £oÎT
* ·μ»Ø £o-PASSED pBuffer1 μèóú pBuffer2
* -FAILED pBuffer1 2»í¬óú pBuffer2
*/
TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength)
{
while(BufferLength--)
{
if(*pBuffer1 != *pBuffer2)
{
return FAILED;
}
pBuffer1++;
pBuffer2++;
}
return PASSED;
}
void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
/*********************************************END OF FILE**********************/
|
|