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

相关文章

这15个Vue指令,让你的项目开发爽到爆

1. V-Hotkey 仓库地址: github.com/Dafrok/v-ho… Demo: 戳这里 https://dafrok.github.io/v-hotkey 安装: npm install --save v-hotkey 这个指令可以给组件绑定一个或多个快捷键。你想要通过按下 Escape 键后隐藏某个组件,按住 Control 和回车键再显示它吗?小菜一碟: <template

Hadoop企业开发案例调优场景

需求 (1)需求:从1G数据中,统计每个单词出现次数。服务器3台,每台配置4G内存,4核CPU,4线程。 (2)需求分析: 1G / 128m = 8个MapTask;1个ReduceTask;1个mrAppMaster 平均每个节点运行10个 / 3台 ≈ 3个任务(4    3    3) HDFS参数调优 (1)修改:hadoop-env.sh export HDFS_NAMENOD

好题——hdu2522(小数问题:求1/n的第一个循环节)

好喜欢这题,第一次做小数问题,一开始真心没思路,然后参考了网上的一些资料。 知识点***********************************无限不循环小数即无理数,不能写作两整数之比*****************************(一开始没想到,小学没学好) 此题1/n肯定是一个有限循环小数,了解这些后就能做此题了。 按照除法的机制,用一个函数表示出来就可以了,代码如下

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

嵌入式QT开发:构建高效智能的嵌入式系统

摘要: 本文深入探讨了嵌入式 QT 相关的各个方面。从 QT 框架的基础架构和核心概念出发,详细阐述了其在嵌入式环境中的优势与特点。文中分析了嵌入式 QT 的开发环境搭建过程,包括交叉编译工具链的配置等关键步骤。进一步探讨了嵌入式 QT 的界面设计与开发,涵盖了从基本控件的使用到复杂界面布局的构建。同时也深入研究了信号与槽机制在嵌入式系统中的应用,以及嵌入式 QT 与硬件设备的交互,包括输入输出设

OpenHarmony鸿蒙开发( Beta5.0)无感配网详解

1、简介 无感配网是指在设备联网过程中无需输入热点相关账号信息,即可快速实现设备配网,是一种兼顾高效性、可靠性和安全性的配网方式。 2、配网原理 2.1 通信原理 手机和智能设备之间的信息传递,利用特有的NAN协议实现。利用手机和智能设备之间的WiFi 感知订阅、发布能力,实现了数字管家应用和设备之间的发现。在完成设备间的认证和响应后,即可发送相关配网数据。同时还支持与常规Sof

活用c4d官方开发文档查询代码

当你问AI助手比如豆包,如何用python禁止掉xpresso标签时候,它会提示到 这时候要用到两个东西。https://developers.maxon.net/论坛搜索和开发文档 比如这里我就在官方找到正确的id描述 然后我就把参数标签换过来

购买磨轮平衡机时应该注意什么问题和技巧

在购买磨轮平衡机时,您应该注意以下几个关键点: 平衡精度 平衡精度是衡量平衡机性能的核心指标,直接影响到不平衡量的检测与校准的准确性,从而决定磨轮的振动和噪声水平。高精度的平衡机能显著减少振动和噪声,提高磨削加工的精度。 转速范围 宽广的转速范围意味着平衡机能够处理更多种类的磨轮,适应不同的工作条件和规格要求。 振动监测能力 振动监测能力是评估平衡机性能的重要因素。通过传感器实时监

缓存雪崩问题

缓存雪崩是缓存中大量key失效后当高并发到来时导致大量请求到数据库,瞬间耗尽数据库资源,导致数据库无法使用。 解决方案: 1、使用锁进行控制 2、对同一类型信息的key设置不同的过期时间 3、缓存预热 1. 什么是缓存雪崩 缓存雪崩是指在短时间内,大量缓存数据同时失效,导致所有请求直接涌向数据库,瞬间增加数据库的负载压力,可能导致数据库性能下降甚至崩溃。这种情况往往发生在缓存中大量 k

6.1.数据结构-c/c++堆详解下篇(堆排序,TopK问题)

上篇:6.1.数据结构-c/c++模拟实现堆上篇(向下,上调整算法,建堆,增删数据)-CSDN博客 本章重点 1.使用堆来完成堆排序 2.使用堆解决TopK问题 目录 一.堆排序 1.1 思路 1.2 代码 1.3 简单测试 二.TopK问题 2.1 思路(求最小): 2.2 C语言代码(手写堆) 2.3 C++代码(使用优先级队列 priority_queue)