久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標題:
STM32驅動 M25P64 FLASH讀寫程序
[打印本頁]
作者:
wjy666888wjy
時間:
2017-8-8 09:58
標題:
STM32驅動 M25P64 FLASH讀寫程序
STM32單片機驅動M25P64 SPI_FLASH參考例程.
0.png
(42.4 KB, 下載次數: 91)
下載附件
2017-8-8 17:58 上傳
全部資料下載地址:
STM32 M25P64 FLASH讀寫程序.rar
(14.41 KB, 下載次數: 57)
2017-8-8 09:56 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name : main.c
* Author : MCD Application Team
* Version : V2.0.1
* Date : 06/13/2008
* Description : Main program body
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "platform_config.h"
#include "spi_flash.h"
/* Local includes ------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
/* Private define ------------------------------------------------------------*/
#define FLASH_WriteAddress 0x700000
#define FLASH_ReadAddress FLASH_WriteAddress
#define FLASH_SectorToErase FLASH_WriteAddress
#define M25P64_FLASH_ID 0x202017
#define BufferSize (countof(Tx_Buffer)-1)
/* Private macro -------------------------------------------------------------*/
#define countof(a) (sizeof(a) / sizeof(*(a)))
/* Private variables ---------------------------------------------------------*/
u8 Tx_Buffer[] = "STM32F10x SPI Firmware Library Example: communication with an M25P64 SPI FLASH";
u8 Index, Rx_Buffer[BufferSize];
volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = PASSED;
vu32 FLASH_ID = 0;
ErrorStatus HSEStartUpStatus;
/* Private functions ---------------------------------------------------------*/
TestStatus Buffercmp(u8* pBuffer1, u8* pBuffer2, u16 BufferLength);
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
/*******************************************************************************
* Function Name : main
* Description : Main program
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
debug();
#endif
/* System clocks configuration */
RCC_Configuration();
/* NVIC configuration */
NVIC_Configuration();
/* GPIO configuration */
GPIO_Configuration();
/* Initialize the SPI FLASH driver */
SPI_FLASH_Init();
/* Get SPI Flash ID */
FLASH_ID = SPI_FLASH_ReadID();
/* Check the SPI Flash ID */
if (FLASH_ID == M25P64_FLASH_ID)
{
/* OK: Set GPIO_LED pin 6 */
GPIO_WriteBit(GPIO_LED, GPIO_Pin_6, Bit_SET);
}
else
{
/* Error: Set GPIO_LED pin 7 */
GPIO_WriteBit(GPIO_LED, GPIO_Pin_7, Bit_SET);
}
/* Perform a write in the Flash followed by a read of the written data */
/* Erase SPI FLASH Sector to write on */
SPI_FLASH_SectorErase(FLASH_SectorToErase);
/* Write Tx_Buffer data to SPI FLASH memory */
SPI_FLASH_BufferWrite(Tx_Buffer, FLASH_WriteAddress, BufferSize);
/* Read data from SPI FLASH memory */
SPI_FLASH_BufferRead(Rx_Buffer, FLASH_ReadAddress, BufferSize);
/* Check the corectness of written dada */
TransferStatus1 = Buffercmp(Tx_Buffer, Rx_Buffer, BufferSize);
/* TransferStatus1 = PASSED, if the transmitted and received data by SPI1
are the same */
/* TransferStatus1 = FAILED, if the transmitted and received data by SPI1
are different */
/* Perform an erase in the Flash followed by a read of the written data */
/* Erase SPI FLASH Sector to write on */
SPI_FLASH_SectorErase(FLASH_SectorToErase);
/* Read data from SPI FLASH memory */
SPI_FLASH_BufferRead(Rx_Buffer, FLASH_ReadAddress, BufferSize);
/* Check the corectness of erasing operation dada */
for (Index = 0; Index < BufferSize; Index++)
{
if (Rx_Buffer[Index] != 0xFF)
{
TransferStatus2 = FAILED;
}
}
/* TransferStatus2 = PASSED, if the specified sector part is erased */
/* TransferStatus2 = FAILED, if the specified sector part is not well erased */
while (1)
{}
}
/*******************************************************************************
* Function Name : RCC_Configuration
* Description : Configures the different system clocks.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RCC_Configuration(void)
{
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if (HSEStartUpStatus == SUCCESS)
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* PLLCLK = 8MHz * 9 = 72 MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{}
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while (RCC_GetSYSCLKSource() != 0x08)
{}
}
/* Enable GPIO_LED clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_LED, ENABLE);
}
/*******************************************************************************
* Function Name : GPIO_Configuration
* Description : Configures the different GPIO ports.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure GPIO LED pin6 and pin7 as Output push-pull --------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIO_LED, &GPIO_InitStructure);
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
}
/*******************************************************************************
* Function Name : Buffercmp
* Description : Compares two buffers.
* Input : - pBuffer1, pBuffer2: buffers to be compared.
* : - BufferLength: buffer's length
* Output : None
* Return : PASSED: pBuffer1 identical to pBuffer2
* FAILED: pBuffer1 differs from pBuffer2
*******************************************************************************/
TestStatus Buffercmp(u8* pBuffer1, u8* pBuffer2, u16 BufferLength)
{
while (BufferLength--)
{
if (*pBuffer1 != *pBuffer2)
{
return FAILED;
}
pBuffer1++;
pBuffer2++;
}
return PASSED;
}
#ifdef DEBUG
/*******************************************************************************
* Function Name : assert_failed
* Description : Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* Input : - file: pointer to the source file name
* - line: assert_param error line source number
* Output : None
* Return : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{}
}
#endif
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
復制代碼
作者:
屏風燭影
時間:
2018-11-5 10:41
下載下來分析下
作者:
hugheao
時間:
2019-3-7 22:05
試試。。。。
歡迎光臨 (http://www.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
久久久久久久久久久久久9999
|
婷婷色成人
|
欧美综合一区
|
亚洲美女视频
|
国产黄色av网站
|
午夜激情视频
|
91福利在线观看视频
|
免费一二区
|
成人午夜免费在线视频
|
欧美日韩在线一区二区三区
|
欧美激情第一区
|
亚洲精品一区二三区不卡
|
永久免费视频
|
久久久久国产一区二区三区四区
|
你懂的在线视频播放
|
日本在线视频一区二区
|
天天干狠狠干
|
亚洲成人蜜桃
|
狠狠色综合久久婷婷
|
天堂色
|
国产精品国产亚洲精品看不卡15
|
成人在线免费视频
|
欧美福利视频
|
国产aaaaav久久久一区二区
|
欧美日韩在线播放
|
亚洲自拍偷拍视频
|
国产视频中文字幕
|
h视频在线观看免费
|
粉嫩高清一区二区三区
|
中文字幕一区二区三区四区五区
|
成人免费福利视频
|
天天干国产
|
欧美在线一区视频
|
九九爱这里只有精品
|
www.国产一区
|
h视频在线播放
|
免费久久精品视频
|
欧美日韩国产精品一区
|
国产福利在线视频
|
日韩精品一区二区三区在线观看
|
中文在线а√在线8
|