stm32怎样将数组存到flash?存到flash中的数组怎样读取出来?

如题所述

第1个回答  推荐于2019-10-12
先初始化FSMC
void FSMC_NAND_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
FSMC_NANDInitTypeDef FSMC_NANDInitStructure;
FSMC_NAND_PCCARDTimingInitTypeDef p;

/* Enable FSMC, GPIOD, GPIOE and AFIO clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
RCC_APB2Periph_GPIOG | RCC_APB2Periph_AFIO , ENABLE);

/*-- GPIO Configuration ------------------------------------------------------*/
/* CLE, ALE, D0->D3, NOE, NWE and NCE2 NAND pin configuration */
GPIO_InitStructure.GPIO_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_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);

/* D4->D7 NAND pin configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
GPIO_Init(GPIOE, &GPIO_InitStructure);

/* CS NAND pin configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOG, &GPIO_InitStructure);

/* NWAIT NAND pin configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOD, &GPIO_InitStructure);

/*-- FSMC Configuration ------------------------------------------------------*/
p.FSMC_SetupTime = 0x1;
p.FSMC_WaitSetupTime = 0x3;
p.FSMC_HoldSetupTime = 0x2;
p.FSMC_HiZSetupTime = 0x1;

FSMC_NANDInitStructure.FSMC_Bank = FSMC_Bank3_NAND;
FSMC_NANDInitStructure.FSMC_Waitfeature = FSMC_Waitfeature_Enable;
FSMC_NANDInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
FSMC_NANDInitStructure.FSMC_ECC = FSMC_ECC_Enable;
FSMC_NANDInitStructure.FSMC_ECCPageSize = FSMC_ECCPageSize_512Bytes;
FSMC_NANDInitStructure.FSMC_TCLRSetupTime = 0x00;
FSMC_NANDInitStructure.FSMC_TARSetupTime = 0x00;
FSMC_NANDInitStructure.FSMC_CommonSpaceTimingStruct = &p;
FSMC_NANDInitStructure.FSMC_AttributeSpaceTimingStruct = &p;

FSMC_NANDInit(&FSMC_NANDInitStructure);

/* FSMC NAND Bank Cmd Test */
FSMC_NANDCmd(FSMC_Bank3_NAND, ENABLE);
}
定义一个写函数
uint32_t FSMC_NAND_WriteSmallPage(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumPageToWrite)
{
uint32_t index = 0x00, numpagewritten = 0x00, addressstatus = NAND_VALID_ADDRESS;
uint32_t status = NAND_READY, size = 0x00;
uint8_t Page = 0x37;
while((NumPageToWrite != 0x00) && (addressstatus == NAND_VALID_ADDRESS) && (status == NAND_READY))
{
/* Page write command and address */
*(vu8 *)(NAND_FLASH_START_ADDR | CMD_AREA) = NAND_CMD_PAGEPROGRAM;

*(vu8 *)(NAND_FLASH_START_ADDR | ADDR_AREA) = 0x00;
*(vu8 *)(NAND_FLASH_START_ADDR | ADDR_AREA) = 0X00;
*(vu8 *)(NAND_FLASH_START_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
*(vu8 *)(NAND_FLASH_START_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);

/* Calculate the size */
size = Page + (Page * numpagewritten);

/* Write data */
for(; index < size; index++)
{
*(vu8 *)(NAND_FLASH_START_ADDR | DATA_AREA) = pBuffer[index];
}

*(vu8 *)(NAND_FLASH_START_ADDR | CMD_AREA) = NAND_CMD_PAGEPROGRAM_TRUE;

/* 读忙脚 */
// while( GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_6) == 0 );
// while( GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) == 0 );

/* Check status for successful operation */
status = FSMC_NAND_GetStatus();

if(status == NAND_READY)
{
numpagewritten++;

NumPageToWrite--;

/* Calculate Next small page Address */
addressstatus = FSMC_NAND_AddressIncrement(&Address);
}
}

return (status | addressstatus);
}
定义一个数组TxBuffer,然后将数组写入flash
FSMC_NAND_WriteSmallPage(TxBuffer, WriteAddr, 1);
读的过程相反,定义读取函数
uint32_t FSMC_NAND_ReadSmallPage(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumPageToRead)
{
uint32_t index = 0x00, numpageread = 0x00, addressstatus = NAND_VALID_ADDRESS;
uint32_t status = NAND_READY, size = 0x00;
uint8_t Page = 0x37;
while((NumPageToRead != 0x0) && (addressstatus == NAND_VALID_ADDRESS))
{
/* Page Read command and page address */
*(vu8 *)(NAND_FLASH_START_ADDR | CMD_AREA) = NAND_CMD_READ_1;

*(vu8 *)(NAND_FLASH_START_ADDR | ADDR_AREA) = 0x00;
*(vu8 *)(NAND_FLASH_START_ADDR | ADDR_AREA) = 0X00;
*(vu8 *)(NAND_FLASH_START_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
*(vu8 *)(NAND_FLASH_START_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);

*(vu8 *)(NAND_FLASH_START_ADDR | CMD_AREA) = NAND_CMD_READ_TRUE;

/* 读忙脚 */
// while( GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_6) == 0 );
// while( GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) == 0 );

/* Calculate the size */
size = Page + (Page * numpageread);

/* Get Data into Buffer */
for(; index < size; index++)
{
pBuffer[index]= *(vu8 *)(NAND_FLASH_START_ADDR | DATA_AREA);
}

numpageread++;

NumPageToRead--;

/* Calculate page address */
addressstatus = FSMC_NAND_AddressIncrement(&Address);
}

status = FSMC_NAND_GetStatus();

return (status | addressstatus);
}本回答被网友采纳

stm32怎样将数组存到flash?存到flash中的数组怎样读取出来?
先初始化FSMC\\x0d\\x0avoid FSMC_NAND_Init(void)\\x0d\\x0a{\\x0d\\x0a GPIO_InitTypeDef GPIO_InitStructure; \\x0d\\x0a FSMC_NANDInitTypeDef FSMC_NANDInitStructure;\\x0d\\x0a FSMC_NAND_PCCARDTimingInitTypeDef p;\\x0d\\x0a \\x0d\\x0a \/* Enable FSMC, GPIOD, GPIOE and AFIO clocks *\/\\x0...

stm32怎样将数组存到flash?存到flash中的数组怎样读取出来?
(vu8 *)(NAND_FLASH_START_ADDR | ADDR_AREA) = 0x00;(vu8 *)(NAND_FLASH_START_ADDR | ADDR_AREA) = 0X00;(vu8 *)(NAND_FLASH_START_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);(vu8 *)(NAND_FLASH_START_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);\/* Calc...

stm32程序里定义的数组是存到Flash里还是SRAM
ARM芯片复位后都是从0x0000 0004地址启动。STM32会转入一段自己的bootloader。然后根据BOOT引脚,选择启动位置。如果是FLASH则跳转到0x0800 0000(不知道地址有没记错)执行。程序一般指定FLASH的地址是链接地址(ARM使用绝对地址,运行和链接地址必须一致)。数组分2类,用const标示的常量数组,普通数组。con...

STM32外加了flash芯片(AT45DB642D),读取flash中的数据,通过串口...
1. 上位机将需要的页号或多个页号发给STM32 2. STM32启动SPI操作,逐页读取,并采取先进先出的方式保存在一个FIFO缓冲区中,该缓冲区以页大小为单位 3. 通过串口拼包发出。

stm32内部flash不足怎么办?
回答:换一个存储空间大一点的SD卡 应该就能解决问题了 楼主

stm32中程序运行的时候,是在ram中还是flash中
1 1 Embedded SRAM Embedded SRAM is selected as boot space 它有两个引脚来控制启动方式 一般都用第一种 选择flash启动 我们一般都是下载到flash 中的 用JLINK在线仿真时 是下载到SRAM中的 但是也不需要改启动方式 SRAM中掉电程序就会消失 而flash是属于ROM类型的存储器 掉电不会丢失...

stm32程序定义的各种参数都存在哪,比如我定义一个存放1000个数的数组...
看你是怎么定义的了,如果加了const,那就保存在ROM中。如果申明了数组但没初始化,那就是放在RAM中的;如果初始化了,数组放在RAM中,但数组初始化的数据放在ROM中,有程序从ROM复制到RAM。

stm32串口收发数据为什么使用dma?
本次学习共有两个程序。第一个为DMA数据转运,使用DMA进行存储器到存储器的数据转运,即把一个数组里的数据复制到另一个数组里。 第二个为DMA+AD多通道,一、DMA简介1.概述1、DMA(Direct Memory Access)直接存储器存取或访问。从名字看,DMA这个外设可以直接访问STM32内部的存储器,包括运行内存SRAM...

stm32擦除flash所有页是否会将程序代码也擦除了
您好,我来为您解答:先在程序中定义一个const 类型的常量数组,并指定其存储位置(方便找到写入、读取位置),这样编译器就会分配你指定的空间将常量数组存入FLASH中。当你做擦除。读写操作时,只要在这个常量数组所在的地址范围就好。const uint8_t table[10] __at(0x08010000) = {0x55} ;MDK3....

stm32在rom中放数据可以直接赋值吗
定义的数据前面加上关键字const 如:const unsigned int a;const unsigned char buf[3]={0x01,0x02,0x03};则变量a和数组buf就放到Flash(即ROM)里面了。

相似回答