最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

三星K9F1G08U0E(128MB,NANDFLASH)STM32平台驱动程序(模拟时序)

IT圈 admin 24浏览 0评论

2023年12月6日发(作者:卑刚捷)

三星K9F1G08U0E(128MB,NANDFLASH)STM32平台驱动程序

(模拟时序)

STM32平台下模拟时序驱动K9F1G08U0E,主要目的为了解、学习NAND FLASH的功能特性,没有使用STM32的FSMC(火龙开发板硬件

为模拟时序驱动),纯粹自娱自乐,如对你有帮助,不胜荣幸,呵呵。

C文件内容:

1 #include "NAND512W3A2C.h"

2 /*

3 作者:毕小乐

4 日期:2019.01.24

5 版本:V1.00

6

7 驱动代码针对K9F1G08U0E时序而写,K9F1G08U0E与NAND512W3A2C,Pin to Pin兼容。

8 驱动运行平台STM32F103。

9 驱动实现功能:

10 1)Page Read

11 2) Page Program

12 3) Block Erase

13 4) Read Status

14 5) Read ID

15 PE0~PE7 -> DB00~DB07

16 PD6 -> CL

17 PD5 -> AL

18 PD14 -> W

19 PD15 -> R

20 PD7 -> CS

21 PB5 -> R/B

22 */

23 static void NAND512_Delay_uS(int tick)

24 {

25 int i;

26 while(tick>0)

27 {

28 tick--;

29 for(i=0;i<10;i++)

30 __nop();

31 }

32 }

33 void NAND512_DB_OutPut(void)

34 {

35 GPIO_InitTypeDef GPIO_InitStructure;

36

37 GPIO__Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3

38 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;

39 GPIO__Speed = GPIO_Speed_50MHz;

40 GPIO__Mode = GPIO_Mode_Out_PP;

41 GPIO_Init(GPIOE, &GPIO_InitStructure);

42 }

43 void NAND512_DB_InPut(void)

44 {

45 GPIO_InitTypeDef GPIO_InitStructure;

46

47 GPIO__Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3

48 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;

49 GPIO__Speed = GPIO_Speed_50MHz;

50 GPIO__Mode = GPIO_Mode_IN_FLOATING;

51 GPIO_Init(GPIOE, &GPIO_InitStructure);

52 }

53 char NAND512_DB_Read(void)

54 {

55 char dat;

56 NAND512_DB_InPut();

57 __nop();

58 dat = GPIO_ReadInputData(GPIOE) & 0x00FF;

59 return dat;

60 }

61 void NAND512_DB_Write(char Data)

62 {

63 u16 temp;

64 NAND512_DB_OutPut();

65 // __nop();

66 temp = GPIO_ReadOutputData(GPIOE) & 0xFF00;

67 temp = temp | Data;

68 GPIO_Write(GPIOE,temp);

69 return;

70 } 71 void NAND512_IO_Init(void) 72 { 73 GPIO_InitTypeDef GPIO_InitStructure; 74

75 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD 76 | RCC_APB2Periph_GPIOE, ENABLE); 77

78 /*CL*/ 79 GPIO__Pin = NAND512_CL_PIN; 80 GPIO__Speed = GPIO_Speed_50MHz; 81 GPIO__Mode = GPIO_Mode_Out_PP; 82 GPIO_Init(NAND512_CL_PORT, &GPIO_InitStructure); 83

84 /*AL*/ 85 GPIO__Pin = NAND512_AL_PIN; 86 GPIO_Init(NAND512_AL_PORT, &GPIO_InitStructure); 87

88 /*W*/ 89 GPIO__Pin = NAND512_W_PIN; 90 GPIO_Init(NAND512_W_PORT, &GPIO_InitStructure); 91

92 /*R*/ 93 GPIO__Pin = NAND512_R_PIN; 94 GPIO_Init(NAND512_R_PORT, &GPIO_InitStructure); 95

96 /*CE*/ 97 GPIO__Pin = NAND512_CE_PIN; 98 GPIO_Init(NAND512_CE_PORT, &GPIO_InitStructure); 99

100 /*R/B*/101 GPIO__Pin = NAND512_RB_PIN;102 GPIO__Speed = GPIO_Speed_50MHz;103 GPIO__Mode = GPIO_Mode_IPU;104 GPIO_Init(NAND512_RB_PORT, &GPIO_InitStructure);105

106 NAND512_CL_LOW;107 NAND512_AL_LOW;108 NAND512_R_HIGH;109 NAND512_W_HIGH;110 NAND512_CE_HIGH;111 }112

113 //读状态寄存器信息114 char NAND512_Read_Status(void)115 {116 char dat;117

118 NAND512_CL_LOW;119 NAND512_W_HIGH;120 NAND512_R_HIGH;121 NAND512_CE_HIGH;122 NOP;123

124 NAND512_Delay_uS(5);125 NAND512_CL_HIGH;126 NOP;127 NOP;128 NAND512_CE_LOW;129 NOP;130 NOP;131 NOP;132 NAND512_W_LOW;133 NAND512_DB_Write(0x70);134 NOP;135 NAND512_W_HIGH;136

137 NAND512_Delay_uS(5);138 NAND512_CL_LOW;139 NOP;140 NOP;141 //CE状态保持不变142

143 NAND512_Delay_uS(10);144 NAND512_R_LOW;145 NOP;146 dat = NAND512_DB_Read();147 NAND512_Delay_uS(5);148 NAND512_R_LOW;149 NAND512_Delay_uS(5);150 NAND512_CE_HIGH;

151 NAND512_Delay_uS(20);152

153 return dat;154 }155

156 void NAND512_Read_ID(char* Buf)157 {158 char i = 0;159

160 NAND512_CL_LOW;161 NAND512_AL_LOW;162 NAND512_R_HIGH;163 NAND512_W_HIGH;164 NAND512_CE_HIGH;165 NAND512_Delay_uS(5);166

167 NAND512_CL_HIGH;168 NAND512_W_LOW;169 NAND512_Delay_uS(5);170 NAND512_CE_LOW;171 NAND512_DB_Write(0x90);172 NAND512_Delay_uS(5);173 NAND512_W_HIGH;174 NAND512_Delay_uS(5);175

176 NAND512_CL_LOW;177 NAND512_Delay_uS(20);178 NAND512_AL_HIGH;179 NAND512_Delay_uS(20);180 NAND512_W_LOW;181 NAND512_DB_Write(0x00); //写地址0182 NAND512_Delay_uS(5);183 NAND512_W_HIGH;184 NAND512_Delay_uS(10);185 NAND512_AL_LOW;186 NAND512_Delay_uS(20);187

188 for(i=0;i<5;i++)189 {190 NAND512_R_LOW;191 NAND512_Delay_uS(10);192 Buf[i] = NAND512_DB_Read();193 NAND512_R_HIGH;194 NAND512_Delay_uS(10);195 }196

197 return ;

198 }199

200 void NAND512_Page_Read(char* Buf,int Len,int Add)201 {202 int Bank_Index,Page_Index,Page_Start_Add;203 int Add_New,j;204 char i;205

206 Bank_Index = Add / BANK_SIZE;207 Page_Index = (Add % BANK_SIZE) / PAGE_SIZE;208 Page_Start_Add = Add % PAGE_SIZE;209 Add_New = (((Bank_Index<<6) | Page_Index)<<16) | Page_Start_Add;210

211 NAND512_CL_LOW;212 NAND512_AL_LOW;213 NAND512_W_HIGH;214 NAND512_R_HIGH;215 NAND512_CE_HIGH;216 NAND512_Delay_uS(10);217

218 NAND512_CE_LOW;219 NAND512_Delay_uS(5);220 NAND512_CL_HIGH;221 NAND512_W_LOW;222 NAND512_DB_Write(0x00);223 NAND512_Delay_uS(5);224 NAND512_W_HIGH;225 NAND512_Delay_uS(5);226 NAND512_CL_LOW;227 NAND512_Delay_uS(5);228 NAND512_AL_HIGH;229 NAND512_Delay_uS(5);230

231 //发送地址232 for(i=0;i<4;i++)233 {234 NAND512_W_LOW;235 NAND512_Delay_uS(5);236 NAND512_DB_Write(Add_New>>8*i);237 NAND512_Delay_uS(10);238 NAND512_W_HIGH;239 NAND512_Delay_uS(10);240 }241 NAND512_AL_LOW;242 NAND512_Delay_uS(5);243 NAND512_CL_HIGH;244 NAND512_Delay_uS(5);245 NAND512_W_LOW;246 NAND512_Delay_uS(5);247 NAND512_DB_Write(0x30);248 NAND512_Delay_uS(5);249 NAND512_W_HIGH;250 NAND512_Delay_uS(5);251 NAND512_CL_LOW;252 NAND512_Delay_uS(5);253

254 while(NAND512_RB_STATUS == 0);255 NAND512_Delay_uS(5);256

257 for(j=0;j

267 return;

268 }269

270 char NAND512_Page_Write(char* Buf,int Len,int Add)271 {272 int Bank_Index,Page_Index,Page_Start_Add;273 int Add_New,j;274 char i,Status;275

276 Bank_Index = Add / BANK_SIZE;277 Page_Index = (Add % BANK_SIZE) / PAGE_SIZE;278 Page_Start_Add = Add % PAGE_SIZE;279 Add_New = (((Bank_Index<<6) | Page_Index)<<16) | Page_Start_Add;280

281 NAND512_CL_LOW;282 NAND512_AL_LOW;283 NAND512_W_HIGH;284 NAND512_R_HIGH;285 NAND512_CE_HIGH;286 NAND512_Delay_uS(10);287

288 NAND512_CE_LOW;289 NAND512_Delay_uS(5);290 NAND512_CL_HIGH;291 NAND512_W_LOW;292 NAND512_DB_Write(0x80);293 NAND512_Delay_uS(5);294 NAND512_W_HIGH;295 NAND512_Delay_uS(5);296 NAND512_CL_LOW;297 NAND512_Delay_uS(5);298 NAND512_AL_HIGH;299 NAND512_Delay_uS(5);300

301 //发送地址302 for(i=0;i<4;i++)303 {304 NAND512_W_LOW;305 NAND512_Delay_uS(5);306 NAND512_DB_Write(Add_New>>8*i);307 NAND512_Delay_uS(10);308 NAND512_W_HIGH;309 NAND512_Delay_uS(10);310 }311 NAND512_AL_LOW;312 NAND512_Delay_uS(5);313

314 for(j=0;j

324 NAND512_CL_HIGH;325 NAND512_Delay_uS(5);326 NAND512_W_LOW;327 NAND512_Delay_uS(5);328 NAND512_DB_Write(0x10);329 NAND512_Delay_uS(5);330 NAND512_W_HIGH;331 NAND512_Delay_uS(5);332

333 while(NAND512_RB_STATUS == 0);334 NAND512_Delay_uS(5);335

336 Status = NAND512_Read_Status();337

338 if((Status & 0x01) == 0)339 return 1;340 else341 return 0;

342 }343

344 char NAND512_Block_Erase(int Add)345 {346 int Bank_Index,Page_Index;347 int Add_New;348 char i,Status;349

350 Bank_Index = Add / BANK_SIZE;351 Page_Index = (Add % BANK_SIZE) / PAGE_SIZE;352 Add_New = (Bank_Index<<6) | Page_Index;353

354 NAND512_CL_LOW;355 NAND512_AL_LOW;356 NAND512_W_HIGH;357 NAND512_R_HIGH;358 NAND512_CE_HIGH;359 NAND512_Delay_uS(10);360

361 NAND512_CE_LOW;362 NAND512_Delay_uS(5);363 NAND512_CL_HIGH;364 NAND512_W_LOW;365 NAND512_DB_Write(0x60);366 NAND512_Delay_uS(5);367 NAND512_W_HIGH;368 NAND512_Delay_uS(5);369 NAND512_CL_LOW;370 NAND512_Delay_uS(5);371 NAND512_AL_HIGH;372 NAND512_Delay_uS(5);373

374 //发送地址375 for(i=0;i<2;i++)376 {377 NAND512_W_LOW;378 NAND512_Delay_uS(5);379 NAND512_DB_Write(Add_New>>8*i);380 NAND512_Delay_uS(10);381 NAND512_W_HIGH;382 NAND512_Delay_uS(10);383 }384 NAND512_AL_LOW;385 NAND512_Delay_uS(5);386

387 NAND512_CL_HIGH;388 NAND512_Delay_uS(5);389 NAND512_W_LOW;390 NAND512_Delay_uS(5);391 NAND512_DB_Write(0xD0);392 NAND512_Delay_uS(5);393 NAND512_W_HIGH;394 NAND512_Delay_uS(5);395 NAND512_CL_LOW;396 NAND512_Delay_uS(5);397

398 while(NAND512_RB_STATUS == 0);399 NAND512_Delay_uS(5);400

401 Status = NAND512_Read_Status();402

403 if((Status & 0x01) == 0)404 return 1;405 else406 return 0; 407 }

H文件内容:

1 #ifndef NAND512W3A2C__H

2 #define NAND512W3A2C__H

3

4 #include "stm32f10x.h"

5

6 #define NAND512_CL_PORT GPIOD

7 #define NAND512_AL_PORT GPIOD

8 #define NAND512_W_PORT GPIOD

9 #define NAND512_R_PORT GPIOD

10 #define NAND512_CE_PORT GPIOD

11 #define NAND512_RB_PORT GPIOB

12 #define NAND512_WP_PORT /*GPIOD*/

13

14 #define NAND512_CL_PIN GPIO_Pin_6

15 #define NAND512_AL_PIN GPIO_Pin_5

16 #define NAND512_W_PIN GPIO_Pin_14

17 #define NAND512_R_PIN GPIO_Pin_15

18 #define NAND512_CE_PIN GPIO_Pin_7

19 #define NAND512_RB_PIN GPIO_Pin_5

20 #define NAND512_WP_PIN /*GPIO_Pin_5*/

21

22 #define NAND512_CL_CLK RCC_APB2Periph_GPIOD

23 #define NAND512_AL_CLK RCC_APB2Periph_GPIOD

24 #define NAND512_W_CLK RCC_APB2Periph_GPIOD

25 #define NAND512_R_CLK RCC_APB2Periph_GPIOD

26 #define NAND512_CE_CLK RCC_APB2Periph_GPIOD

27 #define NAND512_RB_CLK RCC_APB2Periph_GPIOB

28 #define NAND512_WP_CLK /*RCC_APB2Periph_GPIOD*/

29

30 #define NAND512_CE_LOW GPIO_ResetBits(NAND512_CE_PORT,NAND512_CE_PIN)

31 #define NAND512_CE_HIGH GPIO_SetBits(NAND512_CE_PORT,NAND512_CE_PIN)

32 #define NAND512_CL_LOW GPIO_ResetBits(NAND512_CL_PORT,NAND512_CL_PIN)

33 #define NAND512_CL_HIGH GPIO_SetBits(NAND512_CL_PORT,NAND512_CL_PIN)

34 #define NAND512_AL_LOW GPIO_ResetBits(NAND512_AL_PORT,NAND512_AL_PIN)

35 #define NAND512_AL_HIGH GPIO_SetBits(NAND512_AL_PORT,NAND512_AL_PIN)

36 #define NAND512_W_LOW GPIO_ResetBits(NAND512_W_PORT,NAND512_W_PIN)

37 #define NAND512_W_HIGH GPIO_SetBits(NAND512_W_PORT,NAND512_W_PIN)

38 #define NAND512_R_LOW GPIO_ResetBits(NAND512_R_PORT,NAND512_R_PIN)

39 #define NAND512_R_HIGH GPIO_SetBits(NAND512_R_PORT,NAND512_R_PIN)

40

41 #define NAND512_RB_STATUS GPIO_ReadInputDataBit(NAND512_RB_PORT,NAND512_RB_PIN)

42

43 #define NOP __nop()

44 #define BANK_SIZE 131072

45 #define PAGE_SIZE 2048

46

47 extern void NAND512_IO_Init(void);

48 extern char NAND512_Read_Status(void);

49 extern void NAND512_Read_ID(char* Buf);

50 extern void NAND512_Page_Read(char* Buf,int Len,int Add);

51 extern char NAND512_Page_Write(char* Buf,int Len,int Add);

52 extern char NAND512_Block_Erase(int Add);

53 #endif

2023年12月6日发(作者:卑刚捷)

三星K9F1G08U0E(128MB,NANDFLASH)STM32平台驱动程序

(模拟时序)

STM32平台下模拟时序驱动K9F1G08U0E,主要目的为了解、学习NAND FLASH的功能特性,没有使用STM32的FSMC(火龙开发板硬件

为模拟时序驱动),纯粹自娱自乐,如对你有帮助,不胜荣幸,呵呵。

C文件内容:

1 #include "NAND512W3A2C.h"

2 /*

3 作者:毕小乐

4 日期:2019.01.24

5 版本:V1.00

6

7 驱动代码针对K9F1G08U0E时序而写,K9F1G08U0E与NAND512W3A2C,Pin to Pin兼容。

8 驱动运行平台STM32F103。

9 驱动实现功能:

10 1)Page Read

11 2) Page Program

12 3) Block Erase

13 4) Read Status

14 5) Read ID

15 PE0~PE7 -> DB00~DB07

16 PD6 -> CL

17 PD5 -> AL

18 PD14 -> W

19 PD15 -> R

20 PD7 -> CS

21 PB5 -> R/B

22 */

23 static void NAND512_Delay_uS(int tick)

24 {

25 int i;

26 while(tick>0)

27 {

28 tick--;

29 for(i=0;i<10;i++)

30 __nop();

31 }

32 }

33 void NAND512_DB_OutPut(void)

34 {

35 GPIO_InitTypeDef GPIO_InitStructure;

36

37 GPIO__Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3

38 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;

39 GPIO__Speed = GPIO_Speed_50MHz;

40 GPIO__Mode = GPIO_Mode_Out_PP;

41 GPIO_Init(GPIOE, &GPIO_InitStructure);

42 }

43 void NAND512_DB_InPut(void)

44 {

45 GPIO_InitTypeDef GPIO_InitStructure;

46

47 GPIO__Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3

48 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;

49 GPIO__Speed = GPIO_Speed_50MHz;

50 GPIO__Mode = GPIO_Mode_IN_FLOATING;

51 GPIO_Init(GPIOE, &GPIO_InitStructure);

52 }

53 char NAND512_DB_Read(void)

54 {

55 char dat;

56 NAND512_DB_InPut();

57 __nop();

58 dat = GPIO_ReadInputData(GPIOE) & 0x00FF;

59 return dat;

60 }

61 void NAND512_DB_Write(char Data)

62 {

63 u16 temp;

64 NAND512_DB_OutPut();

65 // __nop();

66 temp = GPIO_ReadOutputData(GPIOE) & 0xFF00;

67 temp = temp | Data;

68 GPIO_Write(GPIOE,temp);

69 return;

70 } 71 void NAND512_IO_Init(void) 72 { 73 GPIO_InitTypeDef GPIO_InitStructure; 74

75 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD 76 | RCC_APB2Periph_GPIOE, ENABLE); 77

78 /*CL*/ 79 GPIO__Pin = NAND512_CL_PIN; 80 GPIO__Speed = GPIO_Speed_50MHz; 81 GPIO__Mode = GPIO_Mode_Out_PP; 82 GPIO_Init(NAND512_CL_PORT, &GPIO_InitStructure); 83

84 /*AL*/ 85 GPIO__Pin = NAND512_AL_PIN; 86 GPIO_Init(NAND512_AL_PORT, &GPIO_InitStructure); 87

88 /*W*/ 89 GPIO__Pin = NAND512_W_PIN; 90 GPIO_Init(NAND512_W_PORT, &GPIO_InitStructure); 91

92 /*R*/ 93 GPIO__Pin = NAND512_R_PIN; 94 GPIO_Init(NAND512_R_PORT, &GPIO_InitStructure); 95

96 /*CE*/ 97 GPIO__Pin = NAND512_CE_PIN; 98 GPIO_Init(NAND512_CE_PORT, &GPIO_InitStructure); 99

100 /*R/B*/101 GPIO__Pin = NAND512_RB_PIN;102 GPIO__Speed = GPIO_Speed_50MHz;103 GPIO__Mode = GPIO_Mode_IPU;104 GPIO_Init(NAND512_RB_PORT, &GPIO_InitStructure);105

106 NAND512_CL_LOW;107 NAND512_AL_LOW;108 NAND512_R_HIGH;109 NAND512_W_HIGH;110 NAND512_CE_HIGH;111 }112

113 //读状态寄存器信息114 char NAND512_Read_Status(void)115 {116 char dat;117

118 NAND512_CL_LOW;119 NAND512_W_HIGH;120 NAND512_R_HIGH;121 NAND512_CE_HIGH;122 NOP;123

124 NAND512_Delay_uS(5);125 NAND512_CL_HIGH;126 NOP;127 NOP;128 NAND512_CE_LOW;129 NOP;130 NOP;131 NOP;132 NAND512_W_LOW;133 NAND512_DB_Write(0x70);134 NOP;135 NAND512_W_HIGH;136

137 NAND512_Delay_uS(5);138 NAND512_CL_LOW;139 NOP;140 NOP;141 //CE状态保持不变142

143 NAND512_Delay_uS(10);144 NAND512_R_LOW;145 NOP;146 dat = NAND512_DB_Read();147 NAND512_Delay_uS(5);148 NAND512_R_LOW;149 NAND512_Delay_uS(5);150 NAND512_CE_HIGH;

151 NAND512_Delay_uS(20);152

153 return dat;154 }155

156 void NAND512_Read_ID(char* Buf)157 {158 char i = 0;159

160 NAND512_CL_LOW;161 NAND512_AL_LOW;162 NAND512_R_HIGH;163 NAND512_W_HIGH;164 NAND512_CE_HIGH;165 NAND512_Delay_uS(5);166

167 NAND512_CL_HIGH;168 NAND512_W_LOW;169 NAND512_Delay_uS(5);170 NAND512_CE_LOW;171 NAND512_DB_Write(0x90);172 NAND512_Delay_uS(5);173 NAND512_W_HIGH;174 NAND512_Delay_uS(5);175

176 NAND512_CL_LOW;177 NAND512_Delay_uS(20);178 NAND512_AL_HIGH;179 NAND512_Delay_uS(20);180 NAND512_W_LOW;181 NAND512_DB_Write(0x00); //写地址0182 NAND512_Delay_uS(5);183 NAND512_W_HIGH;184 NAND512_Delay_uS(10);185 NAND512_AL_LOW;186 NAND512_Delay_uS(20);187

188 for(i=0;i<5;i++)189 {190 NAND512_R_LOW;191 NAND512_Delay_uS(10);192 Buf[i] = NAND512_DB_Read();193 NAND512_R_HIGH;194 NAND512_Delay_uS(10);195 }196

197 return ;

198 }199

200 void NAND512_Page_Read(char* Buf,int Len,int Add)201 {202 int Bank_Index,Page_Index,Page_Start_Add;203 int Add_New,j;204 char i;205

206 Bank_Index = Add / BANK_SIZE;207 Page_Index = (Add % BANK_SIZE) / PAGE_SIZE;208 Page_Start_Add = Add % PAGE_SIZE;209 Add_New = (((Bank_Index<<6) | Page_Index)<<16) | Page_Start_Add;210

211 NAND512_CL_LOW;212 NAND512_AL_LOW;213 NAND512_W_HIGH;214 NAND512_R_HIGH;215 NAND512_CE_HIGH;216 NAND512_Delay_uS(10);217

218 NAND512_CE_LOW;219 NAND512_Delay_uS(5);220 NAND512_CL_HIGH;221 NAND512_W_LOW;222 NAND512_DB_Write(0x00);223 NAND512_Delay_uS(5);224 NAND512_W_HIGH;225 NAND512_Delay_uS(5);226 NAND512_CL_LOW;227 NAND512_Delay_uS(5);228 NAND512_AL_HIGH;229 NAND512_Delay_uS(5);230

231 //发送地址232 for(i=0;i<4;i++)233 {234 NAND512_W_LOW;235 NAND512_Delay_uS(5);236 NAND512_DB_Write(Add_New>>8*i);237 NAND512_Delay_uS(10);238 NAND512_W_HIGH;239 NAND512_Delay_uS(10);240 }241 NAND512_AL_LOW;242 NAND512_Delay_uS(5);243 NAND512_CL_HIGH;244 NAND512_Delay_uS(5);245 NAND512_W_LOW;246 NAND512_Delay_uS(5);247 NAND512_DB_Write(0x30);248 NAND512_Delay_uS(5);249 NAND512_W_HIGH;250 NAND512_Delay_uS(5);251 NAND512_CL_LOW;252 NAND512_Delay_uS(5);253

254 while(NAND512_RB_STATUS == 0);255 NAND512_Delay_uS(5);256

257 for(j=0;j

267 return;

268 }269

270 char NAND512_Page_Write(char* Buf,int Len,int Add)271 {272 int Bank_Index,Page_Index,Page_Start_Add;273 int Add_New,j;274 char i,Status;275

276 Bank_Index = Add / BANK_SIZE;277 Page_Index = (Add % BANK_SIZE) / PAGE_SIZE;278 Page_Start_Add = Add % PAGE_SIZE;279 Add_New = (((Bank_Index<<6) | Page_Index)<<16) | Page_Start_Add;280

281 NAND512_CL_LOW;282 NAND512_AL_LOW;283 NAND512_W_HIGH;284 NAND512_R_HIGH;285 NAND512_CE_HIGH;286 NAND512_Delay_uS(10);287

288 NAND512_CE_LOW;289 NAND512_Delay_uS(5);290 NAND512_CL_HIGH;291 NAND512_W_LOW;292 NAND512_DB_Write(0x80);293 NAND512_Delay_uS(5);294 NAND512_W_HIGH;295 NAND512_Delay_uS(5);296 NAND512_CL_LOW;297 NAND512_Delay_uS(5);298 NAND512_AL_HIGH;299 NAND512_Delay_uS(5);300

301 //发送地址302 for(i=0;i<4;i++)303 {304 NAND512_W_LOW;305 NAND512_Delay_uS(5);306 NAND512_DB_Write(Add_New>>8*i);307 NAND512_Delay_uS(10);308 NAND512_W_HIGH;309 NAND512_Delay_uS(10);310 }311 NAND512_AL_LOW;312 NAND512_Delay_uS(5);313

314 for(j=0;j

324 NAND512_CL_HIGH;325 NAND512_Delay_uS(5);326 NAND512_W_LOW;327 NAND512_Delay_uS(5);328 NAND512_DB_Write(0x10);329 NAND512_Delay_uS(5);330 NAND512_W_HIGH;331 NAND512_Delay_uS(5);332

333 while(NAND512_RB_STATUS == 0);334 NAND512_Delay_uS(5);335

336 Status = NAND512_Read_Status();337

338 if((Status & 0x01) == 0)339 return 1;340 else341 return 0;

342 }343

344 char NAND512_Block_Erase(int Add)345 {346 int Bank_Index,Page_Index;347 int Add_New;348 char i,Status;349

350 Bank_Index = Add / BANK_SIZE;351 Page_Index = (Add % BANK_SIZE) / PAGE_SIZE;352 Add_New = (Bank_Index<<6) | Page_Index;353

354 NAND512_CL_LOW;355 NAND512_AL_LOW;356 NAND512_W_HIGH;357 NAND512_R_HIGH;358 NAND512_CE_HIGH;359 NAND512_Delay_uS(10);360

361 NAND512_CE_LOW;362 NAND512_Delay_uS(5);363 NAND512_CL_HIGH;364 NAND512_W_LOW;365 NAND512_DB_Write(0x60);366 NAND512_Delay_uS(5);367 NAND512_W_HIGH;368 NAND512_Delay_uS(5);369 NAND512_CL_LOW;370 NAND512_Delay_uS(5);371 NAND512_AL_HIGH;372 NAND512_Delay_uS(5);373

374 //发送地址375 for(i=0;i<2;i++)376 {377 NAND512_W_LOW;378 NAND512_Delay_uS(5);379 NAND512_DB_Write(Add_New>>8*i);380 NAND512_Delay_uS(10);381 NAND512_W_HIGH;382 NAND512_Delay_uS(10);383 }384 NAND512_AL_LOW;385 NAND512_Delay_uS(5);386

387 NAND512_CL_HIGH;388 NAND512_Delay_uS(5);389 NAND512_W_LOW;390 NAND512_Delay_uS(5);391 NAND512_DB_Write(0xD0);392 NAND512_Delay_uS(5);393 NAND512_W_HIGH;394 NAND512_Delay_uS(5);395 NAND512_CL_LOW;396 NAND512_Delay_uS(5);397

398 while(NAND512_RB_STATUS == 0);399 NAND512_Delay_uS(5);400

401 Status = NAND512_Read_Status();402

403 if((Status & 0x01) == 0)404 return 1;405 else406 return 0; 407 }

H文件内容:

1 #ifndef NAND512W3A2C__H

2 #define NAND512W3A2C__H

3

4 #include "stm32f10x.h"

5

6 #define NAND512_CL_PORT GPIOD

7 #define NAND512_AL_PORT GPIOD

8 #define NAND512_W_PORT GPIOD

9 #define NAND512_R_PORT GPIOD

10 #define NAND512_CE_PORT GPIOD

11 #define NAND512_RB_PORT GPIOB

12 #define NAND512_WP_PORT /*GPIOD*/

13

14 #define NAND512_CL_PIN GPIO_Pin_6

15 #define NAND512_AL_PIN GPIO_Pin_5

16 #define NAND512_W_PIN GPIO_Pin_14

17 #define NAND512_R_PIN GPIO_Pin_15

18 #define NAND512_CE_PIN GPIO_Pin_7

19 #define NAND512_RB_PIN GPIO_Pin_5

20 #define NAND512_WP_PIN /*GPIO_Pin_5*/

21

22 #define NAND512_CL_CLK RCC_APB2Periph_GPIOD

23 #define NAND512_AL_CLK RCC_APB2Periph_GPIOD

24 #define NAND512_W_CLK RCC_APB2Periph_GPIOD

25 #define NAND512_R_CLK RCC_APB2Periph_GPIOD

26 #define NAND512_CE_CLK RCC_APB2Periph_GPIOD

27 #define NAND512_RB_CLK RCC_APB2Periph_GPIOB

28 #define NAND512_WP_CLK /*RCC_APB2Periph_GPIOD*/

29

30 #define NAND512_CE_LOW GPIO_ResetBits(NAND512_CE_PORT,NAND512_CE_PIN)

31 #define NAND512_CE_HIGH GPIO_SetBits(NAND512_CE_PORT,NAND512_CE_PIN)

32 #define NAND512_CL_LOW GPIO_ResetBits(NAND512_CL_PORT,NAND512_CL_PIN)

33 #define NAND512_CL_HIGH GPIO_SetBits(NAND512_CL_PORT,NAND512_CL_PIN)

34 #define NAND512_AL_LOW GPIO_ResetBits(NAND512_AL_PORT,NAND512_AL_PIN)

35 #define NAND512_AL_HIGH GPIO_SetBits(NAND512_AL_PORT,NAND512_AL_PIN)

36 #define NAND512_W_LOW GPIO_ResetBits(NAND512_W_PORT,NAND512_W_PIN)

37 #define NAND512_W_HIGH GPIO_SetBits(NAND512_W_PORT,NAND512_W_PIN)

38 #define NAND512_R_LOW GPIO_ResetBits(NAND512_R_PORT,NAND512_R_PIN)

39 #define NAND512_R_HIGH GPIO_SetBits(NAND512_R_PORT,NAND512_R_PIN)

40

41 #define NAND512_RB_STATUS GPIO_ReadInputDataBit(NAND512_RB_PORT,NAND512_RB_PIN)

42

43 #define NOP __nop()

44 #define BANK_SIZE 131072

45 #define PAGE_SIZE 2048

46

47 extern void NAND512_IO_Init(void);

48 extern char NAND512_Read_Status(void);

49 extern void NAND512_Read_ID(char* Buf);

50 extern void NAND512_Page_Read(char* Buf,int Len,int Add);

51 extern char NAND512_Page_Write(char* Buf,int Len,int Add);

52 extern char NAND512_Block_Erase(int Add);

53 #endif

发布评论

评论列表 (0)

  1. 暂无评论