168 lines
5.2 KiB
C
168 lines
5.2 KiB
C
|
/**
|
|||
|
******************************************************************
|
|||
|
* @file main.c
|
|||
|
* @author fire
|
|||
|
* @version V1.0
|
|||
|
* @date 2018-xx-xx
|
|||
|
* @brief QSPI FLASH<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
******************************************************************
|
|||
|
* @attention
|
|||
|
*
|
|||
|
* ʵ<EFBFBD><EFBFBD>ƽ̨:Ұ<EFBFBD><EFBFBD> STM32H743<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD>̳ :http://www.firebbs.cn
|
|||
|
* <EFBFBD>Ա<EFBFBD> :http://firestm32.taobao.com
|
|||
|
*
|
|||
|
******************************************************************
|
|||
|
*/
|
|||
|
#include "stm32h7xx.h"
|
|||
|
#include "main.h"
|
|||
|
#include "bsp_debug_usart.h"
|
|||
|
#include "FlashOS.H" // FlashOS Structures
|
|||
|
#include "bsp_led.h"
|
|||
|
|
|||
|
typedef enum { FAILED = 0, PASSED = !FAILED} TestStatus;
|
|||
|
/* <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD> */
|
|||
|
#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 0
|
|||
|
#define FLASH_ReadAddress FLASH_WriteAddress
|
|||
|
#define FLASH_SectorToErase FLASH_WriteAddress
|
|||
|
|
|||
|
|
|||
|
/* <20><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC> */
|
|||
|
volatile uint8_t Tx_Buffer[256] = "<EFBFBD><EFBFBD>л<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>Ұ<EFBFBD><EFBFBD>stm32<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\nhttp://firestm32.taobao.com";
|
|||
|
volatile uint8_t Rx_Buffer[BufferSize];
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1>ID<49>洢λ<E6B4A2><CEBB>
|
|||
|
__IO uint32_t DeviceID = 0;
|
|||
|
__IO uint32_t FlashID = 0;
|
|||
|
__IO TestStatus TransferStatus1 = FAILED;
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void Delay(__IO uint32_t nCount);
|
|||
|
|
|||
|
extern uint32_t QSPI_Init(void);
|
|||
|
extern uint32_t QSPI_WritePage(unsigned long adr, unsigned long sz, unsigned char *buf);
|
|||
|
extern uint32_t QSPI_ReadPage(unsigned long adr, unsigned long sz, unsigned char *buf);
|
|||
|
extern uint32_t QSPI_EraseSector(uint32_t adr);
|
|||
|
|
|||
|
TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param <EFBFBD><EFBFBD>
|
|||
|
* @retval <EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
int main(void)
|
|||
|
{
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>ѡ<EFBFBD><D1A1>λalgorithm_debug<75><67><EFBFBD><EFBFBD><EFBFBD>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>debug״̬ */
|
|||
|
/* <20>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㷨<EFBFBD><E3B7A8><EFBFBD>̲<EFBFBD><CCB2><EFBFBD> */
|
|||
|
HAL_Init();
|
|||
|
SystemClock_Config();
|
|||
|
while(1);
|
|||
|
}
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Buffercmp
|
|||
|
* <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>-pBuffer1 src<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
|
|||
|
* -pBuffer2 dst<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
|
|||
|
* -BufferLength <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>-PASSED pBuffer1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD> pBuffer2
|
|||
|
* -FAILED pBuffer1 <EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD> 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--);
|
|||
|
}
|
|||
|
/**
|
|||
|
* @brief System Clock <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* system Clock <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
|
|||
|
* System Clock source = PLL (HSE)
|
|||
|
* SYSCLK(Hz) = 400000000 (CPU Clock)
|
|||
|
* HCLK(Hz) = 200000000 (AXI and AHBs Clock)
|
|||
|
* AHB Prescaler = 2
|
|||
|
* D1 APB3 Prescaler = 2 (APB3 Clock 100MHz)
|
|||
|
* D2 APB1 Prescaler = 2 (APB1 Clock 100MHz)
|
|||
|
* D2 APB2 Prescaler = 2 (APB2 Clock 100MHz)
|
|||
|
* D3 APB4 Prescaler = 2 (APB4 Clock 100MHz)
|
|||
|
* HSE Frequency(Hz) = 25000000
|
|||
|
* PLL_M = 5
|
|||
|
* PLL_N = 160
|
|||
|
* PLL_P = 2
|
|||
|
* PLL_Q = 4
|
|||
|
* PLL_R = 2
|
|||
|
* VDD(V) = 3.3
|
|||
|
* Flash Latency(WS) = 4
|
|||
|
* @param None
|
|||
|
* @retval None
|
|||
|
*/
|
|||
|
static void SystemClock_Config(void)
|
|||
|
{
|
|||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|||
|
|
|||
|
/** Supply configuration update enable
|
|||
|
*/
|
|||
|
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
|
|||
|
/** Configure the main internal regulator output voltage
|
|||
|
*/
|
|||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
|
|||
|
|
|||
|
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
|
|||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
|||
|
* in the RCC_OscInitTypeDef structure.
|
|||
|
*/
|
|||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|||
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|||
|
RCC_OscInitStruct.PLL.PLLM = 5;
|
|||
|
RCC_OscInitStruct.PLL.PLLN = 192;
|
|||
|
RCC_OscInitStruct.PLL.PLLP = 2;
|
|||
|
RCC_OscInitStruct.PLL.PLLQ = 2;
|
|||
|
RCC_OscInitStruct.PLL.PLLR = 2;
|
|||
|
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
|
|||
|
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
|||
|
RCC_OscInitStruct.PLL.PLLFRACN = 0;
|
|||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|||
|
{
|
|||
|
while(1);
|
|||
|
}
|
|||
|
/** Initializes the CPU, AHB and APB buses clocks
|
|||
|
*/
|
|||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|
|||
|
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
|
|||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|||
|
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
|
|||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
|
|||
|
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
|
|||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
|
|||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
|
|||
|
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
|
|||
|
|
|||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
|||
|
{
|
|||
|
while(1);
|
|||
|
}
|
|||
|
}
|
|||
|
/****************************END OF FILE***************************/
|