STM32cubeMX开发 NANDflash 之H27U4G8F2E 问题记录

2023-11-04 02:20

本文主要是介绍STM32cubeMX开发 NANDflash 之H27U4G8F2E 问题记录,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

stm32cubemx配置

时钟配置

 代码部分

/********************************************************************************* File Name          : FMC.c* Description        : This file provides code for the configuration*                      of the FMC peripheral.******************************************************************************* @attention** <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.* All rights reserved.</center></h2>** This software component is licensed by ST under BSD 3-Clause license,* the "License"; You may not use this file except in compliance with the* License. You may obtain a copy of the License at:*                        opensource.org/licenses/BSD-3-Clause********************************************************************************//* Includes ------------------------------------------------------------------*/
#include "fmc.h"/* USER CODE BEGIN 0 *//* USER CODE END 0 */NAND_HandleTypeDef hnand1;/* FMC initialization function */
void MX_FMC_Init(void)
{FMC_NAND_PCC_TimingTypeDef ComSpaceTiming = {0};FMC_NAND_PCC_TimingTypeDef AttSpaceTiming = {0};/** Perform the NAND1 memory initialization sequence*/hnand1.Instance = FMC_NAND_DEVICE;/* hnand1.Init */hnand1.Init.NandBank = FMC_NAND_BANK3;hnand1.Init.Waitfeature = FMC_NAND_PCC_WAIT_FEATURE_ENABLE;hnand1.Init.MemoryDataWidth = FMC_NAND_PCC_MEM_BUS_WIDTH_8;hnand1.Init.EccComputation = FMC_NAND_ECC_DISABLE;hnand1.Init.ECCPageSize = FMC_NAND_ECC_PAGE_SIZE_2048BYTE;hnand1.Init.TCLRSetupTime = 0;hnand1.Init.TARSetupTime = 0;/* hnand1.Config */hnand1.Config.PageSize = 2048;hnand1.Config.SpareAreaSize = 64;hnand1.Config.BlockSize = 64;hnand1.Config.BlockNbr = 4096;hnand1.Config.PlaneNbr = 2;hnand1.Config.PlaneSize = 276824064;hnand1.Config.ExtraCommandEnable = DISABLE;/* ComSpaceTiming */ComSpaceTiming.SetupTime = 0;ComSpaceTiming.WaitSetupTime = 1;ComSpaceTiming.HoldSetupTime = 3;ComSpaceTiming.HiZSetupTime = 1;/* AttSpaceTiming */AttSpaceTiming.SetupTime = 0;AttSpaceTiming.WaitSetupTime = 1;AttSpaceTiming.HoldSetupTime = 3;AttSpaceTiming.HiZSetupTime = 1;if (HAL_NAND_Init(&hnand1, &ComSpaceTiming, &AttSpaceTiming) != HAL_OK){Error_Handler( );}}static uint32_t FMC_Initialized = 0;static void HAL_FMC_MspInit(void){/* USER CODE BEGIN FMC_MspInit 0 *//* USER CODE END FMC_MspInit 0 */GPIO_InitTypeDef GPIO_InitStruct = {0};if (FMC_Initialized) {return;}FMC_Initialized = 1;/* Peripheral clock enable */__HAL_RCC_FMC_CLK_ENABLE();/** FMC GPIO Configuration  PE7   ------> FMC_D4PE8   ------> FMC_D5PE9   ------> FMC_D6PE10   ------> FMC_D7PD11   ------> FMC_CLEPD12   ------> FMC_ALEPD14   ------> FMC_D0PD15   ------> FMC_D1PD0   ------> FMC_D2PD1   ------> FMC_D3PD4   ------> FMC_NOEPD5   ------> FMC_NWEPD6   ------> FMC_NWAITPG9   ------> FMC_NCE3*//* GPIO_InitStruct */GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;GPIO_InitStruct.Alternate = GPIO_AF12_FMC;HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);/* GPIO_InitStruct */GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_14|GPIO_PIN_15 |GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5 |GPIO_PIN_6;GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;GPIO_InitStruct.Alternate = GPIO_AF12_FMC;HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);/* GPIO_InitStruct */GPIO_InitStruct.Pin = GPIO_PIN_9;GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;GPIO_InitStruct.Alternate = GPIO_AF12_FMC;HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);/* USER CODE BEGIN FMC_MspInit 1 *//* USER CODE END FMC_MspInit 1 */
}void HAL_NAND_MspInit(NAND_HandleTypeDef* nandHandle){/* USER CODE BEGIN NAND_MspInit 0 *//* USER CODE END NAND_MspInit 0 */HAL_FMC_MspInit();/* USER CODE BEGIN NAND_MspInit 1 *//* USER CODE END NAND_MspInit 1 */
}static uint32_t FMC_DeInitialized = 0;static void HAL_FMC_MspDeInit(void){/* USER CODE BEGIN FMC_MspDeInit 0 *//* USER CODE END FMC_MspDeInit 0 */if (FMC_DeInitialized) {return;}FMC_DeInitialized = 1;/* Peripheral clock enable */__HAL_RCC_FMC_CLK_DISABLE();/** FMC GPIO Configuration  PE7   ------> FMC_D4PE8   ------> FMC_D5PE9   ------> FMC_D6PE10   ------> FMC_D7PD11   ------> FMC_CLEPD12   ------> FMC_ALEPD14   ------> FMC_D0PD15   ------> FMC_D1PD0   ------> FMC_D2PD1   ------> FMC_D3PD4   ------> FMC_NOEPD5   ------> FMC_NWEPD6   ------> FMC_NWAITPG9   ------> FMC_NCE3*/HAL_GPIO_DeInit(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);HAL_GPIO_DeInit(GPIOD, GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_14|GPIO_PIN_15 |GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5 |GPIO_PIN_6);HAL_GPIO_DeInit(GPIOG, GPIO_PIN_9);/* USER CODE BEGIN FMC_MspDeInit 1 *//* USER CODE END FMC_MspDeInit 1 */
}void HAL_NAND_MspDeInit(NAND_HandleTypeDef* nandHandle){/* USER CODE BEGIN NAND_MspDeInit 0 *//* USER CODE END NAND_MspDeInit 0 */HAL_FMC_MspDeInit();/* USER CODE BEGIN NAND_MspDeInit 1 *//* USER CODE END NAND_MspDeInit 1 */
}
/*** @}*//*** @}*//************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/* USER CODE BEGIN Header */
/********************************************************************************* @file           : main.c* @brief          : Main program body******************************************************************************* @attention** <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.* All rights reserved.</center></h2>** This software component is licensed by ST under BSD 3-Clause license,* the "License"; You may not use this file except in compliance with the* License. You may obtain a copy of the License at:*                        opensource.org/licenses/BSD-3-Clause********************************************************************************/
/* USER CODE END Header *//* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usart.h"
#include "gpio.h"
#include "fmc.h"/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */#include "nandflash.h"/* USER CODE END Includes *//* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD *//* USER CODE END PTD *//* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD *//* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM *//* USER CODE END PM *//* Private variables ---------------------------------------------------------*//* USER CODE BEGIN PV *//* USER CODE END PV *//* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP *//* USER CODE END PFP *//* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 *//* USER CODE END 0 *//*** @brief  The application entry point.* @retval int*/
int main(void)
{/* USER CODE BEGIN 1 *//* USER CODE END 1 *//* MCU Configuration--------------------------------------------------------*//* Reset of all peripherals, Initializes the Flash interface and the Systick. */HAL_Init();/* USER CODE BEGIN Init *//* USER CODE END Init *//* Configure the system clock */SystemClock_Config();/* USER CODE BEGIN SysInit *//* USER CODE END SysInit *//* Initialize all configured peripherals */MX_GPIO_Init();MX_FMC_Init();MX_USART1_UART_Init();/* USER CODE BEGIN 2 */HAL_Delay (500);if(nandflash())HAL_UART_Transmit(&huart1,"read nandflash failed",sizeof("read nandflash failed"),100);/* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */while (1){/* USER CODE END WHILE *//* USER CODE BEGIN 3 */}/* USER CODE END 3 */
}/*** @brief System Clock Configuration* @retval None*/
void SystemClock_Config(void)
{RCC_OscInitTypeDef RCC_OscInitStruct = {0};RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};/** Configure the main internal regulator output voltage */__HAL_RCC_PWR_CLK_ENABLE();__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);/** Initializes the CPU, AHB and APB busses clocks */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 = 25;RCC_OscInitStruct.PLL.PLLN = 192;RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;RCC_OscInitStruct.PLL.PLLQ = 4;if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK){Error_Handler();}/** Initializes the CPU, AHB and APB busses clocks */RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK){Error_Handler();}
}/* USER CODE BEGIN 4 *//* USER CODE END 4 *//*** @brief  This function is executed in case of error occurrence.* @retval None*/
void Error_Handler(void)
{/* USER CODE BEGIN Error_Handler_Debug *//* User can add his own implementation to report the HAL error return state *//* USER CODE END Error_Handler_Debug */
}#ifdef  USE_FULL_ASSERT
/*** @brief  Reports the name of the source file and the source line number*         where the assert_param error has occurred.* @param  file: pointer to the source file name* @param  line: assert_param error line source number* @retval None*/
void assert_failed(uint8_t *file, uint32_t line)
{ /* USER CODE BEGIN 6 *//* User can add his own implementation to report the file name and line number,tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) *//* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT *//************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#include "fmc.h"
#include "usart.h"NAND_IDTypeDef nand_ID;
NAND_AddressTypeDef NAND_Address;void nand_init(uint8_t nPlane,uint16_t nBlock,uint8_t nPage)
{assert_param(IS_nPLANE_OK(nPlane));assert_param(IS_nBLOCK_OK(nBlock));assert_param(IS_nPAGE_OK(nPage));NAND_Address.Plane = nPlane;NAND_Address.Block = nBlock;NAND_Address.Page  = nPage;
}uint8_t nandflash()
{HAL_StatusTypeDef HAL_status;uint8_t read_result[2048] = "0";HAL_NAND_Reset(&hnand1);HAL_Delay (500);HAL_status = HAL_NAND_Read_ID(&hnand1,&nand_ID);if(HAL_status != HAL_OK)return 1;HAL_UART_Transmit(&huart1,&nand_ID.Device_Id,sizeof(uint8_t),100);HAL_UART_Transmit(&huart1,&nand_ID.Fourth_Id,sizeof(uint8_t),100);HAL_UART_Transmit(&huart1,&nand_ID.Maker_Id,sizeof(uint8_t),100);HAL_UART_Transmit(&huart1,&nand_ID.Third_Id,sizeof(uint8_t),100);nand_init(1,1,1);HAL_status = HAL_NAND_Read_Page_8b(&hnand1,&NAND_Address,read_result,1);if(HAL_status != HAL_OK)return 3;HAL_UART_Transmit(&huart1,read_result,sizeof(read_result),3000);if(HAL_status != HAL_OK)return 4;return 0;
}

问题:调试时总是卡在

    HAL_status = HAL_NAND_Read_ID(&hnand1,&nand_ID);这个库函数中

    data = *(__IO uint32_t *)deviceaddress;/* Return the data read */

一执行这一步,就报错

这篇关于STM32cubeMX开发 NANDflash 之H27U4G8F2E 问题记录的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/342541

相关文章

怎样通过分析GC日志来定位Java进程的内存问题

《怎样通过分析GC日志来定位Java进程的内存问题》:本文主要介绍怎样通过分析GC日志来定位Java进程的内存问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、GC 日志基础配置1. 启用详细 GC 日志2. 不同收集器的日志格式二、关键指标与分析维度1.

Java 线程安全与 volatile与单例模式问题及解决方案

《Java线程安全与volatile与单例模式问题及解决方案》文章主要讲解线程安全问题的五个成因(调度随机、变量修改、非原子操作、内存可见性、指令重排序)及解决方案,强调使用volatile关键字... 目录什么是线程安全线程安全问题的产生与解决方案线程的调度是随机的多个线程对同一个变量进行修改线程的修改操

Redis出现中文乱码的问题及解决

《Redis出现中文乱码的问题及解决》:本文主要介绍Redis出现中文乱码的问题及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1. 问题的产生2China编程. 问题的解决redihttp://www.chinasem.cns数据进制问题的解决中文乱码问题解决总结

在Spring Boot中集成RabbitMQ的实战记录

《在SpringBoot中集成RabbitMQ的实战记录》本文介绍SpringBoot集成RabbitMQ的步骤,涵盖配置连接、消息发送与接收,并对比两种定义Exchange与队列的方式:手动声明(... 目录前言准备工作1. 安装 RabbitMQ2. 消息发送者(Producer)配置1. 创建 Spr

全面解析MySQL索引长度限制问题与解决方案

《全面解析MySQL索引长度限制问题与解决方案》MySQL对索引长度设限是为了保持高效的数据检索性能,这个限制不是MySQL的缺陷,而是数据库设计中的权衡结果,下面我们就来看看如何解决这一问题吧... 目录引言:为什么会有索引键长度问题?一、问题根源深度解析mysql索引长度限制原理实际场景示例二、五大解决

Springboot如何正确使用AOP问题

《Springboot如何正确使用AOP问题》:本文主要介绍Springboot如何正确使用AOP问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录​一、AOP概念二、切点表达式​execution表达式案例三、AOP通知四、springboot中使用AOP导出

Python中Tensorflow无法调用GPU问题的解决方法

《Python中Tensorflow无法调用GPU问题的解决方法》文章详解如何解决TensorFlow在Windows无法识别GPU的问题,需降级至2.10版本,安装匹配CUDA11.2和cuDNN... 当用以下代码查看GPU数量时,gpuspython返回的是一个空列表,说明tensorflow没有找到

解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题

《解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题》:本文主要介绍解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4... 目录未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘打开pom.XM

IDEA Maven提示:未解析的依赖项的问题及解决

《IDEAMaven提示:未解析的依赖项的问题及解决》:本文主要介绍IDEAMaven提示:未解析的依赖项的问题及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝... 目录IDEA Maven提示:未解析的依编程赖项例如总结IDEA Maven提示:未解析的依赖项例如

SpringBoot开发中十大常见陷阱深度解析与避坑指南

《SpringBoot开发中十大常见陷阱深度解析与避坑指南》在SpringBoot的开发过程中,即使是经验丰富的开发者也难免会遇到各种棘手的问题,本文将针对SpringBoot开发中十大常见的“坑... 目录引言一、配置总出错?是不是同时用了.properties和.yml?二、换个位置配置就失效?搞清楚加