Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
risc-v-wifi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWPws2020
risc-v-wifi
Commits
a3e7d6d6
Commit
a3e7d6d6
authored
Feb 6, 2021
by
aticu
Browse files
Options
Downloads
Patches
Plain Diff
Improved stability of the ESP32 driver
parent
9360df65
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
sifive_software/src/esp32.c
+38
-29
38 additions, 29 deletions
sifive_software/src/esp32.c
sifive_software/src/spi.c
+2
-0
2 additions, 0 deletions
sifive_software/src/spi.c
with
40 additions
and
29 deletions
sifive_software/src/esp32.c
+
38
−
29
View file @
a3e7d6d6
...
...
@@ -116,6 +116,7 @@ enum esp32_result esp32_recv(void) {
// Checks whether the expected value and length was received, without performing a new receive operation.
enum
esp32_result
esp32_check_expectation
(
int
how
,
const
char
*
expected_value
,
uint32_t
expected_len
)
{
if
(
strncmp
(
expected_value
,
recv_buf
,
min
(
expected_len
,
recv_len
))
!=
0
||
recv_len
!=
expected_len
)
{
#if VERBOSITY > 0
if
(
how
==
EXPECT_NOISY
)
{
printf
(
"Got an unexpected reply from ESP32:
\r\n
"
);
...
...
@@ -140,10 +141,13 @@ enum esp32_result esp32_check_expectation(int how, const char *expected_value, u
}
if
(
recv_buf
[
0
]
==
'\r'
&&
recv_buf
[
1
]
==
'\n'
)
{
printf
(
" Data (string):
\\
r
\\
n%s
\r\n
"
,
&
recv_buf
[
2
]);
}
else
if
(
recv_len
==
0
)
{
printf
(
" Data (string): <no data>
\r\n
"
);
}
else
{
printf
(
" Data (string): %s
\r\n
"
,
recv_buf
);
}
}
#endif
return
ESP32_ERR
;
}
...
...
@@ -197,33 +201,27 @@ enum esp32_result esp32_connect_to_ap(const char *ssid, const char *pwd) {
// Join the AP
spi_send
(
join_msg
);
// Check the result of the command
if
(
esp32_expect
(
"WIFI CONNECTED
\r\n
"
,
16
)
==
ESP32_ERR
)
{
// We expect three messages in return if everything goes well:
// - WIFI CONNECTED
// - WIFI GOT IP
// - OK
//
// These messages take some time to appear however, so we just try receiving messages until they arrive.
while
(
esp32_recv
()
==
ESP32_ERR
);
if
(
esp32_check_expectation
(
EXPECT_NOISY
,
"WIFI CONNECTED
\r\n
"
,
16
)
==
ESP32_ERR
)
{
return
ESP32_ERR
;
}
// Check the status until we are connected.
do
{
spi_send
(
"AT+CIPSTATUS
\r\n
"
);
esp32_recv
();
delay
(
DELAY
);
}
while
(
esp32_check_expectation
(
EXPECT_SILENT
,
MSG_BUSY
)
==
ESP32_OK
||
esp32_check_expectation
(
EXPECT_SILENT
,
"ERR CODE:0x010b0000
\r\n
"
,
21
)
==
ESP32_OK
||
esp32_check_expectation
(
EXPECT_SILENT
,
"WIFI GOT IP
\r\n
"
,
13
)
==
ESP32_OK
);
// At most one "OK" message can occur here, preceding the status
while
(
esp32_check_expectation
(
EXPECT_SILENT
,
MSG_OK
)
==
ESP32_OK
)
{
esp32_recv
();
while
(
esp32_recv
()
==
ESP32_ERR
);
if
(
esp32_check_expectation
(
EXPECT_NOISY
,
"WIFI GOT IP
\r\n
"
,
13
)
==
ESP32_ERR
)
{
return
ESP32_ERR
;
}
// Check the status reports to ensure that we are connected
if
(
esp32_check_expectation
(
EXPECT_NOISY
,
"STATUS:2
\r\n
"
,
10
)
==
ESP32_ERR
)
{
while
(
esp32_recv
()
==
ESP32_ERR
);
if
(
esp32_check_expectation
(
EXPECT_NOISY
,
MSG_OK
)
==
ESP32_ERR
)
{
return
ESP32_ERR
;
}
// Soak up any extra messages generated by the status requests
while
(
esp32_recv
()
==
ESP32_OK
)
{}
return
ESP32_OK
;
}
...
...
@@ -358,7 +356,6 @@ enum esp32_event esp32_wait_for_event(uint32_t *id, uint32_t *len, char **data)
return
ESP32_CLOSED_CONNECTION
;
}
if
(
data
!=
NULL
)
{
*
data
=
buf
;
}
...
...
@@ -384,15 +381,18 @@ enum esp32_result esp32_send(uint32_t id, uint32_t len, char *data) {
// Actually send the data
spi_send_with_len
(
data
,
len
);
esp32_recv
();
if
(
strncmp
(
recv_buf
,
"
\r\n
Recv "
,
7
)
!=
0
)
{
printf
(
"Unexpected message from the ESP32.
\r\n
"
);
return
ESP32_ERR
;
}
buf_len
=
35
;
char
recv_msg_buf
[
buf_len
];
snprintf
(
recv_msg_buf
,
buf_len
,
"
\r\n
Recv %d bytes
\r\n
"
,
len
);
esp32_expect
(
recv_msg_buf
,
strlen
(
recv_msg_buf
));
if
(
esp32_expect
(
"
\r\n
SEND OK
\r\n
"
,
11
)
==
ESP32_ERR
)
{
// Usually the ESP32 will send a SEND OK message here, but there appear to be some situations in which
// that message is not sent, so we check it here, but don't error if it doesn't exist.
if
(
esp32_recv
()
==
ESP32_OK
)
{
if
(
esp32_check_expectation
(
EXPECT_NOISY
,
"
\r\n
SEND OK
\r\n
"
,
11
)
==
ESP32_ERR
)
{
return
ESP32_ERR
;
}
}
return
ESP32_OK
;
}
...
...
@@ -404,9 +404,18 @@ enum esp32_result esp32_close_connection(uint32_t id) {
snprintf
(
send_msg
,
buf_len
,
"AT+CIPCLOSE=%d
\r\n
"
,
id
);
spi_send
(
send_msg
);
if
(
esp32_expect
(
MSG_OK
)
==
ESP32_ERR
)
{
// Sometimes the ESP32 sends no message here (but with extreme delay), so we also accept no message.
if
(
esp32_recv
()
==
ESP32_OK
)
{
// After trying it a couple of times, it became apparent that sometimes an error is returned here.
// The connection will still appear to be closed on the ESP32 (at least the ID is reused).
// This is likely because the other party disconnected first.
// Because of this we accept both OK and ERROR messages here.
if
(
esp32_check_expectation
(
EXPECT_SILENT
,
MSG_OK
)
!=
ESP32_OK
&&
esp32_check_expectation
(
EXPECT_SILENT
,
"
\r\n
ERROR
\r\n
"
,
9
)
!=
ESP32_OK
)
{
// We did not get the expected message, now we just do a noisy comparison to report the error.
esp32_check_expectation
(
EXPECT_NOISY
,
MSG_OK
);
return
ESP32_ERR
;
}
}
return
ESP32_OK
;
}
...
...
This diff is collapsed.
Click to expand it.
sifive_software/src/spi.c
+
2
−
0
View file @
a3e7d6d6
...
...
@@ -110,7 +110,9 @@ void spi_init(uint32_t spi_clock)
// Enable IOF for pin 3,4,5,9 (don't touch other pins)
IOF_EN
|=
IOF_SPI_ENABLE
;
#if VERBOSITY > 2
printf
(
"DONE
\r\n
"
);
#endif
}
//----------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment