4105 views|11 replies

12

Posts

0

Resources
The OP
 

Fudan Micro FM33LC046N Review + FLASH Storage [Copy link]

 
 

1. Overview

1. FLASH capacity 64K * 32 = 256K
Page---page(512B)
Sector--sector(2K)
2. Support page erase, sector erase, full erase (only supports SWD program download mode)
3. Flash memory
Size: 256k
Range: 0x00000000 -- 0x00040000
The size of a Flash sector is 512 bytes, and every 16 sectors form an 8K-byte block.
Flash contains 4 information sectors, 2 LDT sectors, 1 redundant sector, and 1 DCT sector. DCT and LDT are sectors reserved by the chip manufacturer and are not open to users. Information is the user configuration sector, which is used to store user configuration information.
The option sector is isolated from the main Flash area in terms of address.
2. Flash erase method
3. Software Implementation Steps
1. Based on serial communication, send data to MCU through the serial port to operate read/write flash
2. Command judgment Instruction code: flash operation is fixed at 0x01;
Operation code: 0x01--read, 0x04--write

The above commands are all sent in HEX data format

Example:

(1) Write data
68 01 04 02 12 34 16 //Write two bytes of data to the flash. The data is 0x12 and 0x34.
No return. You can check it by reading the data.
(2) Read data
[2021-03-02 13:36:37:313] 68 01 01 01 05 16 (6 bytes) //Read 5 bytes of data from the flash
[2021-03-02 13:36:37:518] 68 01 81 05 11 22 33 44 55 16 (10 bytes) //The data read is: 11 22 33 44 55

3. Flash read function

ErrorStatus FL_FLASH_Read_Dma(FLASH_Type* FLASHx, uint32_t address, uint32_t *data, uint16_t length)
//FLASHx:外设地址
//address:操作的地址(页首地址)
//data:读回的数据存放地址
//length:读取的长度
ErrorStatus FL_FLASH_Read_Dma(FLASH_Type* FLASHx, uint32_t address, uint32_t *data, uint16_t length)
{
    ErrorStatus ret; 
    uint32_t Timeout;
    
    FL_DMA_InitTypeDef initStruct={0};
    
    /* 入口参数检查 */
    assert_param(IS_FLASH_ALL_INSTANCE(FLASHx));
    assert_param(IS_FL_FLASH_MAX_ADDR(address));
    
    /* 半页对齐*/
    if(address & (FL_FLASH_SECTOR_SIZE_BYTE / 2 - 1))
    {
        /*地址未对齐*/
        return FAIL;
    }
    
    initStruct.circMode = DISABLE;
    initStruct.direction = FL_DMA_DIR_FLASH_TO_RAM;
    initStruct.memoryAddressIncMode = FL_DMA_CH7_MEMORY_INC_MODE_INCREASE;
    initStruct.flashAddressIncMode = FL_DMA_CH7_FLASH_INC_MODE_INCREASE;
    initStruct.priority = FL_DMA_PRIORITY_HIGH;
    initStruct.periphAddress = address >> 2;
    FL_DMA_Init(DMA, &initStruct, FL_DMA_CHANNEL_7);
    
    FL_DMA_WriteFlashAddress(DMA, address >> 2);
    FL_DMA_WriteMemoryAddress(DMA, (uint32_t)data >> 2, FL_DMA_CHANNEL_7);
    FL_DMA_WriteTransmissionSize(DMA, length - 1, FL_DMA_CHANNEL_7);
    
    FL_DMA_ClearFlag_TransferComplete(DMA, FL_DMA_CHANNEL_7);
    FL_DMA_EnableChannel(DMA, FL_DMA_CHANNEL_7);
    FL_DMA_Enable(DMA);
    
    Timeout = 0;
    while (1)
    {
        Timeout++;
        if(Timeout > FL_FLASH_ERASE_TIMEOUT)
        {
            ret = FAIL;
            break;
        }
        
        if (FL_DMA_IsActiveFlag_TransferComplete(DMA, FL_DMA_CHANNEL_7) == SET)
        {
            ret = PASS;
            break;
        }
    }
    
    return ret;
}

4. Flash write function

ErrorStatus FL_FLASH_PageErase(FLASH_Type* FLASHx, uint32_t address)
//页擦写函数
//FLASHx:外设地址
//address:操作的地址(页首地址)

ErrorStatus FL_FLASH_Program_Page(FLASH_Type* FLASHx, uint32_t pageNum, uint32_t *data)
//FLASHx:外设地址
//pageNum:扇区号
//data:读回的数据存放地址
ErrorStatus FL_FLASH_Program_Page(FLASH_Type* FLASHx, uint32_t pageNum, uint32_t *data)
{
    uint32_t count;
    uint32_t primask;
    uint32_t address;
    uint32_t timeout;
    ErrorStatus ret;
    
    /* 入口参数检查 */
    assert_param(IS_FLASH_ALL_INSTANCE(FLASHx));
    assert_param(IS_FL_FLASH_MAX_PAGE((uint32_t)pageNum));
    address = pageNum*FL_FLASH_PAGE_SIZE_BYTE;
    
    /* 页对齐*/
    if(address & (FL_FLASH_PAGE_SIZE_BYTE-1))
    {
        /*地址未对齐*/
        return FAIL;
    }
    FL_RCC_EnableGroup2BusClock(FL_RCC_GROUP2_BUSCLK_FLASH);
    FL_RCC_EnableGroup2OperationClock(FL_RCC_GROUP2_OPCLK_FLASH);
    
    FL_FLASH_EnableProgram(FLASHx);
    
    if(FL_FLASH_GetFlashLockStatus(FLASHx) != FL_FLASH_KEY_STATUS_PROGRAM)
    {
        /* Key 序列*/
        primask = __get_PRIMASK();
        __disable_irq();
        FL_FLASH_UnlockFlash(FLASHx,FL_FLASH_PROGRAM_KEY1);
        FL_FLASH_UnlockFlash(FLASHx,FL_FLASH_PROGRAM_KEY2);
        __set_PRIMASK(primask);
    }
    for (count = 0; count < FL_FLASH_PAGE_SIZE_BYTE; count += 4)
    {
        timeout = 0;
        FL_FLASH_EnableProgram(FLASHx);
        *((uint32_t*)address) =  *(data++);
        address += 4;
        while(1)
        {
            timeout++;
            if((timeout > FL_FLASH_ERASE_TIMEOUT)\
               ||(FL_FLASH_IsActiveFlag_ClockError(FLASHx))\
               ||(FL_FLASH_IsActiveFlag_KeyError(FLASHx))\
               ||(FL_FLASH_IsActiveFlag_AuthenticationError(FLASHx)))
            {
                /* 超时或出现错误 */
                ret = FAIL;
                break;
            }
            if(FL_FLASH_IsActiveFlag_ProgramComplete(FLASHx))
            {
                /*编程成功*/  
                FL_FLASH_ClearFlag_ProgramComplete(FLASHx);
                ret = PASS;
                break;
            }
        }        
    }
    FL_FLASH_LockFlash(FLASHx);
    FL_RCC_DisableGroup2OperationClock(FL_RCC_GROUP2_OPCLK_FLASH);
    return ret;
}

5. Serial communication test

if(uc_uart0_revok==1)//串口数据接收完成
{
	uc_uart0_revok=0;
	if(uc_uart0_rev[1]==0x01)//flash操作
	{
		if(uc_uart0_rev[2]==0x01)//读flash
		{
			FL_FLASH_Read_Dma(FLASH,0x00004000,(uint32_t * )DataTowrite,512);
			uc_uart0_sendbuf[0]=0x68;
			uc_uart0_sendbuf[1]=0x01;
			uc_uart0_sendbuf[2]=0x81;
			uc_uart0_sendbuf[3]=uc_uart0_rev[4];
			for(i1=0;i1<uc_uart0_rev[4];i1++)
			{
				uc_uart0_sendbuf[4+i1]=DataTowrite[i1];
			}
			uc_uart0_sendbuf[4+uc_uart0_rev[4]]=0x16;
			uc_uart0_sendlight=5+uc_uart0_rev[4];
			uart0_send();
		}
		else if(uc_uart0_rev[2]==0x04)//写flash
		{
			memset(DataTowrite,0,512);//清缓冲区数据
			for(i1=0;i1<uc_uart0_rev[3];i1++)
			{
				DataTowrite[i1]=uc_uart0_rev[4+i1];
			}
			FL_FLASH_PageErase(FLASH, 0x00004000);//页擦写
			FL_FLASH_Program_Page(FLASH,32,DataTowrite);
		}
			
	}
}

6. Serial port interrupt service function

void UART0_IRQHandler(void)
{
	uint8_t tmp08;
	
	//接收中断处理
	if((ENABLE == FL_UART_IsEnabledIT_RXBuffFull(UART0))
		&&(SET == FL_UART_IsActiveFlag_RXBuffFull(UART0)))
	{
		//中断转发接收到的数据
		uc_uart0_rev[uc_uart0_num]=FL_UART_ReadRXBuff(UART0);//接收中断标志可通过读取rxreg寄存器清除
		uc_uart0_num++;
		uc_uart0_revouttime=20;//200ms超时
		
	}
	
	//发送中断处理
	if((ENABLE == FL_UART_IsEnabledIT_TXShiftBuffEmpty(UART0))
		&&(SET == FL_UART_IsActiveFlag_TXShiftBuffEmpty(UART0)))
	{
		//发送中断标志可通过写txreg寄存器清除或txif写1清除
		//发送指定长度的数据
		if(uc_uart0_sendnum<uc_uart0_sendlight)
		{
			FL_UART_WriteTXBuff(UART0, uc_uart0_sendbuf[uc_uart0_sendnum]); //发送一个数据
			uc_uart0_sendnum++;
		}
		else
		{
			uc_uart0_sendnum=0;
			uc_uart0_sendlight=0;
		}

		FL_UART_ClearFlag_TXShiftBuffEmpty(UART0);	//清除发送中断标志
	}
}

7. Serial port sending function

//uart0 串口发送函数
void uart0_send(void)
{
	uc_uart0_sendnum=1;
	FL_UART_ClearFlag_TXShiftBuffEmpty(UART0);//清除UART发送移位寄存器标志
	FL_UART_EnableIT_TXShiftBuffEmpty(UART0);//启用UART发送移位寄存器中断
	FL_UART_WriteTXBuff(UART0, uc_uart0_sendbuf[0]);
	DelayMs(50);//软件延时
	FL_UART_DisableIT_TXShiftBuffEmpty(UART0); //禁用UART发送移位寄存器中断
	FL_UART_EnableIT_RXBuffFull(UART0);//启用UART接收缓冲区中断
}

8. Screenshot of the communication message of the serial port assistant

This post is from Domestic Chip Exchange

Latest reply

The last picture of the serial communication, is the read data returned consistent with the read data?   Details Published on 2021-3-9 20:31

赞赏

1

查看全部赞赏

 
 

1942

Posts

2

Resources
2
 

Thanks for sharing!

This post is from Domestic Chip Exchange
 
 
 

2w

Posts

341

Resources
3
 

Can you summarize the FM33LC046N storage Flash situation? Is there any stuck when reading Flash content?

This post is from Domestic Chip Exchange

Comments

A detailed introduction to the flash resources of FM33LC046N can be found in the official documentation. I only verified simple flash read and write operations. As for whether the flash will get stuck when reading, I have not found it yet.  Details Published on 2021-3-9 16:39
 
 
 

7422

Posts

2

Resources
4
 

I wrote so much code myself, this review was done very seriously!

This post is from Domestic Chip Exchange

Comments

New things always arouse people's interest, and the same is true for development boards  Details Published on 2021-3-9 16:47
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

6547

Posts

0

Resources
5
 

Key verification is required before flash erasure

This post is from Domestic Chip Exchange

Comments

[attachimg]527326[/attachimg][attachimg]527327[/attachimg]The document says that you need to verify before you can operate the flash.  Details Published on 2021-3-9 16:43
 
 
 

2w

Posts

74

Resources
6
 

It is definitely not easy to get FREE, keep working hard

This post is from Domestic Chip Exchange
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle

Comments

Thanks  Details Published on 2021-3-9 16:44
 
 
 

12

Posts

0

Resources
7
 
qwqwqw2088 posted on 2021-3-5 11:53 Can you summarize the FM33LC046N storage Flash situation, and whether it is stuck when reading Flash content

A detailed introduction to the flash resources of FM33LC046N can be found in the official documentation. I only verified simple flash read and write operations. As for whether the flash will get stuck when reading, I have not found it yet.

This post is from Domestic Chip Exchange
 
 
 

12

Posts

0

Resources
8
 
Jacktang posted on 2021-3-8 20:27 Key verification is required before flash erasure

The document says that you need to verify before you can operate the flash.

This post is from Domestic Chip Exchange
 
 
 

12

Posts

0

Resources
9
 
soso posted on 2021-3-9 16:02 It must be not easy to get FREE, keep it up, OP

Thanks

This post is from Domestic Chip Exchange
 
 
 

12

Posts

0

Resources
10
 
freebsder posted on 2021-3-6 21:40 I wrote so much code myself, and I did this review very seriously!

New things always arouse people's interest, and the same is true for development boards

This post is from Domestic Chip Exchange
 
 
 

6547

Posts

0

Resources
11
 

The last picture of the serial communication, is the read data returned consistent with the read data?

This post is from Domestic Chip Exchange

Comments

are different, green is sending, blue is receiving  Details Published on 2021-3-11 14:34
 
 
 

12

Posts

0

Resources
12
 
Jacktang posted on 2021-3-9 20:31 The last picture of serial communication, is the read data return consistent with the read data?

are different, green is sending, blue is receiving

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list