| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lpc_norflash_sst39vf320.c
Go to the documentation of this file.
1 /*
2 * @brief SST39VF320 NOR FLASH driver
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
29 * this code.
30 */
31
32 #include "board.h"
33 #include "lpc_norflash.h"
34
41 /*****************************************************************************
42 * Private types/enumerations/variables
43 ****************************************************************************/
44 /* Total size */
45 #define FLASH_SIZE (4 << 20) /* 2Mx16 */
46 /* Sector size */
47 #define SECTOR_SIZE (4 << 10) /* 2K words */
48 /* Block size */
49 #define BLOCK_SIZE (64 << 10) /* 32K words */
50 /* Toggle bit */
51 #define TOGGLE_BIT (1 << 6) /* DQ6 */
52
53 /*****************************************************************************
54 * Public types/enumerations/variables
55 ****************************************************************************/
56
57 /*****************************************************************************
58 * Private functions
59 ****************************************************************************/
60
61 /*****************************************************************************
62 * Public functions
63 ****************************************************************************/
64 /* Init nor flash */
65 void lpc_norflash_init(void)
66 {}
67
68 /* Get the flash size */
69 void lpc_norflash_get_size(UNS_32 *size, UNS_32 *sector_count)
70 {
71 *size = FLASH_SIZE;
72 *sector_count = FLASH_SIZE / SECTOR_SIZE; /* Uniform 2 KWord sectors*/
73 }
74
75 /* Get offset of a sector in flash */
76 UNS_32 lpc_norflash_get_sector_offset(UNS_32 sector)
77 {
78 return SECTOR_SIZE * sector;
79 }
80
81 void lpc_norflash_get_id(UNS_16 *manu_id, UNS_16 *device_id)
82 {
83 volatile uint32_t i;
84
85 /* Enter Product Identification Mode */
86 Board_NorFlash_WriteCmd(0x5555, 0xAAAA);
87 Board_NorFlash_WriteCmd(0x2AAA, 0x5555);
88 Board_NorFlash_WriteCmd(0x5555, 0x9090);
89
90 /* Wait tIDA (~150ns) */
91 // FIXME - this needs to be done with a more accurate delay
92 for (i = 0; i < 10; i++) {}
93
94 /* Read Manufacturer ID. It should be 0xBF */
95 *manu_id = Board_NorFlash_ReadCmdData(0x0000);
96 /* Read Device ID. It should be 0x235B for SST39VF3201 and 0x235A for SST39VF3202*/
97 *device_id = Board_NorFlash_ReadCmdData(0x0001);
98
99 /* Exit Product Identification Mode */
100 Board_NorFlash_WriteCmd(0x5555, 0xAAAA);
101 Board_NorFlash_WriteCmd(0x2AAA, 0x5555);
102 Board_NorFlash_WriteCmd(0x5555, 0xF0F0);
103
104 /* Wait tIDA (~150ns) */
105 // FIXME - this needs to be done with a more accurate delay
106 for (i = 0; i < 10; i++) {}
107 }
108
109 /* Toggle Bit check */
110 bool lpc_norflash_toggle_bit_check(UNS_32 addr)
111 {
112 UNS_16 tmp1 = lpc_norflash_read_word(addr);
113 UNS_16 tmp2 = lpc_norflash_read_word(addr);
114
115 if ((tmp1 & TOGGLE_BIT) == (tmp2 & TOGGLE_BIT)) {
116 return true;
117 }
118 return false;
119 }
120
121 /* Erase sector */
122 void lpc_norflash_erase_sector(UNS_32 sec_addr)
123 {
124 Board_NorFlash_WriteCmd(0x5555, 0xAAAA);
125 Board_NorFlash_WriteCmd(0x2AAA, 0x5555);
126 Board_NorFlash_WriteCmd(0x5555, 0x8080);
127 Board_NorFlash_WriteCmd(0x5555, 0xAAAA);
128 Board_NorFlash_WriteCmd(0x2AAA, 0x5555);
129 Board_NorFlash_WriteWord(sec_addr, 0x3030);
130 }
131
132 /* Write data to flash */
133 void lpc_norflash_write_word(UNS_32 addr, UNS_16 data)
134 {
135 Board_NorFlash_WriteCmd(0x5555, 0xAAAA);
136 Board_NorFlash_WriteCmd(0x2AAA, 0x5555);
137 Board_NorFlash_WriteCmd(0x5555, 0xA0A0);
138 Board_NorFlash_WriteWord(addr, data);
139 }
140
141 /* Write buffer to flash */
142 UNS_32 lpc_norflash_write_buffer(UNS_32 addr, UNS_16 *data, UNS_32 size)
143 {
144 UNS_32 i = 0;
145 for (i = 0; i < size; i += 2) {
146 lpc_norflash_write_word(addr + i, *data);
147 while (!lpc_norflash_toggle_bit_check(addr + i)) {}
148 data++;
149 }
150 return i;
151 }
152
153 /* Read 16-bit data from flash */
154 UNS_16 lpc_norflash_read_word(UNS_32 addr)
155 {
156 return Board_NorFlash_ReadWord(addr);
157 }
158