Skip to content

Commit adf9d90

Browse files
committed
Get Write opperations working
Did a general rewrite of the cli App class, again. Finally got the communication to work properly, and fixed the memory write drivers which were a mess. Also tuned the i2c timeouts according with the datasheets and the link speed (at the moment set at 100 kHz) This is almost ready to merge with main branch. Only thing left is to test on Windows.
1 parent b52a106 commit adf9d90

File tree

18 files changed

+474
-430
lines changed

18 files changed

+474
-430
lines changed

eeprom_programmer_PC/eeprom-programmer.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
2020

2121
# Disable debug messages for release builds
2222
# evaluate only when "release" is defined of the two options "debug" and "release"
23-
#CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
23+
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
2424
DEFINES += QT_NO_DEBUG_OUTPUT
2525

2626
# You can also make your code fail to compile if you use deprecated APIs.

eeprom_programmer_PC/eeprom-programmer.pro.user

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 6.0.2, 2022-03-20T22:37:06. -->
3+
<!-- Written by QtCreator 6.0.2, 2022-03-23T00:50:34. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>
@@ -245,7 +245,7 @@
245245
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">eeprom-programmer2</value>
246246
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/feer/coding/stm32/STM32CubeIDE/eeprom-programmer/eeprom_programmer_PC/eeprom-programmer.pro</value>
247247
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">/home/feer/coding/stm32/STM32CubeIDE/eeprom-programmer/eeprom_programmer_PC/eeprom-programmer.pro</value>
248-
<value type="QString" key="RunConfiguration.Arguments">X24645 -r</value>
248+
<value type="QString" key="RunConfiguration.Arguments">X24645 -w</value>
249249
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
250250
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
251251
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>

eeprom_programmer_PC/src/app.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1-
#include "app.h"
1+
/*
2+
* EEPROM-Programmer - Read and write EEPROM memories.
3+
* Copyright (C) 2022 Fernando Coda <fcoda@pm.me>
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along
16+
* with this program; if not, write to the Free Software Foundation, Inc.,
17+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
219

20+
#include "app.h"
321

422

523
App::App(int &argc, char **argv, FILE* outStream)
@@ -47,11 +65,11 @@ void App::setSignals()
4765
void App::setCommandLineOptions(QCommandLineParser& parser)
4866
{
4967
App::setApplicationName("EEPROM Programmer");
50-
App::setApplicationVersion("1.0");
68+
App::setApplicationVersion("2.0-rc1");
5169
parser.setApplicationDescription("Read and write EEPROM memories.");
5270

5371
parser.addOption({{"h", "help"},
54-
"Displays help on commandline options."});
72+
"Displays help on commandline options."});
5573
parser.addVersionOption();
5674

5775
parser.addOptions({
@@ -62,9 +80,9 @@ void App::setCommandLineOptions(QCommandLineParser& parser)
6280
{{"f", "file"},
6381
"Read from / write to <file>.", "file"},
6482
{{"p", "port"},
65-
"Select the serial port to connect.", "port"},
83+
"Connect to serial port <port>.", "port"},
6684
{{"b", "baudrate"},
67-
"Set the desired baudrate.", "baudrate"},
85+
"Set the serial port baudrate to <baudrate>.", "baudrate"},
6886
});
6987

7088
parser.addPositionalArgument("target", "24LC16 - X24645 - 24LC64 - 24LC256");
@@ -103,12 +121,12 @@ bool App::configure() {
103121
}
104122

105123
if(parser.isSet("write")) {
106-
setOperation(CMD_WRITEMEM);
124+
setNextOperation(OP_TX);
107125
if(!targetFile.isNull())
108126
setInputFilename(targetFile);
109127
}
110128
else if(parser.isSet("read")) {
111-
setOperation(CMD_READMEM);
129+
setNextOperation(OP_RX);
112130
if(!targetFile.isNull())
113131
setOutputFilename(targetFile);
114132
}
@@ -153,7 +171,7 @@ void App::setOutputFilename(const QString &newFilename_out)
153171
m_filename_out = newFilename_out;
154172
}
155173

156-
void App::setOperation(int newOperation)
174+
void App::setNextOperation(operations_e newOperation)
157175
{
158-
m_requestedOperation = newOperation;
176+
m_nextOperation = newOperation;
159177
}

eeprom_programmer_PC/src/app.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,28 @@
1010
#include <QCommandLineParser>
1111
#include <QFile>
1212

13-
14-
1513
class App: public MemoryComm
1614
{
1715

1816
public:
1917
App(int &argc, char **argv, FILE* outStream = stdout);
2018
~App();
2119

22-
23-
void setOperation(int newOperation);
2420
void setOutputFilename(const QString &newFilename_out);
2521
void setInputFilename(const QString &newFilename_in);
22+
void setNextOperation(operations_e newOperation);
2623

2724
const QString &getInputFilename() const;
2825
const QString &getOutputFilename() const;
2926

27+
enum app_states_e {
28+
ST_DISCONNECTED,
29+
ST_INIT,
30+
ST_IDLE,
31+
ST_PING,
32+
ST_WAIT_READMEM,
33+
ST_WAIT_WRITEMEM
34+
};
3035

3136
private slots:
3237
void handleTimeout(void);
@@ -39,7 +44,6 @@ private slots:
3944
void printError(pkgdata_t *pkg);
4045
bool configure(void);
4146

42-
4347
void printData(void);
4448
virtual bool saveData(void);
4549
virtual void reconnect();
@@ -49,14 +53,17 @@ private slots:
4953
QByteArray m_memBuffer;
5054
QTimer m_pingTimer;
5155

52-
int m_xferState = 0;
56+
app_states_e m_xferState = ST_DISCONNECTED;
5357
bool m_connected = false;
54-
int m_requestedOperation = 0;
58+
// Use two variables so we can change one without affecting
59+
// the other (new requests will go to m_nextOperation).
60+
operations_e m_currentOperation = OP_NONE;
61+
operations_e m_nextOperation = OP_NONE;
5562

56-
QString m_filename_in = "mem_in.bin";
63+
QString m_filename_in = "mem_in.bin";
5764
QString m_filename_out = "mem_out.bin";
5865
void setSignals();
59-
void doStuff();
66+
bool doSomething();
6067
};
6168

6269
// m_ = member

0 commit comments

Comments
 (0)