Skip to content

Commit 25f9348

Browse files
committed
Use NAND parameters in chip DB instead of STM
1 parent d646afe commit 25f9348

File tree

6 files changed

+121
-17
lines changed

6 files changed

+121
-17
lines changed

qt/chip_db.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
static ChipInfo chipDB[] =
1010
{
11-
{ CHIP_ID_NONE, "No Chip", 0, 0, 0, 0, 0, 0, 0, 0, 0 },
12-
{ CHIP_ID_K9F2G08U0C, "K9F2G08U0C", 0x800, 0x20000, 0x10000000, 1, 3, 1,
13-
1, 1, 1 },
11+
/* id, name, pageSize, blockSize, size, tCS, tCLS, tALS, tCLR, tAR, tWP, tRP, tDS, tCH, tCLH, tALH, tWC, tRC, tREA */
12+
{ CHIP_ID_NONE, "No Chip", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
13+
{ CHIP_ID_K9F2G08U0C, "K9F2G08U0C", 0x800, 0x20000, 0x10000000, 20, 12, 12, 10, 10, 12, 12, 12, 5, 5, 5, 25, 25, 20 },
1414
};
1515

1616
uint32_t chipDbGet(ChipInfo *&db)

qt/chip_db.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,20 @@ typedef struct
2424
uint32_t pageSize;
2525
uint32_t blockSize;
2626
uint32_t size;
27-
uint8_t setupTime;
28-
uint8_t waitSetupTime;
29-
uint8_t holdSetupTime;
30-
uint8_t hiZSetupTime;
31-
uint8_t clrSetupTime;
32-
uint8_t arSetupTime;
27+
uint32_t tCS;
28+
uint32_t tCLS;
29+
uint32_t tALS;
30+
uint32_t tCLR;
31+
uint32_t tAR;
32+
uint32_t tWP;
33+
uint32_t tRP;
34+
uint32_t tDS;
35+
uint32_t tCH;
36+
uint32_t tCLH;
37+
uint32_t tALH;
38+
uint32_t tWC;
39+
uint32_t tRC;
40+
uint32_t tREA;
3341
} ChipInfo;
3442

3543
uint32_t chipDbGet(ChipInfo *&db);

qt/programmer.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include "programmer.h"
7+
#include "stm32.h"
78
#include <QDebug>
89

910
#define USB_DEV_NAME "/dev/ttyACM0"
@@ -221,18 +222,21 @@ void Programmer::confChipCb(int ret)
221222
void Programmer::confChip(ChipInfo *chipInfo)
222223
{
223224
ConfCmd confCmd;
225+
StmParams params;
224226
Cmd cmd = { .code = CMD_NAND_CONF };
225227

228+
chipInfoToStmParams(chipInfo, &params);
229+
226230
confCmd.cmd = cmd;
227231
confCmd.pageSize = chipInfo->pageSize;
228232
confCmd.blockSize = chipInfo->blockSize;
229233
confCmd.size = chipInfo->size;
230-
confCmd.setupTime = chipInfo->setupTime;
231-
confCmd.waitSetupTime = chipInfo->waitSetupTime;
232-
confCmd.holdSetupTime = chipInfo->holdSetupTime;
233-
confCmd.hiZSetupTime = chipInfo->hiZSetupTime;
234-
confCmd.clrSetupTime = chipInfo->clrSetupTime;
235-
confCmd.arSetupTime = chipInfo->arSetupTime;
234+
confCmd.setupTime = params.setupTime;
235+
confCmd.waitSetupTime = params.waitSetupTime;
236+
confCmd.holdSetupTime = params.holdSetupTime;
237+
confCmd.hiZSetupTime = params.hiZSetupTime;
238+
confCmd.clrSetupTime = params.clrSetupTime;
239+
confCmd.arSetupTime = params.arSetupTime;
236240

237241
QObject::connect(&reader, SIGNAL(result(int)), this,
238242
SLOT(confChipCb(int)));

qt/qt.pro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ SOURCES += main.cpp\
3131
buffer_table_model.cpp \
3232
writer.cpp \
3333
reader.cpp \
34-
settings_programmer_dialog.cpp
34+
settings_programmer_dialog.cpp \
35+
stm32.cpp
3536

3637
HEADERS += main_window.h \
3738
programmer.h \
@@ -41,7 +42,8 @@ HEADERS += main_window.h \
4142
cmd.h \
4243
writer.h \
4344
reader.h \
44-
settings_programmer_dialog.h
45+
settings_programmer_dialog.h \
46+
stm32.h
4547

4648
FORMS += main_window.ui \
4749
settings_programmer_dialog.ui

qt/stm32.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "stm32.h"
2+
#include <stdint.h>
3+
#include <algorithm>
4+
#include <array>
5+
#include <math.h>
6+
7+
/* Convert NAND parameters to STM32 FSMC parameters.
8+
* See Application Note AN2784.
9+
*/
10+
void chipInfoToStmParams(ChipInfo *chipInfo, StmParams *stmParams)
11+
{
12+
double setupTime, waitSetupTime, hiZSetupTime, holdSetupTime, arSetupTime,
13+
clrSetupTime;
14+
const double tHCLK = 13.88; /* 1 / 72MHz */
15+
const double tsuD_NOE = 25;
16+
std::array<uint32_t, 5> setupArr = { chipInfo->tCH, chipInfo->tCLS,
17+
chipInfo->tALS, chipInfo->tCLR, chipInfo->tAR };
18+
std::array<uint32_t, 3> hiZArr = { chipInfo->tCH, chipInfo->tALS,
19+
chipInfo->tCLS };
20+
std::array<uint32_t, 3> holdArr = { chipInfo->tCH, chipInfo->tCLH,
21+
chipInfo->tALH };
22+
23+
/* (SET + 1) * tHCLK >= max(tCH, tCLS, tALS, tCLR, tAR) - tWP */
24+
setupTime = *std::max_element(setupArr.begin(), setupArr.end()) -
25+
chipInfo->tWP;
26+
setupTime = setupTime / tHCLK - 1;
27+
setupTime = setupTime <= 0 ? 0 : ceil(setupTime);
28+
stmParams->setupTime = static_cast<uint8_t>(setupTime);
29+
30+
/* (WAIT + 1) * tHCLK >= max(tWP, tRP) */
31+
waitSetupTime = std::max(chipInfo->tWP, chipInfo->tRP);
32+
waitSetupTime = waitSetupTime / tHCLK - 1;
33+
waitSetupTime = waitSetupTime <= 0 ? 0 : ceil(waitSetupTime);
34+
stmParams->waitSetupTime = static_cast<uint8_t>(waitSetupTime);
35+
/* (WAIT + 1) *tHCLK >= tREA + tsuD_NOE */
36+
waitSetupTime = chipInfo->tREA + tsuD_NOE;
37+
waitSetupTime = waitSetupTime / tHCLK - 1;
38+
waitSetupTime = waitSetupTime <= 0 ? 0 : ceil(waitSetupTime);
39+
if (waitSetupTime > stmParams->waitSetupTime)
40+
stmParams->waitSetupTime = static_cast<uint8_t>(waitSetupTime);
41+
42+
/* (HIZ + 1) * tHCLK >= max(tCH, tALS, tCLS) + (tWP - tDS) */
43+
hiZSetupTime = *std::max_element(hiZArr.begin(), hiZArr.end());
44+
hiZSetupTime -= chipInfo->tWP - chipInfo->tDS;
45+
hiZSetupTime = hiZSetupTime / tHCLK - 1;
46+
hiZSetupTime = hiZSetupTime <= 0 ? 0 : ceil(hiZSetupTime);
47+
stmParams->hiZSetupTime = static_cast<uint8_t>(hiZSetupTime);
48+
49+
/* (HOLD + 1) * tHCLK >= max(tCH, tCLH, tALH) */
50+
holdSetupTime =*std::max_element(holdArr.begin(), holdArr.end());
51+
holdSetupTime = holdSetupTime / tHCLK - 1;
52+
/* K9F2G08U0C requires at least 1 tick */
53+
holdSetupTime = holdSetupTime <= 0 ? 1 : ceil(holdSetupTime);
54+
stmParams->holdSetupTime = static_cast<uint8_t>(holdSetupTime);
55+
56+
/* ((WAIT + 1) + (HOLD + 1) + (SET + 1)) * tHCLK >= max(tWC, tRC) */
57+
while (((stmParams->setupTime + 1) + (stmParams->waitSetupTime + 1) +
58+
(stmParams->holdSetupTime + 1)) * tHCLK < std::max(chipInfo->tWC,
59+
chipInfo->tRC))
60+
{
61+
stmParams->setupTime++;
62+
}
63+
64+
/* Not clear how to calculate, use the same approach as above */
65+
arSetupTime = chipInfo->tAR / tHCLK - 1;
66+
arSetupTime = arSetupTime <= 0 ? 0 : ceil(arSetupTime);
67+
stmParams->arSetupTime = static_cast<uint8_t>(arSetupTime);
68+
69+
clrSetupTime = chipInfo->tCLR / tHCLK - 1;
70+
clrSetupTime = clrSetupTime <= 0 ? 0 : ceil(clrSetupTime);
71+
stmParams->clrSetupTime = static_cast<uint8_t>(clrSetupTime);
72+
}

qt/stm32.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef STM32_H
2+
#define STM32_H
3+
4+
#include "chip_db.h"
5+
6+
typedef struct
7+
{
8+
uint8_t setupTime;
9+
uint8_t waitSetupTime;
10+
uint8_t holdSetupTime;
11+
uint8_t hiZSetupTime;
12+
uint8_t clrSetupTime;
13+
uint8_t arSetupTime;
14+
} StmParams;
15+
16+
void chipInfoToStmParams(ChipInfo *chipInfo, StmParams *stmParams);
17+
18+
#endif // STM32_H

0 commit comments

Comments
 (0)