From 2f3aa40c9125fb07d6e25476497d09e0503b7dd3 Mon Sep 17 00:00:00 2001 From: XiongYu Date: Wed, 27 Feb 2019 20:32:25 +0800 Subject: [PATCH] feature(spi): optimizing hspi example --- components/esp8266/driver/gpio.c | 5 +- components/esp8266/driver/spi.c | 3 +- examples/peripherals/spi_master/README.md | 80 ++------ .../spi_master/main/spi_master_example_main.c | 187 +++++++----------- examples/peripherals/spi_slave/README.md | 78 ++------ .../spi_slave/main/spi_slave_example_main.c | 132 +++++++------ 6 files changed, 187 insertions(+), 298 deletions(-) diff --git a/components/esp8266/driver/gpio.c b/components/esp8266/driver/gpio.c index a1c5d546..460cd6f2 100644 --- a/components/esp8266/driver/gpio.c +++ b/components/esp8266/driver/gpio.c @@ -338,7 +338,7 @@ esp_err_t gpio_config(const gpio_config_t *gpio_cfg) return ESP_OK; } -void gpio_intr_service(void *arg) +void IRAM_ATTR gpio_intr_service(void *arg) { //GPIO intr process uint32_t gpio_num = 0; @@ -352,11 +352,10 @@ void gpio_intr_service(void *arg) do { if (gpio_num < GPIO_PIN_COUNT - 1) { if (gpio_intr_status & BIT(gpio_num)) { //gpio0-gpio15 + GPIO.status_w1tc = BIT(gpio_num); if (gpio_isr_func[gpio_num].fn != NULL) { gpio_isr_func[gpio_num].fn(gpio_isr_func[gpio_num].args); } - - GPIO.status_w1tc = BIT(gpio_num); } } } while (++gpio_num < GPIO_PIN_COUNT - 1); diff --git a/components/esp8266/driver/spi.c b/components/esp8266/driver/spi.c index 5f43728c..a7ce207c 100644 --- a/components/esp8266/driver/spi.c +++ b/components/esp8266/driver/spi.c @@ -210,7 +210,8 @@ esp_err_t spi_set_mode(spi_host_t host, spi_mode_t *mode) SPI[host]->pin.slave_mode = true; SPI[host]->slave.slave_mode = true; SPI[host]->user.usr_miso_highpart = true; - SPI[host]->ctrl2.mosi_delay_num = 1; + // MOSI signals are delayed by APB_CLK(80MHz) mosi_delay_num cycles + SPI[host]->ctrl2.mosi_delay_num = 2; SPI[host]->ctrl2.miso_delay_num = 0; SPI[host]->slave.wr_rd_sta_en = 1; SPI[host]->slave1.status_bitlen = 31; diff --git a/examples/peripherals/spi_master/README.md b/examples/peripherals/spi_master/README.md index ebda9bce..1cc8640d 100644 --- a/examples/peripherals/spi_master/README.md +++ b/examples/peripherals/spi_master/README.md @@ -51,68 +51,24 @@ See the Getting Started Guide for full steps to configure and use ESP-IDF to bui * LOG: ``` -I (214) spi_master_example: init gpio -I (216) gpio: GPIO[4]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:1 -I (238) spi_master_example: init spi -I (1238) spi_master_example: ------Master read------ - -I (1231) spi_master_example: addr: 0x0 - -I (1233) spi_master_example: read_data[0]: 0xaaaaaaaa - -I (1249) spi_master_example: read_data[1]: 0xbbbbbbbb - -I (1248) spi_master_example: read_data[2]: 0xcccccccc - -I (1257) spi_master_example: read_data[3]: 0xdddddddd - -I (1266) spi_master_example: read_data[4]: 0xeeeeeeee - -I (1275) spi_master_example: read_data[5]: 0xffffffff - -I (1284) spi_master_example: read_data[6]: 0xaaaabbbb - -I (1293) spi_master_example: read_data[7]: 0x0 - -I (1301) spi_master_example: ------Master read------ - -I (1310) spi_master_example: addr: 0x1 - -I (1317) spi_master_example: read_data[0]: 0xaaaaaaaa - -I (1326) spi_master_example: read_data[1]: 0xbbbbbbbb - -I (1335) spi_master_example: read_data[2]: 0xcccccccc - -I (1344) spi_master_example: read_data[3]: 0xdddddddd - -I (1353) spi_master_example: read_data[4]: 0xeeeeeeee - -I (1363) spi_master_example: read_data[5]: 0xffffffff - -I (1372) spi_master_example: read_data[6]: 0xaaaabbbb - -I (1381) spi_master_example: read_data[7]: 0x1 - -I (1399) spi_master_example: ------Master read------ - -I (1408) spi_master_example: addr: 0x2 - -I (1405) spi_master_example: read_data[0]: 0xaaaaaaaa - -I (1414) spi_master_example: read_data[1]: 0xbbbbbbbb - -I (1423) spi_master_example: read_data[2]: 0xcccccccc - -I (1432) spi_master_example: read_data[3]: 0xdddddddd - -I (1441) spi_master_example: read_data[4]: 0xeeeeeeee - -I (1450) spi_master_example: read_data[5]: 0xffffffff - -I (1469) spi_master_example: read_data[6]: 0xaaaabbbb - -I (1478) spi_master_example: read_data[7]: 0x2 +I (516) spi_master_example: init gpio +I (526) gpio: GPIO[4]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:1 +I (536) spi_master_example: init spi +I (556) spi_master_example: Master wrote 3200 bytes in 4302 us +I (656) spi_master_example: Master wrote 3200 bytes in 4519 us +I (766) spi_master_example: Master wrote 3200 bytes in 4522 us +I (866) spi_master_example: Master wrote 3200 bytes in 4520 us +I (966) spi_master_example: Master wrote 3200 bytes in 4521 us +I (1066) spi_master_example: Master wrote 3200 bytes in 4520 us +I (1166) spi_master_example: Master wrote 3200 bytes in 4522 us +I (1266) spi_master_example: Master wrote 3200 bytes in 4521 us +I (1366) spi_master_example: Master wrote 3200 bytes in 4520 us +I (1466) spi_master_example: Master wrote 3200 bytes in 4520 us +I (1566) spi_master_example: Master wrote 3200 bytes in 4520 us +I (1666) spi_master_example: Master wrote 3200 bytes in 4519 us +I (1766) spi_master_example: Master wrote 3200 bytes in 4521 us +I (1866) spi_master_example: Master wrote 3200 bytes in 4519 us +I (1966) spi_master_example: Master wrote 3200 bytes in 4520 us ``` * WAVE FORM: diff --git a/examples/peripherals/spi_master/main/spi_master_example_main.c b/examples/peripherals/spi_master/main/spi_master_example_main.c index 5a1e6026..22abc310 100644 --- a/examples/peripherals/spi_master/main/spi_master_example_main.c +++ b/examples/peripherals/spi_master/main/spi_master_example_main.c @@ -8,12 +8,15 @@ */ #include - +#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "freertos/queue.h" +#include "freertos/semphr.h" +#include "ringbuf.h" +#include "esp8266/spi_struct.h" #include "esp8266/gpio_struct.h" +#include "esp_system.h" #include "esp_log.h" #include "driver/gpio.h" @@ -21,61 +24,62 @@ static const char *TAG = "spi_master_example"; -#define SPI_SLAVE_HANDSHARK_GPIO 4 -#define SPI_SLAVE_HANDSHARK_SEL (1ULL< - +#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "freertos/queue.h" #include "freertos/semphr.h" +#include "ringbuf.h" +#include "esp8266/spi_struct.h" #include "esp8266/gpio_struct.h" +#include "esp_system.h" #include "esp_log.h" #include "driver/gpio.h" @@ -25,20 +27,25 @@ static const char *TAG = "spi_slave_example"; #define SPI_SLAVE_HANDSHARK_GPIO 4 #define SPI_SLAVE_HANDSHARK_SEL (1ULL<