Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed EEPROM USBDevice
Revision 4:2e8b78a74493, committed 2021-09-15
- Comitter:
- muraguchi
- Date:
- Wed Sep 15 16:32:12 2021 +0000
- Parent:
- 3:28ceea26c918
- Commit message:
- AirioBase + 2 chip PicoSSD board.
Changed in this revision
diff -r 28ceea26c918 -r 2e8b78a74493 RawNAND.cpp
--- a/RawNAND.cpp Wed Feb 10 03:45:12 2021 +0000
+++ b/RawNAND.cpp Wed Sep 15 16:32:12 2021 +0000
@@ -2,7 +2,7 @@
// TODO: Replace wait_us(int) to wait_ns
-RawNAND::RawNAND(PinName ceb, PinName cle,
+RawNAND::RawNAND(PinName ceb0,PinName ceb1, PinName cle,
PinName ale, PinName web,
PinName reb, PinName wpb,
PinName rbb,
@@ -10,22 +10,26 @@
PinName io3, PinName io4,
PinName io5, PinName io6,
PinName io7, PinName io8)
- : _ceb(ceb,1),_cle(cle,1),
+ : _ceb0(ceb0,1),_ceb1(ceb1,1),_cle(cle,1),
_ale(ale,1),_web(web,1),
_reb(reb,1),_wpb(wpb,1),
- _rbb(rbb,PullNone),
+ _rbb(rbb,PullUp),
_io(io1,io2,io3,io4,io5,io6,io7,io8) {
_io.mode(PullNone);
_io.input();
}
-void RawNAND::reset() {
+void RawNAND::reset(uint8_t cs) {
// wait ready
while(_rbb==0){
__NOP();
}
// RESET COMMAND (0xff)
- _ceb = 0;
+ if(cs==0) {
+ _ceb0 = 0;
+ } else if (cs==1) {
+ _ceb1 = 1;
+ }
_cle = 1;
_ale = 0;
_web = 0;
@@ -40,11 +44,19 @@
while (_rbb==0){
__NOP();
}
- _ceb = 1;
+ if(cs==0) {
+ _ceb0 = 1;
+ } else if (cs==1) {
+ _ceb1 = 1;
+ }
}
-void RawNAND::idRead(uint8_t * readData) {
+void RawNAND::idRead(uint8_t cs, uint8_t * readData) {
// ID READ COMMAND (0x90)
- _ceb = 0;
+ if(cs==0) {
+ _ceb0 = 0;
+ } else if (cs==1) {
+ _ceb1 = 0;
+ }
_cle = 1;
_ale = 0;
_web = 0;
@@ -84,10 +96,14 @@
wait_us(tREH_US);
}
// wait io hiz
- _ceb = 1;
+ if(cs==0) {
+ _ceb0 = 1;
+ } else if (cs==1) {
+ _ceb1 = 1;
+ }
wait_us(tCHZ_US);
}
-uint8_t RawNAND::statusRead() {
+uint8_t RawNAND::statusRead(uint8_t cs) {
uint8_t status;
// wait ready
while(_rbb==0){
@@ -95,7 +111,11 @@
}
// STATUS READ COMMAND (0x70)
- _ceb = 0;
+ if(cs==0) {
+ _ceb0 = 0;
+ } else if (cs==1) {
+ _ceb1 = 0;
+ }
_cle = 1;
_ale = 0;
_web = 0;
@@ -117,7 +137,11 @@
_reb = 1;
// wait tREH
wait_us(tREH_US);
- _ceb = 1;
+ if(cs==0) {
+ _ceb0 = 1;
+ } else if (cs==1) {
+ _ceb1 = 1;
+ }
wait_us(tCHZ_US);
// wait io hiz
return status;
@@ -129,14 +153,18 @@
wait_us(tWW_US);
}
-void RawNAND::pageRead(uint8_t * readData,uint16_t blockAddress,uint8_t pageAddress,uint16_t columnAddress,uint16_t beats){
+void RawNAND::pageRead(uint8_t cs, uint8_t * readData,uint16_t blockAddress,uint8_t pageAddress,uint16_t columnAddress,uint16_t beats){
// wait ready
while(_rbb==0){
__NOP();
}
// 1ST READ COMMAND (0x00)
- _ceb = 0;
+ if(cs==0) {
+ _ceb0 = 0;
+ } else if (cs==1) {
+ _ceb1 = 0;
+ }
_cle = 1;
_ale = 0;
_web = 0;
@@ -225,21 +253,29 @@
wait_us(tREH_US);
}
- _ceb = 1;
+ if(cs==0) {
+ _ceb0 = 1;
+ } else if (cs==1) {
+ _ceb1 = 1;
+ }
// wait io hiz
wait_us(tCHZ_US);
}
-uint8_t RawNAND::erase(uint16_t blockAddress){
+uint8_t RawNAND::erase(uint8_t cs, uint16_t blockAddress){
// wait ready
while(_rbb==0){
__NOP();
}
// 1ST ERASE COMMAND (0x60)
- _ceb = 0;
+ if(cs==0) {
+ _ceb0 = 0;
+ } else if (cs==1) {
+ _ceb1 = 0;
+ }
_cle = 1;
_ale = 0;
_web = 0;
@@ -295,17 +331,21 @@
__NOP();
}
- return statusRead();
+ return statusRead(cs);
}
-uint8_t RawNAND::pageProgram(const uint8_t * writeData,uint16_t blockAddress,uint8_t pageAddress,uint16_t columnAddress,uint16_t beats){
+uint8_t RawNAND::pageProgram(uint8_t cs, const uint8_t * writeData,uint16_t blockAddress,uint8_t pageAddress,uint16_t columnAddress,uint16_t beats){
// wait ready
while(_rbb==0){
__NOP();
}
// 1ST PROGRAM COMMAND (0x80)
- _ceb = 0;
+ if(cs==0) {
+ _ceb0 = 0;
+ } else if (cs==1) {
+ _ceb1 = 0;
+ }
_cle = 1;
_ale = 0;
_web = 0;
@@ -395,5 +435,5 @@
__NOP();
}
- return statusRead();
+ return statusRead(cs);
}
\ No newline at end of file
diff -r 28ceea26c918 -r 2e8b78a74493 RawNAND.h
--- a/RawNAND.h Wed Feb 10 03:45:12 2021 +0000
+++ b/RawNAND.h Wed Sep 15 16:32:12 2021 +0000
@@ -140,27 +140,28 @@
class RawNAND
{
public:
- RawNAND(PinName ceb, PinName cle,
- PinName ale, PinName web,
- PinName reb, PinName wpb,
- PinName rbb,
- PinName io1, PinName io2,
- PinName io3, PinName io4,
- PinName io5, PinName io6,
- PinName io7, PinName io8);
- void reset();
- void idRead(uint8_t * readData);
- uint8_t statusRead();
+ RawNAND(PinName ceb0, PinName ceb1,
+ PinName cle , PinName ale ,
+ PinName web , PinName reb ,
+ PinName wpb , PinName rbb ,
+ PinName io1 , PinName io2 ,
+ PinName io3 , PinName io4 ,
+ PinName io5 , PinName io6 ,
+ PinName io7 , PinName io8 );
+ void reset(uint8_t cs);
+ void idRead(uint8_t cs, uint8_t * readData);
+ uint8_t statusRead(uint8_t cs);
void setWriteProtect(uint8_t writeProtect);
- void pageRead(uint8_t * readData,uint16_t blockAddress,uint8_t pageAddress,uint16_t columnAddress,uint16_t beats);
+ void pageRead(uint8_t cs, uint8_t * readData,uint16_t blockAddress,uint8_t pageAddress,uint16_t columnAddress,uint16_t beats);
// return status
- uint8_t pageProgram(const uint8_t * writeData,uint16_t blockAddress,uint8_t pageAddress,uint16_t columnAddress,uint16_t beats);
+ uint8_t pageProgram(uint8_t cs, const uint8_t * writeData,uint16_t blockAddress,uint8_t pageAddress,uint16_t columnAddress,uint16_t beats);
// return status
- uint8_t erase(uint16_t blockAddress);
+ uint8_t erase(uint8_t cs, uint16_t blockAddress);
private:
- DigitalOut _ceb;
+ DigitalOut _ceb0;
+ DigitalOut _ceb1;
DigitalOut _cle;
DigitalOut _ale;
DigitalOut _web;
diff -r 28ceea26c918 -r 2e8b78a74493 USBDevice.lib --- a/USBDevice.lib Wed Feb 10 03:45:12 2021 +0000 +++ b/USBDevice.lib Wed Sep 15 16:32:12 2021 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/muraguchi/code/USBDevice/#c80da04112fd +https://os.mbed.com/users/muraguchi/code/USBDevice/#72808bd55ce2
diff -r 28ceea26c918 -r 2e8b78a74493 USBMSD_STEP1.cpp
--- a/USBMSD_STEP1.cpp Wed Feb 10 03:45:12 2021 +0000
+++ b/USBMSD_STEP1.cpp Wed Sep 15 16:32:12 2021 +0000
@@ -1,7 +1,7 @@
#include "USBMSD_STEP1.h"
#include "RawNAND.h"
-USBMSD_STEP1::USBMSD_STEP1(PinName ceb, PinName cle,
+USBMSD_STEP1::USBMSD_STEP1(PinName ceb0,PinName ceb1, PinName cle,
PinName ale, PinName web,
PinName reb, PinName wpb,
PinName rbb,
@@ -11,8 +11,8 @@
PinName io7, PinName io8,
PinName ledRd,PinName ledWr,PinName swInit)
{
- m_rawNand = new RawNAND(ceb,cle,ale,web,reb,wpb,rbb,io1,io2,io3,io4,io5,io6,io7,io8);
- m_bbt = new bbt_eeprom(1004);
+ m_rawNand = new RawNAND(ceb0,ceb1,cle,ale,web,reb,wpb,rbb,io1,io2,io3,io4,io5,io6,io7,io8);
+ m_bbt = new bbt_eeprom(2048-40);
m_ledRead = new DigitalOut(ledRd,1);
@@ -27,8 +27,8 @@
*m_ledWrite=0;
// search bad blocks in replace area. block 1004-1023
- for (int r=0;r<20;r++) {
- m_rawNand->pageRead(&pagebuff,(r+1004),63,2175,1);
+ for (int r=0;r<40;r++) {
+ m_rawNand->pageRead(get_cs_from_block(2048-40+r),&pagebuff,get_chip_block_from_block(2048-40+r),63,2175,1);
if( pagebuff!=0xff) {
m_bbt->setSlot_EEP(r,1,0,0);
}
@@ -39,8 +39,8 @@
}
// search bad blocks
- for (int b=0;b<1024-20;b++) {
- m_rawNand->pageRead(&pagebuff,b,63,2175,1);
+ for (int b=0;b<2048-40;b++) {
+ m_rawNand->pageRead(get_cs_from_block(b),&pagebuff,get_chip_block_from_block(b),63,2175,1);
if (pagebuff!=0xff){
m_bbt->setSlot_EEP(m_bbt->getFreeSlot_EEP(), 0, 1,b);
}
@@ -56,11 +56,31 @@
}
+uint8_t USBMSD_STEP1::get_cs_from_block(uint16_t block)
+{
+ if (block<1024) {
+ return 0;
+ } else {
+ return 1;
+ }
+}
+
+uint16_t USBMSD_STEP1::get_chip_block_from_block(uint16_t block)
+{
+ if (block<1024) {
+ return block;
+ } else {
+ return block-1024;
+ }
+}
+
+
int USBMSD_STEP1::disk_read(uint8_t* data, uint64_t block, uint8_t count)
{
*m_ledRead = 0;
- m_rawNand->pageRead(data,m_bbt->getTranslatedBlockAddress(block>>1),62+(block&0x1),0,512);
+ m_rawNand->pageRead(get_cs_from_block(m_bbt->getTranslatedBlockAddress(block>>1)),data,
+ get_chip_block_from_block(m_bbt->getTranslatedBlockAddress(block>>1)),62+(block&0x1),0,512);
//m_rawNand->pageRead(data,m_bbt->getTranslatedBlockAddress(block),63,0,512);
*m_ledRead = 1;
return 0;
@@ -71,15 +91,16 @@
// copy data
for (uint16_t c=0;c<2;c++){
if ( (block&0x1) == c) continue;
- m_rawNand->pageRead(m_buffer,m_bbt->getTranslatedBlockAddress(block>>1),62+c,0,512);
+ m_rawNand->pageRead(get_cs_from_block(m_bbt->getTranslatedBlockAddress(block>>1)),m_buffer,
+ get_chip_block_from_block(m_bbt->getTranslatedBlockAddress(block>>1)),62+c,0,512);
}
// write data
- m_rawNand->erase(m_bbt->getTranslatedBlockAddress(block>>1));
+ m_rawNand->erase(get_cs_from_block(m_bbt->getTranslatedBlockAddress(block>>1)),get_chip_block_from_block(m_bbt->getTranslatedBlockAddress(block>>1)));
for (uint16_t c=0;c<2;c++){
if ( (block&0x1) == c) {
- m_rawNand->pageProgram(data,m_bbt->getTranslatedBlockAddress(block>>1),62+c,0,512);
+ m_rawNand->pageProgram(get_cs_from_block(m_bbt->getTranslatedBlockAddress(block>>1)),data,get_chip_block_from_block(m_bbt->getTranslatedBlockAddress(block>>1)),62+c,0,512);
} else {
- m_rawNand->pageProgram(m_buffer,m_bbt->getTranslatedBlockAddress(block>>1),62+c,0,512);
+ m_rawNand->pageProgram(get_cs_from_block(m_bbt->getTranslatedBlockAddress(block>>1)),m_buffer,get_chip_block_from_block(m_bbt->getTranslatedBlockAddress(block>>1)),62+c,0,512);
}
}
diff -r 28ceea26c918 -r 2e8b78a74493 USBMSD_STEP1.h
--- a/USBMSD_STEP1.h Wed Feb 10 03:45:12 2021 +0000
+++ b/USBMSD_STEP1.h Wed Sep 15 16:32:12 2021 +0000
@@ -3,7 +3,7 @@
#include "mbed.h"
-#define USBMSD_STEP1_SECTORS 1004*2
+#define USBMSD_STEP1_SECTORS 4016
#define USBMSD_STEP1_SECTOR_SIZE 512
#define USBMSD_STEP1_DISK_SIZE USBMSD_STEP1_SECTOR_SIZE*USBMSD_STEP1_SECTORS
#include <stdlib.h>
@@ -13,7 +13,7 @@
class USBMSD_STEP1: public USBMSD
{ public:
- USBMSD_STEP1(PinName ceb, PinName cle,
+ USBMSD_STEP1(PinName ceb0, PinName ceb1, PinName cle,
PinName ale, PinName web,
PinName reb, PinName wpb,
PinName rbb,
@@ -30,11 +30,17 @@
virtual uint64_t disk_size();
virtual int disk_status();
+
+ uint8_t get_cs_from_block(uint16_t block);
+ uint16_t get_chip_block_from_block(uint16_t block);
+
+
DigitalOut * m_ledRead;
DigitalOut * m_ledWrite;
DigitalIn * m_swInit;
// DigitalIn * m_isp;
+
private:
RawNAND * m_rawNand;
bbt_eeprom * m_bbt;
diff -r 28ceea26c918 -r 2e8b78a74493 bbt_eeprom.cpp
--- a/bbt_eeprom.cpp Wed Feb 10 03:45:12 2021 +0000
+++ b/bbt_eeprom.cpp Wed Sep 15 16:32:12 2021 +0000
@@ -1,6 +1,6 @@
#include "bbt_eeprom.h"
-bbt_eeprom::bbt_eeprom(uint16_t offsetReservedBlockAddress=1004){
+bbt_eeprom::bbt_eeprom(uint16_t offsetReservedBlockAddress=2048-40){
m_offsetReservedBlockAddress = offsetReservedBlockAddress;
m_translateTableMaxIndex=0;
m_tempSlot=0;
diff -r 28ceea26c918 -r 2e8b78a74493 bbt_eeprom.h --- a/bbt_eeprom.h Wed Feb 10 03:45:12 2021 +0000 +++ b/bbt_eeprom.h Wed Sep 15 16:32:12 2021 +0000 @@ -4,7 +4,7 @@ #ifndef BBT_EEPROM_H #define BBT_EEPROM_H -#define BBT_EEPROM_SLOT_LENGTH 20 +#define BBT_EEPROM_SLOT_LENGTH 40 #define BBT_EEPROM_SLOT_SIZE 2 #define BBT_EEPROM_STATUS_ADDR 0 #define BBT_EEPROM_TEMPSLOT_ADDR 1
diff -r 28ceea26c918 -r 2e8b78a74493 main.cpp
--- a/main.cpp Wed Feb 10 03:45:12 2021 +0000
+++ b/main.cpp Wed Sep 15 16:32:12 2021 +0000
@@ -2,21 +2,23 @@
#include "USBMSD_STEP1.h"
-#define ND_CEB P0_9
-#define ND_CLE P0_8
-#define ND_ALE P1_29
-#define ND_WEB P0_12
-#define ND_REB P1_21
-#define ND_WPB P0_11
-#define ND_RBB P1_31
-#define ND_IO1 P0_18
-#define ND_IO2 P0_19
-#define ND_IO3 P1_25
-#define ND_IO4 P0_20
-#define ND_IO5 P0_2
-#define ND_IO6 P1_26
-#define ND_IO7 P1_27
-#define ND_IO8 P1_23
+// PicoSSD pin assignment
+#define ND_CEB0 P0_13
+#define ND_CEB1 P0_14
+#define ND_CLE P0_8
+#define ND_ALE P1_29
+#define ND_WEB P0_12
+#define ND_REB P0_9
+#define ND_WPB P0_11
+#define ND_RBB P1_21
+#define ND_IO1 P1_25
+#define ND_IO2 P0_20
+#define ND_IO3 P0_2
+#define ND_IO4 P1_26
+#define ND_IO5 P1_27
+#define ND_IO6 P1_23
+#define ND_IO7 P1_28
+#define ND_IO8 P1_31
#define LED_RD P0_7
#define LED_WR P1_13
@@ -26,7 +28,7 @@
int main() {
USBMSD_STEP1 *myusb;
- myusb = new USBMSD_STEP1(ND_CEB,ND_CLE,ND_ALE,ND_WEB,ND_REB,ND_WPB,ND_RBB,
+ myusb = new USBMSD_STEP1(ND_CEB0,ND_CEB1,ND_CLE,ND_ALE,ND_WEB,ND_REB,ND_WPB,ND_RBB,
ND_IO1,ND_IO2,ND_IO3,ND_IO4,ND_IO5,ND_IO6,ND_IO7,ND_IO8,
LED_RD,LED_WR,SW_INIT);
myusb->connect();