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
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
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.
Hi Milorad,
there's no such clock (especially for the SMC controller).
I disable the pio mode, select peripheral A and disable the pull-ups. And now the NCS0 signal and NRD signal goes low if I tried to erase the nor flash.
// Specify Size and Address of Sectors 0x10000, 0x000000, // Sector Size 64kB (31 Sectors) 0x02000, 0x1F0000, // Sector Size 8kB (8 Sectors)
Could you tell me the way I get the start addr from the sector 8kb (0x1F0000)? In the datasheet there's a table about the start and end of each sector. The last 64k sector ends at 0xF7FFF and the first 8k sector starts at F80000.
How do I have to name the read function in the flash algorithm (FlashProg.c)? Because I have to write 0xFF (as command) to one addr.
At the moment I see that somethings happens on the pins (ncs0, nrd and nwe) but the veryfication failed. I think that I'm not able to read out anything from the flash.
Anyways seems that pins and clocks are not fully configured
Here's the clock-enable-function:
FUNC void Clock_Setup (void) { // Setup clock; XTAL = 18.432000 MHz, // PLLA = 96.109714 MHz, // Processor = 96.109714 MHz _WDWORD(PMC+ 0x20, 0x0000FF01); // CKGR_MOR: Enable main oscillator _sleep_(100); // Wait for stable Main Oscillator _WDWORD(PMC+ 0x28, 0x20483F0E); // CKGR_PLLAR: Configure PLL A _sleep_(100); // Wait for stable PLL A _WDWORD(PMC+ 0x30, 0x00000000); // PMC_MCKR: MDIV and PRES fields _sleep_(100); // Wait for Main Master Clock ready _WDWORD(PMC+ 0x30, 0x00000002); // PMC_MCKR: all fields _sleep_(100); // Wait for Main Master Clock ready }
Your SectorErase fuction will be called with addresses of each sector correctly, so you do not need to worry about sector address.
Why do you want to get sector address?
As this is NOR flash you do not need to specify any Read function because processor should be able to directly read from NOR flash and it uses directly reading to verify what has been written.
In other words you can not specify read function you could specify Verify function but in your case you do not need it as flash should be readable directly at its memory addresses.
You could try this by entering debug and looking at flash memory addresses where your flash is mapped if you do not see what you have written then everything still does not function as expected.
My guess is that you still do not write to flash correctly.
Best regards, Milorad
that's right. When I try to erase the whole flash memory then I get a signal on NCS0 and NRD; but when I try to download some code to the memory there's no activity on NWE or at the whole databus. Only at the address bus, NCS0 and NRD is an activity.
The programming algorithm for the flash is:
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 + 0x15) = 0x10; M16(adr) = *((unsigned short *) buf); if (Polling(adr) != 0) return (1); buf += 2; adr += 2; } return (0); }
Datasheet: Word-Program: Cycle 1: Addr=XX and Data 40/10 - I'm not sure what this means (40 / 10)? I tried to use 0x40 and 0x10 - but nothing has changed.
Cycle 2: Addr=Addr and Data is Din
I'm not sure, where there could be another error in my configuration.
can you answer following questions: - do you have flash connected in 16-bit bus? - do you have !WP pin connected High? - did you connect A1 processor line to A0 on flash? (flash expects half word address on A0..A19, and this means that A1 which is first half word address on processor has to be connected to A0 on flash chip, and all other lines are shifted by one, meaning:
proc A1 -> flash A0 proc A2 -> flash A1 ... proc A20 -> flash A19
If answers to previous questions are yes can you then try this for SectorErase:
int EraseSector (unsigned long adr) { // Start Erase Sector Command M16(adr) = 0x20; M16(adr) = 0xD0; return (Polling(adr)); }
- do you have flash connected in 16-bit bus?
_WDWORD(0xFFFFEC0C,0x00021003);
this is the mode register for the SMC controller (NCS0), where I selected 16bit databus mode, write operation controlled by NWE, read operation controlled by NRD, NWAIT disabled, TDF data float time = 2, standard read, page mode not enableda and TDF optimization disabled.
If answers to previous questions are yes can you then try this for
yes, the connections are correct (and as you described it in your last message).
It's still the same problem -> no activity on NWE and the databus (0x20 and 0xD0), when I try to erase the chip. There's only a activity at NCS0, the addressbus and NRD. All control signals (NWE, NCS0 and NRD), as well as all address lines are connected direct to the memory.
I have installed two bidirectional transceivers for the whole databus (between the controller and the flash memory). OE (transceiver) is always low active when the sdram (which is not connected at the moment) won't be active (-> so it's always low which is correct). And NRD is connected to control the T/R (transmit / receive) pin. If NRD is low then the information goes from the memory to the controller.
www.fairchildsemi.com/.../74LVTH245.pdf
That's my hardware wiring.
can you try in initialization:
_WDWORD(0xFFFFEC00,0x3F3F3F3F); _WDWORD(0xFFFFEC04,0x7F7F7F7F); _WDWORD(0xFFFFEC08,0x01FF01FF); _WDWORD(0xFFFFEC0C,0x000F1103);
Did you see anything on NWR or NRD?
When I try this configuration, then I see nothing on NRD, NCS0 and NWE... No signal at all.
That setting I gave you should have setup communication for longest times and should have worked.
Can you try another microcontroller (new chip)?
I would suggest that you contact Atmel support directly and ask them for help about how to configure SMC for NOR Flash.
thanks for your help. I will contact the support from atmel.
By the way, when I try to erase the flash, I see an activity at the SDCS pin (NCS1 chip select configurated for the sdram)? And I don't program the sdram in the init-file. The same occurs when I use another NCS-pin.
At the moment there's no sdram chip on the board.
I changed the controller and know I am able to see some activity on all relative pins (WE, NRD and so on).
The problem now is, that NRD, WE or CE pin goes only low at the beginning of each page; but within a page there's still no activity. From this it follows that'I have only at the addr - and data lines activity within each page. So a lot of the data, the controller sends to the flash, can't be stored in the flash because the CS and WE lines are both high.
Dataline: |||||||||||| (activity) CS: | | | NRD: | | |
what did Atmel support tell you? Did you get any help from them?
If you want to read/write from the chip, you must know the SPI protocol, that's it.
However, If you want to make it compatible with windows (linux, etc..) you must adhere to the FAT format which is very complex. You can either spend two years learning it, or you can use off the shelf chips that contain the fat stack.
Alfat is one of several companies that create a system where you communicate using DOS-like commands and UART to write the code and the chip handles the FAT.
While reuse of existing code is good, it is wrong to say that FAT is very complex. It is actually very, very simple, so we are not talking about any two years to learn, as long as support for long file names are ignored.
Without long file names, it is probably possible to implement FAT in two days.
On the other hand, almost no FAT implementation available have support for long file names. The code used by Linux may be the only free code in existence for long file names.
atmel send me a configuration example for the registers which should work - but their timing is very fast (maybe normal) and so there's no activity at the pins like WE. I'm only able to read out the product ID from the flash, when I use a extrem slow configuration (long timings) but, I'm not able to read out for example the CFI ID.
At the moment I'm in the dark.
The difference between the longest and shortest trace is only 40mm - (which is round about 0.25ns). It's very strange.