AT45DB021 flash and the likes

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hhm... I got the impression that you can do byte by byte write...but it seems you have to read the page (256bytes) to buffer and then modify the buffer at the location you please and then write the whole buffer back to the page. A bit cumbersome...

Also I am a bit confused at the datasheet...why does sector 0 devided into 0a and 0b? and it has 8 pages and the sector 1 has 120 pages...and the rest of the sectors have 128pages?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

also I the OTP programming to enable 256 page size instead of the default 264...can I leave the OTP programming steps in my code? so that everytime micro starts up the flash will get OTP programmed to 256...its kind of useless but otherwise I would have to comment out the section and recompile and program my atmega chip to run through that init function section.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

A bit cumbersome...

These chips are wonderful compared to most Nand in that the page size is only 256 (512 in the larger) and you have the two RAM buffers internally. Most Nand have 16K/32K/64K pages and no buffering so with those to change 1 byte (with 0->1 transitions) you read a full 16/32/64K out, erase the page, edit the byte and write back. So count yourself lucky!

As for the 0a/0b this is quite usual for Nand devices to have "boot" sectors that are larger/smaller than the rest of the device. In this day and age many ARMs and such can boot from SPI-Nand and the boot code would be located in either sector 0a (if it fits) or sectors 0a and 0b. Now take a look at chapter 10 in the data "sector lockdown" where those early sectors can be locked so they can never be changed (so you have to get your bootloader right!)

As to the question of keep setting 256 page size. Look at the 0xD7 read status command (section 11.4). Bit 0 says whether it is 256 or 264. So wrap your changing code in a test to first see if it's already been done.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for that clawson :)
you guys are avr legends! But does it really matter if the OTP was already programed? I mean if everytime micro reboots and the code for OTP is there active everytime, the at45db flash might just not care about it as its a OTP register...yes?

So I should probably select sector 1 onwards to write my firmware in the flash. I have finally managed to set up ftp on my self written socket/tcp/ip driver :) and last night was able to get ftp put and get working successfull! so I am now thinking of ftping my firmware into the flash and then also somehow send the MD5 via ftp so that micro can check the firmware and if valid does a self reboot and boots from the boodloader and the bootloader grabs the hext from at45dbx flash and reprograms the program flash on UC3A chip. What do you think?

I suppose ftp doesnt have any MD5 transmit facility? I might have to send it as a smaller file.

Also if I was to do a web page layout on my micro webserver and then there was a button called submit and a field where you could browes and input the firmware file and clicked submit, would that be sent as ftp within http? how does that work? how does http send file? This is same as how you do firmware upgrade for your router I guess... hhm... this is tooo addictive! I need so more more time to work on these stuff than my spare time :(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have just recently wrote some routines for an AT25 dataflash chip... Smaller version of similar chip, only coded the commands I'll actually use... There are byte write commands, but quite honestly they are much more cumbersome than manipulating a single 256 bytes buffer... In BASCOM of course:

Dim At25_address_local As Dword                                  ' Local AT25 address register, 32-bits.
Dim At25_address_low As Byte At At25_address_local Overlay       ' Pointer to the low byte.
Dim At25_address_mid As Byte At At25_address_local + 1 Overlay   ' Pointer to the middle byte.
Dim At25_address_high As Byte At At25_address_local + 2 Overlay  ' Pointer to the high byte.

Dim At25_sreg As Byte                                            ' AT25 Dataflash Status Register
    At25_busy Alias At25_sreg.0                                  ' AT25 Busy Flag
    At25_wel Alias At25_sreg.1                                   ' AT25 Write Enable Latch Status Flag
    At25_error Alias At25_sreg.5                                 ' AT25 Erase/Program Error Flag

Dim Buffer_in(256) As Byte                                       ' Input buffer
Dim Buffer_page(256) As Byte                                     ' Page buffer
Dim Buffer_command(4) As Byte                                    ' Command buffer

' AT25 Dataflash
' #########################################

Sub At25_read_page(address As Dword)                             ' Read 256 bytes from the AT25 at Address into Buffer_page().
   Buffer_command(1) = &H03                                      ' NOTE: Address must be divisible by 256.
                                                            ' ----------------------------------------------------------
   ' Copy the address into our local variable and stick the 3 lower bytes into the command buffer.
   At25_address_local = Address
   Buffer_command(2) = At25_address_high
   Buffer_command(3) = At25_address_mid
   Buffer_command(4) = At25_address_low

   ' Start the SPI transaction, send the opcode and 3 address bytes, read 256 bytes in the page buffer, then end the SPI transaction.
   Reset Spi_ss
   Spiout Buffer_command(1) , 4
   ' We need to split the reply in two reads because of a buffer limitation in BASCOM.
   Spiin Buffer_page(1) , 255
   Spiin Buffer_page(256) , 1
   Set Spi_ss

End Sub


Sub At25_write_page(address As Dword)                            ' Write 256 bytes to the AT25 from Buffer_page() at Address.
   Buffer_command(1) = &H02                                      ' NOTE: Address must be divisible by 256.
                                                            ' ----------------------------------------------------------
   ' Copy the address into our local variable and stick the 3 lower bytes into the command buffer.
   At25_address_local = Address
   Buffer_command(2) = At25_address_high
   Buffer_command(3) = At25_address_mid
   Buffer_command(4) = At25_address_low

   ' Enable writing to the AT25
   Call At25_write_enable

   ' Start the SPI transaction, send the opcode and 3 address bytes, and the page of data to write, then end the SPI transaction.
   Reset Spi_ss
   Spiout Buffer_command(1) , 4
   ' We need to split the transaction in two writes because of a buffer limitation in BASCOM.
   Spiout Buffer_page(1) , 255
   Spiout Buffer_page(256) , 1
   Set Spi_ss

   ' Wait until the AT25 is done writing the data.
   Call At25_busywait

   ' Check is there was an error, and report it.
   If At25_error = 1 Then
      Call At25_reporterror
   End If
End Sub


Sub At25_busywait()                                              ' Wait until the AT25 comes out of busy state
   Do                                                            ' -------------------------------------------
      ' Read the AT25 status register every 100ms until it is no longer busy.
      Call At25_readstatus
      If At25_busy = 0 Then Exit Do
      Waitms 100
   Loop
End Sub


Sub At25_fullerase()                                             ' Perform a full chip erase on the AT25
   Buffer_command(1) = &H60                                      ' -------------------------------------

   ' Enable writing to the AT25
   Call At25_write_enable

   ' Start the SPI transaction, send the Erase Chip opcode, then end the SPI transaction.
   Reset Spi_ss
   Spiout Buffer_command(1) , 1
   Set Spi_ss

   ' Wait until the AT25 is done erasing itself.
   Call At25_busywait

   ' Check is there was an error, and report it.
   If At25_error = 1 Then
      Call At25_reporterror
   End If
End Sub


Sub At25_readstatus()                                            ' Read the AT25 Dataflash Status Register
   Buffer_command(1) = &H05                                      ' ---------------------------------------

   ' Start the SPI transaction, send the Read Status Register opcode, read back the register, then end the SPI transaction.
   Reset Spi_ss
   Spiout Buffer_command(1) , 1
   Spiin At25_sreg , 1
   Set Spi_ss
End Sub


Sub At25_write_enable()                                          ' Enable writing to the AT25
   Buffer_command(1) = &H06                                      ' --------------------------

   ' Start the SPI transaction, send the Write Enable opcode, then end the SPI transaction.
   Reset Spi_ss
   Spiout Buffer_command(1) , 1
   Set Spi_ss

   ' Check if the Write Enable Latch is set, if not report an error.
   If At25_wel = 0 Then
      Call At25_reporterror
   End If
End Sub