大学生
最后登录1970-1-1
在线时间 小时
注册时间2016-11-23
|
楼主 |
发表于 2017-5-18 08:32:24
|
显示全部楼层
原子哥,我按407的改完之后就出现HardFault_Handler了,不知道啥原因,我把我改完之后的贴出来您帮我看看,或者您帮我用w25q64例程上改成w25128,发我邮箱吧,然后我会贴出来和大家分享,造福广大群众,改完之后发我qq邮箱: 1491895682@qq.com
改后出错,代码贴出如下:
/**
******************************************************************************
* @file mass_mal.c
* @author MCD Application Team
* @version V3.4.0
* @date 29-June-2012
* @brief Medium Access Layer interface
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "..\User\spi_flash\fatfs_flash_spi.h"
#include "mass_mal.h"
#include <stdio.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
uint32_t Mass_Memory_Size[2];
uint32_t Mass_Block_Size[2];
uint32_t Mass_Block_Count[2];
__IO uint32_t Status = 0;
//#define sFLASH_ID 0xEF3015 //W25X16
//#define sFLASH_ID 0xEF4015 //W25Q16
//#define sFLASH_ID 0XEF4017 //W25Q64
#define sFLASH_ID 0XEF4018 //W25Q128
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : MAL_Init
* Description : Initializes the Media on the STM32
* Input : None
* Output : None
* Return : None
*******************************************************************************/
uint16_t MAL_Init(uint8_t lun)
{
uint16_t status = MAL_OK;
switch (lun)
{
case 0:
FLASH_SPI_disk_initialize();
if(SPI_FLASH_ReadID()==sFLASH_ID)
{
//printf("flash init succsee\n");
Status = MAL_OK;
}
else
Status = MAL_FAIL;
break;
default:
return MAL_FAIL;
}
return status;
}
/*******************************************************************************
* Function Name : MAL_Write
* Description : Write sectors
* Input : None
* Output : None
* Return : None
*******************************************************************************/
uint16_t MAL_Write(uint8_t lun, uint32_t Memory_Offset, uint32_t *Writebuff, uint16_t Transfer_Length)
{
switch (lun)
{
case 0:
//Memory_Offset+=(512*4096);//éèÇøÆ«òÆ£¬ía2¿FlashÎļtÏμí3¿Õ¼ä·ÅÔúía2¿FlashoóÃæ6M¿Õ¼ä
Memory_Offset+=1536;
//printf("write add =%d.length=%d\n",Memory_Offset/4096,Transfer_Length/4096);
SPI_FLASH_SectorErase(Memory_Offset<<12);
SPI_FLASH_BufferWrite((uint8_t *)Writebuff,Memory_Offset<<12,Transfer_Length<<12);
break;
default:
return MAL_FAIL;
}
return MAL_OK;
}
/*******************************************************************************
* Function Name : MAL_Read
* Description : Read sectors
* Input : None
* Output : None
* Return : Buffer pointer
*******************************************************************************/
uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint16_t Transfer_Length)
{
switch (lun)
{
case 0:
//Memory_Offset+=(512*4096);//éèÇøÆ«òÆ£¬ía2¿FlashÎļtÏμí3¿Õ¼ä·ÅÔúía2¿FlashoóÃæ6M¿Õ¼ä
Memory_Offset+=1536;
//printf("read add =%d.length=%d\n",Memory_Offset/4096,Transfer_Length/4096);
SPI_FLASH_BufferRead((uint8_t *)Readbuff, Memory_Offset<<12, Transfer_Length<<12);
break;
default:
return MAL_FAIL;
}
return MAL_OK;
}
/*******************************************************************************
* Function Name : MAL_GetStatus
* Description : Get status
* Input : None
* Output : None
* Return : None
*******************************************************************************/
uint16_t MAL_GetStatus (uint8_t lun)
{
if (lun == 0)
{
FLASH_SPI_disk_initialize();
if(SPI_FLASH_ReadID()==sFLASH_ID)
{
Mass_Block_Size[0] =4096;
Mass_Block_Count[0] =2560;
Mass_Memory_Size[0] =Mass_Block_Size[0]*Mass_Block_Count[0];
return MAL_OK;
}
}
return MAL_FAIL;
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|