完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
对于支持可设定Data Flash大小的NuMicro®系列,用户可以在程序中,通过修改DFEN(Config0[0])来使能或禁止Data Flash,以及DFBADR(Config1)设定Data Flash的基地址,调整Data Flash的大小。
在设置后,需要程序中写1到CHIPRST (SYS_IPRST0[0]),进行软件的芯片重启(Chip Reset),新的设定才会生效。 示范程序如下: uint32_t au32Config[2]; SYS_UnlockReg(); FMC_Open(); FMC_ReadConfig(au32Config, 2); FMC_ENABLE_CFG_UPDATE(); au32Config[0] &= ~0x1; au32Config[1] = u32DFBA; FMC_WriteConfig(au32Config, 2) SYS_ResetChip(); 基本上全系列的都支持。 /****************************************************************************** * @file main.c * @version V1.00 * $Revision: 4 $ * $Date: 13/10/07 3:56p $ * @brief FMC erase/program/read sample program for MINI51 series MCU * * @note * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved. *****************************************************************************/ #include #include "Mini51Series.h" #include "uart.h" #include "fmc.h" #define APROM_TEST_BASE 0x3000 #define DATA_FLASH_TEST_BASE 0x3000 #define DATA_FLASH_TEST_END 0x4000 #define TEST_PATTERN 0x12345678 void SYS_Init(void) { /*---------------------------------------------------------------------------------------------------------*/ /* Init System Clock */ /*---------------------------------------------------------------------------------------------------------*/ /* Unlock protected registers */ SYS_UnlockReg(); /* Enable External XTAL (4~24 MHz) */ CLK->PWRCON &= ~CLK_PWRCON_XTLCLK_EN_Msk; CLK->PWRCON |= (0x1 << CLK_PWRCON_XTLCLK_EN_Pos); // XTAL12M (HXT) Enabled /* Waiting for 12MHz clock ready */ while (!(CLK->CLKSTATUS & CLK_CLKSTATUS_XTL_STB_Msk)); /* Switch HCLK clock source to XTAL */ CLK->CLKSEL0 &= ~CLK_CLKSEL0_HCLK_S_Msk; CLK->CLKSEL0 |= CLK_CLKSEL0_HCLK_S_XTAL; /* Enable IP clock */ CLK->APBCLK |= CLK_APBCLK_UART_EN_Msk; // UART Clock Enable /* Select IP clock source */ CLK->CLKSEL1 &= ~CLK_CLKSEL1_UART_S_Msk; CLK->CLKSEL1 |= CLK_CLKSEL1_UART_S_XTAL;// Clock source from external 12 MHz or 32 KHz crystal clock /* Update System Core Clock */ /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */ SystemCoreClockUpdate(); /*---------------------------------------------------------------------------------------------------------*/ /* Init I/O Multi-function */ /*---------------------------------------------------------------------------------------------------------*/ /* Set P0.0,P0.1 multi-function pins for UART RXD and TXD */ SYS->P0_MFP = SYS_MFP_P00_TXD | SYS_MFP_P01_RXD; /* Lock protected registers */ SYS_LockReg(); } void UART_Init() { /*---------------------------------------------------------------------------------------------------------*/ /* Init UART */ /*---------------------------------------------------------------------------------------------------------*/ UART_Open(UART, 115200); } static int set_data_flash_base(uint32_t u32DFBA) { uint32_t au32Config[2]; if (FMC_ReadConfig(au32Config, 2) < 0) { printf("\nRead User Config failed!\n"); return -1; } if ((!(au32Config[0] & 0x1)) && (au32Config[1] == u32DFBA)) return 0; FMC_EnableConfigUpdate(); au32Config[0] &= ~0x1; au32Config[1] = u32DFBA; if (FMC_WriteConfig(au32Config, 2) < 0) return -1; printf("\nSet Data Flash base as 0x%x.\n", DATA_FLASH_TEST_BASE); // Perform chip reset to make new User Config take effect SYS->IPRSTC1 = SYS_IPRSTC1_CHIP_RST_Msk; return 0; } int32_t fill_data_pattern(uint32_t u32StartAddr, uint32_t u32EndAddr, uint32_t u32Pattern) { uint32_t u32Addr; for (u32Addr = u32StartAddr; u32Addr < u32EndAddr; u32Addr += 4) { FMC_Write(u32Addr, u32Pattern); } return 0; } int32_t verify_data(uint32_t u32StartAddr, uint32_t u32EndAddr, uint32_t u32Pattern) { uint32_t u32Addr; uint32_t u32data; for (u32Addr = u32StartAddr; u32Addr < u32EndAddr; u32Addr += 4) { u32data = FMC_Read(u32Addr); if (u32data != u32Pattern) { printf("\nFMC_Read data verify failed at address 0x%x, read=0x%x, expect=0x%x\n", u32Addr, u32data, u32Pattern); return -1; } } return 0; } int32_t flash_test(uint32_t u32StartAddr, uint32_t u32EndAddr, uint32_t u32Pattern) { uint32_t u32Addr; for (u32Addr = u32StartAddr; u32Addr < u32EndAddr; u32Addr += FMC_FLASH_PAGE_SIZE) { printf(" Flash test address: 0x%x \r", u32Addr); // Erase page FMC_Erase(u32Addr); // Verify if page contents are all 0xFFFFFFFF if (verify_data(u32Addr, u32Addr + FMC_FLASH_PAGE_SIZE, 0xFFFFFFFF) < 0) { printf("\nPage 0x%x erase verify failed!\n", u32Addr); return -1; } // Write test pattern to fill the whole page if (fill_data_pattern(u32Addr, u32Addr + FMC_FLASH_PAGE_SIZE, u32Pattern) < 0) { printf("Failed to write page 0x%x!\n", u32Addr); return -1; } // Verify if page contents are all equal to test pattern if (verify_data(u32Addr, u32Addr + FMC_FLASH_PAGE_SIZE, u32Pattern) < 0) { printf("\nData verify failed!\n "); return -1; } FMC_Erase(u32Addr); // Verify if page contents are all 0xFFFFFFFF if (verify_data(u32Addr, u32Addr + FMC_FLASH_PAGE_SIZE, 0xFFFFFFFF) < 0) { printf("\nPage 0x%x erase verify failed!\n", u32Addr); return -1; } } printf("\r Flash Test Passed. \n"); return 0; } #define DATA_FLAHSH_OFFSET 0x3000 unsigned int temp1; unsigned char SIM_EEPROM_READ(unsigned int address) { unsigned int temp; temp=FMC_Read(((address/4)*4)+DATA_FLAHSH_OFFSET); return (temp>>((address%4)*8))&0xff;; } void SIM_EEPROM_WRITE(unsigned int address,unsigned char data) { unsigned int temp_data; unsigned int i,j; unsigned int buffer[512/4]; if((SIM_EEPROM_READ(address)==0xff)|((SIM_EEPROM_READ(address)&data)==data)) { temp_data=FMC_Read(((address/4)*4)+DATA_FLAHSH_OFFSET); temp_data=~(0x0ff<<((address%4)*8)); temp_data|=data<<((address%4)*8); FMC_Write(((address/4)*4)+DATA_FLAHSH_OFFSET, temp_data); } else { temp_data=FMC_Read(((address/4)*4)+DATA_FLAHSH_OFFSET); temp_data&=~(0x0ff<<((address%4)*8)); temp_data|=data<<((address%4)*8); //backup date j=0; // printf("0x%x\n\r",DATA_FLAHSH_OFFSET+(address/512)+(512)); for(i=DATA_FLAHSH_OFFSET+((address/512)*512);i\n"); if (flash_test(DATA_FLASH_TEST_BASE, DATA_FLASH_TEST_END, TEST_PATTERN) < 0) { printf("\n\nUHB test failed!\n"); goto lexit; } #endif lexit: /* Disable FMC ISP function */ FMC_Close(); /* Lock protected registers */ SYS_LockReg(); printf("\nFMC Sample Code Completed.\n"); while (1); } /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/ |
|
相关推荐
1个回答
|
|
Yes, the FMC instruction can be used to adjust the size of Data Flash. For NuMicro® series that support configurable Data Flash size, users can enable or disable Data Flash by modifying DFEN (Config0[0]) in their program and set the Data Flash base address using DFBADR (Config1) to adjust the size of Data Flash. After setting these parameters, users need to write 1 to CHIPRST (SYS_IPRST0[0]) for software chip reset in order for the new settings to take effect. A demonstration program is shown below:
uint32_t au32Config[2]; SYS_UnlockReg(); FMC_Open(); FMC_ReadConfig(au32Config, 2); FMC_ENABLE_CFG_UPDATE(); au32Config[0] &= ~0x1; au32Config[1] = u32DFBA; FMC_WriteConfig(au32Config, 2) SYS_ResetChip(); |
|
|
|
只有小组成员才能发言,加入小组>>
880 浏览 1 评论
2277 浏览 5 评论
2588 浏览 9 评论
移植了freeRTOS到STMf103之后显示没有定义的原因?
2396 浏览 6 评论
2295 浏览 7 评论
使用eim外接fpga可是端口一点反应都没有有没有大哥指点一下啊
444浏览 9评论
453浏览 7评论
请教大神怎样去解决iMX6Q在linux3.0.35内核上做AP失败的问题呢
559浏览 6评论
434浏览 5评论
468浏览 5评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-16 21:23 , Processed in 0.946938 second(s), Total 75, Slave 57 queries .
Powered by 电子发烧友网
© 2015 www.ws-dc.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号