共2条
1/1 1 跳转至页
AT29LV160 一个AT29LV160的程序,非常简单!
问
/***********************************************************************/
/* This file is part of the ARM Toolchain package */
/* Copyright KEIL ELEKTRONIK GmbH 2003 - 2004 */
/***********************************************************************/
/* */
/* FlashDev.C: Flash Programming Functions adapted */
/* for AM29F160DT (16-bit Bus) */
/* */
/***********************************************************************/
#include "..\FlashOS.H" // FlashOS Structures
#define M8(adr) (*((volatile unsigned char *) (adr)))
#define M16(adr) (*((volatile unsigned short *) (adr)))
#define M32(adr) (*((volatile unsigned long *) (adr)))
#define STACK_SIZE 64 // Stack Size
union fsreg { // Flash Status Register
struct b {
unsigned int q0:1;
unsigned int q1:1;
unsigned int q2:1;
unsigned int q3:1;
unsigned int q4:1;
unsigned int q5:1;
unsigned int q6:1;
unsigned int q7:1;
} b;
unsigned int v;
} fsr;
unsigned long base_adr;
/*
* Check if Program/Erase completed
* Parameter: adr: Block Start Address
* Return Value: 0 - OK, 1 - Failed
*/
int Polling (unsigned long adr) {
unsigned int q6;
fsr.v = M16(adr);
q6 = fsr.b.q6;
do {
fsr.v = M16(adr);
if (fsr.b.q6 == q6) return (0); // Done
q6 = fsr.b.q6;
} while (fsr.b.q5 == 0); // Check for Timeout
fsr.v = M16(adr);
q6 = fsr.b.q6;
fsr.v = M16(adr);
if (fsr.b.q6 == q6) return (0); // Done
M16(adr) = 0xF0; // Reset Device
return (1); // Failed
}
/*
* Initialize Flash Programming Functions
* Parameter: adr: Device Base Address
* clk: Clock Frequency (Hz)
* Return Value: 0 - OK, 1 - Failed
*/
int Init (unsigned long adr, unsigned long clk) {
base_adr = adr;
return (0);
}
/*
* De-Initialize Flash Programming Functions
* Return Value: 0 - OK, 1 - Failed
*/
int UnInit (void) {
return (0);
}
/*
* Erase complete Flash Memory
* Return Value: 0 - OK, 1 - Failed
*/
int EraseChip (void) {
// Start Chip Erase Command
M16(base_adr + 0xAAA) = 0xAA;
M16(base_adr + 0x554) = 0x55;
M16(base_adr + 0xAAA) = 0x80;
M16(base_adr + 0xAAA) = 0xAA;
M16(base_adr + 0x554) = 0x55;
M16(base_adr + 0xAAA) = 0x10;
return (Polling(base_adr)); // Wait until Erase completed
}
/*
* Erase Sector in Flash Memory
* Parameter: adr: Sector Address
* Return Value: 0 - OK, 1 - Failed
*/
int EraseSector (unsigned long adr) {
// Start Erase Sector Command
M16(base_adr + 0xAAA) = 0xAA;
M16(base_adr + 0x554) = 0x55;
M16(base_adr + 0xAAA) = 0x80;
M16(base_adr + 0xAAA) = 0xAA;
M16(base_adr + 0x554) = 0x55;
M16(adr) = 0x30;
do {
fsr.v = M16(adr);
} while (fsr.b.q3 == 0); // Wait for Sector Erase Timeout
return (Polling(adr)); // Wait until Erase completed
}
/*
* Program Page in Flash Memory
* Parameter: adr: Page Start Address
* sz: Page Size
* buf: Page Data
* Return Value: 0 - OK, 1 - Failed
*/
int ProgramPage (unsigned long adr, unsigned long sz, unsigned char *buf) {
int i;
for (i = 0; i < ((sz+1)/2); i++) {
// Start Program Command
M16(base_adr + 0xAAA) = 0xAA;
M16(base_adr + 0x554) = 0x55;
M16(base_adr + 0xAAA) = 0xA0;
M16(adr) = *((unsigned short *) buf);
if (Polling(adr) != 0) return (1);
buf += 2;
adr += 2;
}
return (0);
}
/***********************************************************************/
/* This file is part of the ARM Toolchain package */
/* Copyright KEIL ELEKTRONIK GmbH 2003 - 2004 */
/***********************************************************************/
/* */
/* FlashDev.C: Device Description for AM29F160DT (16-bit Bus) */
/* */
/***********************************************************************/
#include "..\FlashOS.H" // FlashOS Structures
struct FlashDevice const FlashDevice = {
FLASH_DRV_VERS, // Driver Version, do not modify!
"AM29F160DT Flash", // Device Name
EXT16BIT, // Device Type
0x000000, // Device Start Address
0x200000, // Device Size in Bytes (2MB)
1024, // Programming Page Size
0, // Reserved, must be 0
0xFF, // Initial Content of Erased Memory
100, // Program Page Timeout 100 mSec
3000, // Erase Sector Timeout 3000 mSec
// Specify Size and Address of Sectors
0x10000, 0x000000, // Sector Size 64kB (31 Sectors)
0x08000, 0x1F0000, // Sector Size 32kB (1 Sector)
0x02000, 0x1F8000, // Sector Size 8kB (2 Sectors)
0x04000, 0x1FC000, // Sector Size 16kB (1 Sector)
SECTOR_END
};
答 1: regood!
/* This file is part of the ARM Toolchain package */
/* Copyright KEIL ELEKTRONIK GmbH 2003 - 2004 */
/***********************************************************************/
/* */
/* FlashDev.C: Flash Programming Functions adapted */
/* for AM29F160DT (16-bit Bus) */
/* */
/***********************************************************************/
#include "..\FlashOS.H" // FlashOS Structures
#define M8(adr) (*((volatile unsigned char *) (adr)))
#define M16(adr) (*((volatile unsigned short *) (adr)))
#define M32(adr) (*((volatile unsigned long *) (adr)))
#define STACK_SIZE 64 // Stack Size
union fsreg { // Flash Status Register
struct b {
unsigned int q0:1;
unsigned int q1:1;
unsigned int q2:1;
unsigned int q3:1;
unsigned int q4:1;
unsigned int q5:1;
unsigned int q6:1;
unsigned int q7:1;
} b;
unsigned int v;
} fsr;
unsigned long base_adr;
/*
* Check if Program/Erase completed
* Parameter: adr: Block Start Address
* Return Value: 0 - OK, 1 - Failed
*/
int Polling (unsigned long adr) {
unsigned int q6;
fsr.v = M16(adr);
q6 = fsr.b.q6;
do {
fsr.v = M16(adr);
if (fsr.b.q6 == q6) return (0); // Done
q6 = fsr.b.q6;
} while (fsr.b.q5 == 0); // Check for Timeout
fsr.v = M16(adr);
q6 = fsr.b.q6;
fsr.v = M16(adr);
if (fsr.b.q6 == q6) return (0); // Done
M16(adr) = 0xF0; // Reset Device
return (1); // Failed
}
/*
* Initialize Flash Programming Functions
* Parameter: adr: Device Base Address
* clk: Clock Frequency (Hz)
* Return Value: 0 - OK, 1 - Failed
*/
int Init (unsigned long adr, unsigned long clk) {
base_adr = adr;
return (0);
}
/*
* De-Initialize Flash Programming Functions
* Return Value: 0 - OK, 1 - Failed
*/
int UnInit (void) {
return (0);
}
/*
* Erase complete Flash Memory
* Return Value: 0 - OK, 1 - Failed
*/
int EraseChip (void) {
// Start Chip Erase Command
M16(base_adr + 0xAAA) = 0xAA;
M16(base_adr + 0x554) = 0x55;
M16(base_adr + 0xAAA) = 0x80;
M16(base_adr + 0xAAA) = 0xAA;
M16(base_adr + 0x554) = 0x55;
M16(base_adr + 0xAAA) = 0x10;
return (Polling(base_adr)); // Wait until Erase completed
}
/*
* Erase Sector in Flash Memory
* Parameter: adr: Sector Address
* Return Value: 0 - OK, 1 - Failed
*/
int EraseSector (unsigned long adr) {
// Start Erase Sector Command
M16(base_adr + 0xAAA) = 0xAA;
M16(base_adr + 0x554) = 0x55;
M16(base_adr + 0xAAA) = 0x80;
M16(base_adr + 0xAAA) = 0xAA;
M16(base_adr + 0x554) = 0x55;
M16(adr) = 0x30;
do {
fsr.v = M16(adr);
} while (fsr.b.q3 == 0); // Wait for Sector Erase Timeout
return (Polling(adr)); // Wait until Erase completed
}
/*
* Program Page in Flash Memory
* Parameter: adr: Page Start Address
* sz: Page Size
* buf: Page Data
* Return Value: 0 - OK, 1 - Failed
*/
int ProgramPage (unsigned long adr, unsigned long sz, unsigned char *buf) {
int i;
for (i = 0; i < ((sz+1)/2); i++) {
// Start Program Command
M16(base_adr + 0xAAA) = 0xAA;
M16(base_adr + 0x554) = 0x55;
M16(base_adr + 0xAAA) = 0xA0;
M16(adr) = *((unsigned short *) buf);
if (Polling(adr) != 0) return (1);
buf += 2;
adr += 2;
}
return (0);
}
/***********************************************************************/
/* This file is part of the ARM Toolchain package */
/* Copyright KEIL ELEKTRONIK GmbH 2003 - 2004 */
/***********************************************************************/
/* */
/* FlashDev.C: Device Description for AM29F160DT (16-bit Bus) */
/* */
/***********************************************************************/
#include "..\FlashOS.H" // FlashOS Structures
struct FlashDevice const FlashDevice = {
FLASH_DRV_VERS, // Driver Version, do not modify!
"AM29F160DT Flash", // Device Name
EXT16BIT, // Device Type
0x000000, // Device Start Address
0x200000, // Device Size in Bytes (2MB)
1024, // Programming Page Size
0, // Reserved, must be 0
0xFF, // Initial Content of Erased Memory
100, // Program Page Timeout 100 mSec
3000, // Erase Sector Timeout 3000 mSec
// Specify Size and Address of Sectors
0x10000, 0x000000, // Sector Size 64kB (31 Sectors)
0x08000, 0x1F0000, // Sector Size 32kB (1 Sector)
0x02000, 0x1F8000, // Sector Size 8kB (2 Sectors)
0x04000, 0x1FC000, // Sector Size 16kB (1 Sector)
SECTOR_END
};
答 1: regood!
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
vscode+cmake搭建雅特力AT32L021开发环境被打赏30分 | |
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 |