Working with the AT91SAM9260 controller from atmel, I get a lot of errors when I try to program the NOR flash AT49BV160 which is connected at NSC0.
The problem is, that I have no communication at NRD, NRW0 and NCS0, when I try to program the flash or turn on the power of this board (BMS pin is high during the reset).
During the programming via the jtag interface I get a lot of errors (validation failed). Erase and programming was successfull (said uvision).
Maybe someone of you working with this controller, could show me the right commands / settings (especially to configurate this flash).
thank you in advance - best regards
Stefan
Hi Stefan,
my guess is that you did not enable clocks for SMC (in PMC_PCER register). Anyways seems that pins and clocks are not fully configured.
here's my configuration from the FlashDev.c-file:
struct FlashDevice const FlashDevice = { FLASH_DRV_VERS, // Driver Version, do not modify! "AT49BV160 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 1000, // Erase Sector Timeout 1000 mSec // Specify Size and Address of Sectors 0x10000, 0x000000, // Sector Size 64kB (31 Sectors) 0x02000, 0x1F0000, // Sector Size 8kB (8 Sectors) SECTOR_END };
The flash memory is 2MB,. 1024 page size and the sector size is 64kB and 8kB....
best regards Stefan
thanks for your answer. At the moment, when I press the erase-button (under Flash->Erase) -> nothing happens on the pins NCS0, NWE0.
I deleted the EraseChip-Function. The sector-erase-chip function is:
int EraseSector (unsigned long adr) { // Start Erase Sector Command M16(base_adr + 0x0AAA) = 0x20; M16(adr) = 0xD0; return (Polling(adr)); // Wait until Erase completed }
Sector Erase/Confirm: 2 cycles Addr: XX (any addr) 20 (data) and the second cycle is SA(sector addr) and D0 (data).
The polling-function: q3 is the VPP status and q7 determine if sector erase or Word Program is complete.
int Polling (unsigned long adr) { unsigned int q7; //1: ready 0: busy fsr.v = M16(adr); q7 = fsr.b.q7; do { fsr.v = M16(adr); if (fsr.b.q7 == 1) return (0); // Done q7 = fsr.b.q7; if (fsr.b.q3 == 1) break; // VPP not high enough } while (fsr.b.q7 == 0); // Check for Timeout fsr.v = M16(adr); q7 = fsr.b.q7; fsr.v = M16(adr); if (fsr.b.q7 == 1) return (0); // Done //M16(adr) = 0xF0; // Reset Device return (1); // Failed }
Under options-for-target->utlities I have a short init-file, where I start the clocks and program the three SMC controller registers. The clock function is directly from keil (and works).
//Control Register: 16bit databus, NRD, NWE controlled _WDWORD(0xFFFFEC0C,0x00021003); //Cycle Register: NWE_Cycle - NRD_Cycle _WDWORD(0xFFFFEC08, 0x00070007); //Setup Register: NWE_Setup - NCS_WR_Setup - NRD_Setup - NCS_RD_Setup _WDWORD(0xFFFFEC00, 0x00000001); //Pulse Register: NWE_Pulse - NCS_WR_Pulse - NRD_Pulse - NCS_RD_Pulse _WDWORD(0xFFFFEC04, 0x07070703);
I hope you could tell me what I'm doing wrong so that I have no signal output (on NCS0, NWE...) when I press the erase-button.
If you do not have EraseChip function implemented in your flash algorithm (delete EraseChip function, do not leave it empty), ULINK driver will automatically call EraseSector command for each sector of the flash.
Important things to define are in FlashDev.c and they are "Device Size in Bytes" and "Size and Address of Sectors". According to these 2 parameters ULINK driver knows how many times it has to call SectorErase command and with what address increments.
thanks for your answer. I tried to program a new algorithm for the flash memory.
The memory flash doesn't provide an "chip erase" command (only a sector erase command) - could you tell me how is it possible to use the "erase-button" (Flash>Erase) in the uvision IDE to erase the whole memory flash? I think that this function will be called if I / you press the erase-button.
int EraseChip (void) { // Start Chip Erase Command //return (Polling(base_adr)); // Wait until Erase completed return 0; }
There's the datashheet of this memory flash: The command table is on page 15. www.atmel.com/.../doc3591.pdf
Hello Stefan,
It is logical that you get some action on pins when you try programming.
I'm not really sure what is the problem now?
Anyways it is strange to me that you are mentioning memcpy for copying code to NOR flash, NOR flash is programmed by entering instructions first and then entering data. For example for programming: M16(base_adr + 0x0AAA) = 0xAA; M16(base_adr + 0x1554) = 0x55; M16(base_adr + 0x0AAA) = 0xA0; M16(adr) = *((unsigned short *) buf);
so you have to enter commands before every 16-bit value you write to NOR flas.
So I don't see how you planed to do that with memcpy?
Please, ask more (detailed) clear questions if you still have problems.
thank you for your answer.
I'm using the algorithm AT49xV16A (from keil) which is similar to the AT49BV160TD.
Also what you have to (and this is why you do not see anything happening on NRD, NWR0 and NCS0 pins) is enable hardware to work with NOR Flash.
You're right, I'm programming the three SMC controller registers for the NCS0 and now I'm able to see something happining on NRD NWE and NCS0 (but only when I try to programm the flash).
Do you know if there's anything else to enable to use the NOR flash? Because, when I run a short application in the internal RAM and I use the memcpy-instruction to copy some code into the NOR flash - nothing happens on NWE or NCS0. I also programm the three SMC controller registers (in the startup-file).
It seems that you have a custom board with NOR flash and you are trying to program it with our flash algorithm which was made for Atmel AT91SAM9260 board which has Serial (SPI driven) DataFlash chip and not NOR Flash.
So what you have to do is write your own Flash Algorithm for your NOR Flash chip you can use similar algorithm for example AT49xV32x from \Keil\ARM\Flash folder.
Our agorithm that is default for AT91SAM9260 is for Serial DataFlash which is on Atmel board.
View all questions in Keil forum