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

相关文章

Python获取中国节假日数据记录入JSON文件

《Python获取中国节假日数据记录入JSON文件》项目系统内置的日历应用为了提升用户体验,特别设置了在调休日期显示“休”的UI图标功能,那么问题是这些调休数据从哪里来呢?我尝试一种更为智能的方法:P... 目录节假日数据获取存入jsON文件节假日数据读取封装完整代码项目系统内置的日历应用为了提升用户体验,

springboot循环依赖问题案例代码及解决办法

《springboot循环依赖问题案例代码及解决办法》在SpringBoot中,如果两个或多个Bean之间存在循环依赖(即BeanA依赖BeanB,而BeanB又依赖BeanA),会导致Spring的... 目录1. 什么是循环依赖?2. 循环依赖的场景案例3. 解决循环依赖的常见方法方法 1:使用 @La

Spring Boot + MyBatis Plus 高效开发实战从入门到进阶优化(推荐)

《SpringBoot+MyBatisPlus高效开发实战从入门到进阶优化(推荐)》本文将详细介绍SpringBoot+MyBatisPlus的完整开发流程,并深入剖析分页查询、批量操作、动... 目录Spring Boot + MyBATis Plus 高效开发实战:从入门到进阶优化1. MyBatis

Spring Boot 配置文件之类型、加载顺序与最佳实践记录

《SpringBoot配置文件之类型、加载顺序与最佳实践记录》SpringBoot的配置文件是灵活且强大的工具,通过合理的配置管理,可以让应用开发和部署更加高效,无论是简单的属性配置,还是复杂... 目录Spring Boot 配置文件详解一、Spring Boot 配置文件类型1.1 applicatio

Python基于wxPython和FFmpeg开发一个视频标签工具

《Python基于wxPython和FFmpeg开发一个视频标签工具》在当今数字媒体时代,视频内容的管理和标记变得越来越重要,无论是研究人员需要对实验视频进行时间点标记,还是个人用户希望对家庭视频进行... 目录引言1. 应用概述2. 技术栈分析2.1 核心库和模块2.2 wxpython作为GUI选择的优

MySQL INSERT语句实现当记录不存在时插入的几种方法

《MySQLINSERT语句实现当记录不存在时插入的几种方法》MySQL的INSERT语句是用于向数据库表中插入新记录的关键命令,下面:本文主要介绍MySQLINSERT语句实现当记录不存在时... 目录使用 INSERT IGNORE使用 ON DUPLICATE KEY UPDATE使用 REPLACE

SpringBoot启动报错的11个高频问题排查与解决终极指南

《SpringBoot启动报错的11个高频问题排查与解决终极指南》这篇文章主要为大家详细介绍了SpringBoot启动报错的11个高频问题的排查与解决,文中的示例代码讲解详细,感兴趣的小伙伴可以了解一... 目录1. 依赖冲突:NoSuchMethodError 的终极解法2. Bean注入失败:No qu

Python 中的异步与同步深度解析(实践记录)

《Python中的异步与同步深度解析(实践记录)》在Python编程世界里,异步和同步的概念是理解程序执行流程和性能优化的关键,这篇文章将带你深入了解它们的差异,以及阻塞和非阻塞的特性,同时通过实际... 目录python中的异步与同步:深度解析与实践异步与同步的定义异步同步阻塞与非阻塞的概念阻塞非阻塞同步

Python Dash框架在数据可视化仪表板中的应用与实践记录

《PythonDash框架在数据可视化仪表板中的应用与实践记录》Python的PlotlyDash库提供了一种简便且强大的方式来构建和展示互动式数据仪表板,本篇文章将深入探讨如何使用Dash设计一... 目录python Dash框架在数据可视化仪表板中的应用与实践1. 什么是Plotly Dash?1.1

MySQL新增字段后Java实体未更新的潜在问题与解决方案

《MySQL新增字段后Java实体未更新的潜在问题与解决方案》在Java+MySQL的开发中,我们通常使用ORM框架来映射数据库表与Java对象,但有时候,数据库表结构变更(如新增字段)后,开发人员可... 目录引言1. 问题背景:数据库与 Java 实体不同步1.1 常见场景1.2 示例代码2. 不同操作