8000 Fix for #723, SPI communication problem described in "Improve SPI interface (GIT8266O-397)" (GIT8266O-706) by vargavik · Pull Request #1128 · espressif/ESP8266_RTOS_SDK · GitHub
[go: up one dir, main page]

Skip to content

Fix for #723, SPI communication problem described in "Improve SPI interface (GIT8266O-397)" (GIT8266O-706) #1128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ docs/doxygen_sqlite3.db
.settings

# MacOS directory files
.DS_Store
.DS_Store
examples/wifi/getting_started/station/.vs/
15 changes: 6 additions & 9 deletions components/esp8266/driver/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,8 @@ static esp_err_t SPI_HIGH_THROUGHPUT_ATTR spi_master_trans(spi_host_t host, spi_
SPI[host]->data_buf[y] = trans->mosi[y];
}
} else {
ESP_LOGW(TAG,"Using unaligned data may reduce transmission efficiency");
memset(spi_object[host]->buf, 0, sizeof(uint32_t) * 16);
memcpy(spi_object[host]->buf, trans->mosi, trans->bits.mosi / 8 + (trans->bits.mosi % 8) ? 1 : 0);
memcpy(spi_object[host]->buf, trans->mosi, trans->bits.mosi / 8 + ((trans->bits.mosi % 8) ? 1 : 0));

for (x = 0; x < trans->bits.mosi; x += 32) {
y = x / 32;
SPI[host]->data_buf[y] = spi_object[host]->buf[y];
Expand Down Expand Up @@ -522,19 +521,17 @@ static esp_err_t SPI_HIGH_THROUGHPUT_ATTR spi_master_trans(spi_host_t host, spi_
if (trans->bits.miso && trans->miso) {
while (SPI[host]->cmd.usr);

if ((uint32_t)(trans->miso) % 4 == 0) {
if ((uint32_t)(trans->miso) % 4 == 0 && trans->bits.miso % 32 == 0) {
for (x = 0; x < trans->bits.miso; x += 32) {
y = x / 32;
trans->miso[y] = SPI[host]->data_buf[y];
}
} else {
ESP_LOGW(TAG,"Using unaligned data may reduce transmission efficiency");
memset(spi_object[host]->buf, 0, sizeof(uint32_t) * 16);
for (x = 0; x < trans->bits.miso; x += 32) {
y = x / 32;
spi_object[host]->buf[y] = SPI[host]->data_buf[y];
}
memcpy(trans->miso, spi_object[host]->buf, trans->bits.miso / 8 + (trans->bits.miso % 8) ? 1 : 0);
memcpy(trans->miso, spi_object[host]->buf, trans->bits.miso / 8 + ((trans->bits.miso % 8) ? 1 : 0));
}
}

Expand Down Expand Up @@ -577,7 +574,7 @@ static esp_err_t SPI_HIGH_THROUGHPUT_ATTR spi_slave_trans(spi_host_t host, spi_t
} else {
ESP_LOGW(TAG,"Using unaligned data may reduce transmission efficiency");
memset(spi_object[host]->buf, 0, sizeof(uint32_t) * 16);
memcpy(spi_object[host]->buf, trans->miso, trans->bits.miso / 8 + (trans->bits.miso % 8) ? 1 : 0);
memcpy(spi_object[host]->buf, trans->miso, trans->bits.miso / 8 + ((trans->bits.miso % 8) ? 1 : 0));
for (x = 0; x < trans->bits.miso; x += 32) {
y = x / 32;
SPI[host]->data_buf[y] = spi_object[host]->buf[y];
Expand All @@ -599,7 +596,7 @@ static esp_err_t SPI_HIGH_THROUGHPUT_ATTR spi_slave_trans(spi_host_t host, spi_t
y = x / 32;
spi_object[host]->buf[y] = SPI[host]->data_buf[y];
}
memcpy(trans->mosi, spi_object[host]->buf, trans->bits.mosi / 8 + (trans->bits.mosi % 8) ? 1 : 0);
memcpy(trans->mosi, spi_object[host]->buf, trans->bits.mosi / 8 + ((trans->bits.mosi % 8) ? 1 : 0));
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/spi_flash/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(srcs "src/partition"
set(srcs "src/partition.c"
"src/spi_flash_raw.c"
"src/spi_flash.c")
if(BOOTLOADER_BUILD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@
#include "mbedtls/certs.h"

/* Constants that aren't configurable in menuconfig */
#define WEB_SERVER "www.howsmyssl.com"
//#define WEB_SERVER "www.howsmyssl.com"
#define WEB_SERVER "home.z52.hu"
#define WEB_PORT "443"
#define WEB_URL "https://www.howsmyssl.com/a/check"
//#define WEB_URL "https://www.howsmyssl.com/a/check"
#define WEB_URL "https://home.z52.hu"

static const char *TAG = "example";

Expand Down
1 change: 1 addition & 0 deletions examples/storage/spiffs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(spiffs)
spiffs_create_partition_image(spiffs data)
Binary file added examples/storage/spiffs/_spiffs.bin
Binary file not shown.
Binary file added examples/storage/spiffs/_spiffs_r.bin
Binary file not shown.
5 changes: 5 additions & 0 deletions examples/storage/spiffs/data/ademo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ademo szoveg




5 changes: 5 additions & 0 deletions examples/storage/spiffs/data/demo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
masik demo szoveg




3 changes: 3 additions & 0 deletions examples/storage/spiffs/flashspiffs.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rem mkspiffs -c data -b 4096 -p 256 -s 458752 spiffs.bin
python spiffsgen.py 0x70000 data spiffs.bin
python %IDF_PATH%/components/esptool_py/esptool/esptool.py --chip esp8266 --port COM5 --baud 115200 --before default_reset --after hard_reset write_flash -z 0x90000 spiffs.bin
92 changes: 66 additions & 26 deletions examples/storage/spiffs/main/spiffs_example_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "esp_err.h"
#include "esp_log.h"
#include "esp_spiffs.h"
#include <dirent.h>
#include <sys/stat.h>

static const char *TAG = "example";

Expand All @@ -21,7 +23,7 @@ void app_main(void)
ESP_LOGI(TAG, "Initializing SPIFFS");

esp_vfs_spiffs_conf_t conf = {
.base_path = "/spiffs",
.base_path = "",
.partition_label = NULL,
.max_files = 5,
.format_if_mount_failed = true
Expand Down Expand Up @@ -49,36 +51,58 @@ void app_main(void)
} else {
ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
}


DIR *dp;
struct dirent *ep;
dp = opendir ("/");

// Use POSIX and C standard library functions to work with files.
// First create a file.
ESP_LOGI(TAG, "Opening file");
FILE* f = fopen("/spiffs/hello.txt", "w");
if (f == NULL) {
ESP_LOGE(TAG, "Failed to open file for writing");
return;
}
fprintf(f, "Hello World!\n");
fclose(f);
ESP_LOGI(TAG, "File written");
if (dp != NULL)
{
while ((ep = readdir (dp)))
puts (ep->d_name);

// Check if destination file exists before renaming
struct stat st;
if (stat("/spiffs/foo.txt", &st) == 0) {
// Delete it if it exists
unlink("/spiffs/foo.txt");
}
(void) closedir (dp);
}
else
ESP_LOGE(TAG, "Couldn't open the directory");

FILE* f = NULL;

// // // Use POSIX and C standard library functions to work with files.
// // // First create a file.
// ESP_LOGI(TAG, "Opening file");
// f = fopen("/ademo.txt", "w");
// if (f == NULL) {
// ESP_LOGE(TAG, "Failed to open file for writing");
// return;
// }
// fprintf(f, "ademo szoveg");
// fclose(f);
// ESP_LOGI(TAG, "File written");

// Rename original file
ESP_LOGI(TAG, "Renaming file");
if (rename("/spiffs/hello.txt", "/spiffs/foo.txt") != 0) {
ESP_LOGE(TAG, "Rename failed");
return;
}
// // Check if destination file exists before renaming
// struct stat st;
// if (stat("/spiffs/foo.txt", &st) == 0) {
// // Delete it if it exists
// unlink("/spiffs/foo.txt");
// }

// // Rename original file
// ESP_LOGI(TAG, "Renaming file");
// if (rename("/spiffs/hello.txt", "/spiffs/foo.txt") != 0) {
// ESP_LOGE(TAG, "Rename failed");
// return;
// }

struct stat st;
stat("/demo.txt", &st);
int size = st.st_size;

// Open renamed file for reading
ESP_LOGI(TAG, "Reading file");
f = fopen("/spiffs/foo.txt", "r");
ESP_LOGI(TAG, "Reading file (size %u)",size);
f = fopen("/ademo.txt", "r");
//f = fopen("/spiffs/foo.txt", "r");
if (f == NULL) {
ESP_LOGE(TAG, "Failed to open file for reading");
return;
Expand All @@ -91,6 +115,22 @@ void app_main(void)
if (pos) {
*pos = '\0';
}
ESP_LOGI(TAG, "Read from file: '%s'", line);

// Open file for reading
ESP_LOGI(TAG, "Reading file");
f = fopen("/demo.txt", "r");
if (f == NULL) {
ESP_LOGE(TAG, "Failed to open file for reading");
return;
}
fgets(line, sizeof(line), f);
fclose(f);
// strip newline
pos = strchr(line, '\n');
if (pos) {
*pos = '\0';
}
ESP_LOGI(TAG, "Read from file: '%s'", line);

// All done, unmount partition and disable SPIFFS
Expand Down
Binary file added examples/storage/spiffs/mkspiffs.exe
Binary file not shown.
Loading
0