Angus Gratton
2017-03-03 12:58:22 +08:00
21 changed files with 171 additions and 33 deletions

View File

@@ -476,8 +476,7 @@ static void btc_search_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data
param.scan_rst.ble_addr_type = p_data->inq_res.ble_addr_type; param.scan_rst.ble_addr_type = p_data->inq_res.ble_addr_type;
param.scan_rst.ble_evt_type = p_data->inq_res.ble_evt_type; param.scan_rst.ble_evt_type = p_data->inq_res.ble_evt_type;
param.scan_rst.flag = p_data->inq_res.flag; param.scan_rst.flag = p_data->inq_res.flag;
memcpy(param.scan_rst.ble_adv, p_data->inq_res.p_eir, memcpy(param.scan_rst.ble_adv, p_data->inq_res.p_eir, sizeof(param.scan_rst.ble_adv));
ESP_BLE_ADV_DATA_LEN_MAX);
break; break;
} }
case BTA_DM_INQ_CMPL_EVT: { case BTA_DM_INQ_CMPL_EVT: {

View File

@@ -182,13 +182,16 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
future_t *future_p; future_t *future_p;
esp_ble_gatts_cb_param_t param; esp_ble_gatts_cb_param_t param;
//set the attribute table create service flag to ture //set the attribute table create service flag to true
btc_creat_tab_env.is_tab_creat_svc = true; btc_creat_tab_env.is_tab_creat_svc = true;
btc_creat_tab_env.num_handle = max_nb_attr; btc_creat_tab_env.num_handle = max_nb_attr;
for(int i = 0; i < max_nb_attr; i++){ for(int i = 0; i < max_nb_attr; i++){
if(gatts_attr_db[i].att_desc.uuid_length== ESP_UUID_LEN_16){ if(gatts_attr_db[i].att_desc.uuid_length== ESP_UUID_LEN_16){
uuid = (gatts_attr_db[i].att_desc.uuid_p[1] << 8) + (gatts_attr_db[i].att_desc.uuid_p[0]); uuid = (gatts_attr_db[i].att_desc.uuid_p[1] << 8) + (gatts_attr_db[i].att_desc.uuid_p[0]);
} }
else{
continue;
}
future_p = future_new(); future_p = future_new();
if (future_p == NULL) { if (future_p == NULL) {
LOG_ERROR("%s failed:no mem\n", __func__); LOG_ERROR("%s failed:no mem\n", __func__);

View File

@@ -50,10 +50,12 @@ extern "C" {
typedef struct { typedef struct {
gpio_num_t gpio_cd; ///< GPIO number of card detect signal gpio_num_t gpio_cd; ///< GPIO number of card detect signal
gpio_num_t gpio_wp; ///< GPIO number of write protect signal gpio_num_t gpio_wp; ///< GPIO number of write protect signal
uint8_t width; ///< Bus width used by the slot (might be less than the max width supported)
} sdmmc_slot_config_t; } sdmmc_slot_config_t;
#define SDMMC_SLOT_NO_CD ((gpio_num_t) -1) ///< indicates that card detect line is not used #define SDMMC_SLOT_NO_CD ((gpio_num_t) -1) ///< indicates that card detect line is not used
#define SDMMC_SLOT_NO_WP ((gpio_num_t) -1) ///< indicates that write protect line is not used #define SDMMC_SLOT_NO_WP ((gpio_num_t) -1) ///< indicates that write protect line is not used
#define SDMMC_SLOT_WIDTH_DEFAULT 0 ///< use the default width for the slot (8 for slot 0, 4 for slot 1)
/** /**
* Macro defining default configuration of SDMMC host slot * Macro defining default configuration of SDMMC host slot
@@ -61,6 +63,7 @@ typedef struct {
#define SDMMC_SLOT_CONFIG_DEFAULT() {\ #define SDMMC_SLOT_CONFIG_DEFAULT() {\
.gpio_cd = SDMMC_SLOT_NO_CD, \ .gpio_cd = SDMMC_SLOT_NO_CD, \
.gpio_wp = SDMMC_SLOT_NO_WP, \ .gpio_wp = SDMMC_SLOT_NO_WP, \
.width = SDMMC_SLOT_WIDTH_DEFAULT, \
} }
/** /**

View File

@@ -299,21 +299,32 @@ esp_err_t sdmmc_host_init_slot(int slot, const sdmmc_slot_config_t* slot_config)
} }
int gpio_cd = slot_config->gpio_cd; int gpio_cd = slot_config->gpio_cd;
int gpio_wp = slot_config->gpio_wp; int gpio_wp = slot_config->gpio_wp;
uint8_t slot_width = slot_config->width;
// Configure pins // Configure pins
const sdmmc_slot_info_t* pslot = &s_slot_info[slot]; const sdmmc_slot_info_t* pslot = &s_slot_info[slot];
if (slot_width == SDMMC_SLOT_WIDTH_DEFAULT) {
slot_width = pslot->width;
}
else if (slot_width > pslot->width) {
return ESP_ERR_INVALID_ARG;
}
configure_pin(pslot->clk); configure_pin(pslot->clk);
configure_pin(pslot->cmd); configure_pin(pslot->cmd);
configure_pin(pslot->d0); configure_pin(pslot->d0);
if (slot_width >= 4) {
configure_pin(pslot->d1); configure_pin(pslot->d1);
configure_pin(pslot->d2); configure_pin(pslot->d2);
configure_pin(pslot->d3); configure_pin(pslot->d3);
if (pslot->width == 8) { if (slot_width == 8) {
configure_pin(pslot->d4); configure_pin(pslot->d4);
configure_pin(pslot->d5); configure_pin(pslot->d5);
configure_pin(pslot->d6); configure_pin(pslot->d6);
configure_pin(pslot->d7); configure_pin(pslot->d7);
} }
}
if (gpio_cd != -1) { if (gpio_cd != -1) {
gpio_set_direction(gpio_cd, GPIO_MODE_INPUT); gpio_set_direction(gpio_cd, GPIO_MODE_INPUT);
gpio_matrix_in(gpio_cd, pslot->card_detect, 0); gpio_matrix_in(gpio_cd, pslot->card_detect, 0);

View File

@@ -11,10 +11,10 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef __ESP_ERR_H__ #pragma once
#define __ESP_ERR_H__
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <assert.h> #include <assert.h>
#ifdef __cplusplus #ifdef __cplusplus
@@ -40,15 +40,38 @@ typedef int32_t esp_err_t;
#define ESP_ERR_WIFI_BASE 0x3000 /*!< Starting number of WiFi error codes */ #define ESP_ERR_WIFI_BASE 0x3000 /*!< Starting number of WiFi error codes */
void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression) __attribute__((noreturn));
#ifndef __ASSERT_FUNC
/* This won't happen on IDF, which defines __ASSERT_FUNC in assert.h, but it does happen when building on the host which
uses /usr/include/assert.h or equivalent.
*/
#ifdef __ASSERT_FUNCTION
#define __ASSERT_FUNC __ASSERT_FUNCTION /* used in glibc assert.h */
#else
#define __ASSERT_FUNC "??"
#endif
#endif
/** /**
* Macro which can be used to check the error code, * Macro which can be used to check the error code,
* and terminate the program in case the code is not ESP_OK. * and terminate the program in case the code is not ESP_OK.
* Prints the failed statement to serial output. * Prints the error code, error location, and the failed statement to serial output.
*
* Disabled if assertions are disabled.
*/ */
#define ESP_ERROR_CHECK(x) do { esp_err_t rc = (x); if (rc != ESP_OK) { assert(0 && #x);} } while(0); #ifdef NDEBUG
#define ESP_ERROR_CHECK(x) do { (x); } while (0)
#else
#define ESP_ERROR_CHECK(x) do { \
esp_err_t rc = (x); \
if (rc != ESP_OK) { \
_esp_error_check_failed(rc, __FILE__, __LINE__, \
__ASSERT_FUNC, #x); \
} \
} while(0);
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* __ESP_ERR_H__ */

View File

@@ -34,6 +34,7 @@
#include "esp_attr.h" #include "esp_attr.h"
#include "esp_err.h" #include "esp_err.h"
#include "esp_core_dump.h" #include "esp_core_dump.h"
#include "esp_spi_flash.h"
/* /*
Panic handlers; these get called when an unhandled exception occurs or the assembly-level Panic handlers; these get called when an unhandled exception occurs or the assembly-level
@@ -107,11 +108,8 @@ void __attribute__((weak)) vApplicationStackOverflowHook( TaskHandle_t xTask, s
static bool abort_called; static bool abort_called;
void abort() static __attribute__((noreturn)) inline void invoke_abort()
{ {
#if !CONFIG_ESP32_PANIC_SILENT_REBOOT
ets_printf("abort() was called at PC 0x%08x\n", (intptr_t)__builtin_return_address(0) - 3);
#endif
abort_called = true; abort_called = true;
while(1) { while(1) {
__asm__ ("break 0,0"); __asm__ ("break 0,0");
@@ -119,6 +117,14 @@ void abort()
} }
} }
void abort()
{
#if !CONFIG_ESP32_PANIC_SILENT_REBOOT
ets_printf("abort() was called at PC 0x%08x\n", (intptr_t)__builtin_return_address(0) - 3);
#endif
invoke_abort();
}
static const char *edesc[] = { static const char *edesc[] = {
"IllegalInstruction", "Syscall", "InstructionFetchError", "LoadStoreError", "IllegalInstruction", "Syscall", "InstructionFetchError", "LoadStoreError",
@@ -441,4 +447,11 @@ void esp_clear_watchpoint(int no)
} }
} }
void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression)
{
ets_printf("ESP_ERROR_CHECK failed: esp_err_t 0x%x at 0x%08x\n", rc, (intptr_t)__builtin_return_address(0) - 3);
if (spi_flash_cache_enabled()) { // strings may be in flash cache
ets_printf("file: \"%s\" line %d\nfunc: %s\nexpression: %s\n", file, line, function, expression);
}
invoke_abort();
}

View File

@@ -29,6 +29,7 @@
#include MBEDTLS_CONFIG_FILE #include MBEDTLS_CONFIG_FILE
#endif #endif
#include "platform.h"
#include "bignum.h" #include "bignum.h"
#include "ecp.h" #include "ecp.h"

View File

@@ -2,6 +2,7 @@ TEST_PROGRAM=test_nvs
all: $(TEST_PROGRAM) all: $(TEST_PROGRAM)
SOURCE_FILES = \ SOURCE_FILES = \
esp_error_check_stub.cpp \
$(addprefix ../src/, \ $(addprefix ../src/, \
nvs_types.cpp \ nvs_types.cpp \
nvs_api.cpp \ nvs_api.cpp \

View File

@@ -0,0 +1,9 @@
#include "catch.hpp"
#include "esp_err.h"
void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression)
{
printf("ESP_ERROR_CHECK failed: esp_err_t 0x%x at %p\n", rc, __builtin_return_address(0));
printf("file: \"%s\" line %d\nfunc: %s\nexpression: %s\n", file, line, function, expression);
abort();
}

View File

@@ -275,3 +275,9 @@ static void IRAM_ATTR spi_flash_restore_cache(uint32_t cpuid, uint32_t saved_sta
} }
} }
IRAM_ATTR bool spi_flash_cache_enabled()
{
return REG_GET_BIT(DPORT_PRO_CACHE_CTRL_REG, DPORT_PRO_CACHE_ENABLE)
&& REG_GET_BIT(DPORT_APP_CACHE_CTRL_REG, DPORT_APP_CACHE_ENABLE);
}

View File

@@ -233,6 +233,12 @@ size_t spi_flash_cache2phys(const void *cached);
*/ */
const void *spi_flash_phys2cache(size_t phys_offs, spi_flash_mmap_memory_t memory); const void *spi_flash_phys2cache(size_t phys_offs, spi_flash_mmap_memory_t memory);
/** @brief Check at runtime if flash cache is enabled on both CPUs
*
* @return true if both CPUs have flash cache enabled, false otherwise.
*/
bool spi_flash_cache_enabled();
/** /**
* @brief SPI flash critical section enter function. * @brief SPI flash critical section enter function.
*/ */

View File

@@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/semphr.h>
#include <unity.h>
#include <esp_spi_flash.h>
#include <esp_attr.h>
#include <esp_flash_encrypt.h>
#include "../cache_utils.h"
static QueueHandle_t result_queue;
static IRAM_ATTR void cache_test_task(void *arg)
{
bool do_disable = (bool)arg;
bool result;
if(do_disable) {
spi_flash_disable_interrupts_caches_and_other_cpu();
}
result = spi_flash_cache_enabled();
if (do_disable) {
spi_flash_enable_interrupts_caches_and_other_cpu();
}
TEST_ASSERT( xQueueSendToBack(result_queue, &result, 0) );
vTaskDelete(NULL);
}
TEST_CASE("spi_flash_cache_enabled() works on both CPUs", "[spi_flash]")
{
result_queue = xQueueCreate(1, sizeof(bool));
for(int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
for(int disable = 0; disable <= 1; disable++) {
bool do_disable = disable;
bool result;
printf("Testing cpu %d disabled %d\n", cpu, do_disable);
xTaskCreatePinnedToCore(cache_test_task, "cache_check_task",
2048, (void *)do_disable, configMAX_PRIORITIES-1, NULL, cpu);
TEST_ASSERT( xQueueReceive(result_queue, &result, 2) );
TEST_ASSERT_EQUAL(!do_disable, result);
}
}
vQueueDelete(result_queue);
}

View File

@@ -731,7 +731,7 @@ esp_err_t tcpip_adapter_set_hostname(tcpip_adapter_if_t tcpip_if, const char *ho
{ {
#if LWIP_NETIF_HOSTNAME #if LWIP_NETIF_HOSTNAME
struct netif *p_netif; struct netif *p_netif;
static char hostinfo[TCPIP_HOSTNAME_MAX_SIZE + 1][TCPIP_ADAPTER_IF_MAX]; static char hostinfo[TCPIP_ADAPTER_IF_MAX][TCPIP_HOSTNAME_MAX_SIZE + 1];
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || hostname == NULL) { if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || hostname == NULL) {
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS; return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
@@ -744,7 +744,7 @@ esp_err_t tcpip_adapter_set_hostname(tcpip_adapter_if_t tcpip_if, const char *ho
p_netif = esp_netif[tcpip_if]; p_netif = esp_netif[tcpip_if];
if (p_netif != NULL) { if (p_netif != NULL) {
memset(hostinfo[tcpip_if], 0, sizeof(hostinfo[tcpip_if])); memset(hostinfo[tcpip_if], 0, sizeof(hostinfo[tcpip_if]));
memcpy(hostinfo[tcpip_if], hostname, strlen(hostname)); strlcpy(hostinfo[tcpip_if], hostname, sizeof(hostinfo[tcpip_if]));
p_netif->hostname = hostinfo[tcpip_if]; p_netif->hostname = hostinfo[tcpip_if];
return ESP_OK; return ESP_OK;
} else { } else {

View File

@@ -79,6 +79,7 @@ Of all the funtions listed below, only ``sdmmc_host_init``, ``sdmmc_host_init_sl
.. doxygendefine:: SDMMC_HOST_SLOT_0 .. doxygendefine:: SDMMC_HOST_SLOT_0
.. doxygendefine:: SDMMC_HOST_SLOT_1 .. doxygendefine:: SDMMC_HOST_SLOT_1
.. doxygendefine:: SDMMC_HOST_DEFAULT .. doxygendefine:: SDMMC_HOST_DEFAULT
.. doxygendefine:: SDMMC_SLOT_WIDTH_DEFAULT
.. doxygenfunction:: sdmmc_host_init_slot .. doxygenfunction:: sdmmc_host_init_slot

View File

@@ -62,6 +62,7 @@ Functions
.. doxygenfunction:: spi_flash_mmap_dump .. doxygenfunction:: spi_flash_mmap_dump
.. doxygenfunction:: spi_flash_cache2phys .. doxygenfunction:: spi_flash_cache2phys
.. doxygenfunction:: spi_flash_phys2cache .. doxygenfunction:: spi_flash_phys2cache
.. doxygenfunction:: spi_flash_cache_enabled
.. doxygenfunction:: esp_partition_find .. doxygenfunction:: esp_partition_find
.. doxygenfunction:: esp_partition_find_first .. doxygenfunction:: esp_partition_find_first
.. doxygenfunction:: esp_partition_get .. doxygenfunction:: esp_partition_get

View File

@@ -144,7 +144,7 @@ The minimal ``component.mk`` file is an empty file(!). If the file is empty, the
See `example component makefiles` for more complete component makefile examples. See `example component makefiles` for more complete component makefile examples.
Note that there is a different between an empty ``component.mk`` file (which invokes default component build behaviour) and no ``component.mk`` file (which means no default component build behaviour will occur.) It is possible for a component to have no `component.mk` file, if it only contains other files which influence the project configuration or build process. Note that there is a difference between an empty ``component.mk`` file (which invokes default component build behaviour) and no ``component.mk`` file (which means no default component build behaviour will occur.) It is possible for a component to have no `component.mk` file, if it only contains other files which influence the project configuration or build process.
.. component variables: .. component variables:

View File

@@ -49,7 +49,9 @@ Project Properties
* Click "Add..." again, and enter name ``IDF_PATH``. The value should be the full path where ESP-IDF is installed. * Click "Add..." again, and enter name ``IDF_PATH``. The value should be the full path where ESP-IDF is installed.
*All users, continue with these steps:* * Edit the ``PATH`` environment variable. Keep the current value, and append the path to the Xtensa toolchain that will installed as part of IDF setup (``something/xtensa-esp32-elf/bin``) if this is not already listed on the PATH.
* On macOS, add a ``PYTHONPATH`` environment variable and set it to ``/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages``. This is so that the system Python, which has pyserial installed as part of the setup steps, overrides any built-in Eclipse Python.
Navigate to "C/C++ General" -> "Preprocessor Include Paths" property page: Navigate to "C/C++ General" -> "Preprocessor Include Paths" property page:

View File

@@ -77,12 +77,18 @@ If you can't think of a reason why you need to build it yourself, then probably
In any case, here are the steps to compile the toolchain yourself. In any case, here are the steps to compile the toolchain yourself.
(Note: You will also need the prerequisite packages mentioned in step 0, above.)
- Install dependencies: - Install dependencies:
- Ubuntu:: - Ubuntu pre-16.04::
sudo apt-get install gawk gperf grep gettext libncurses-dev python python-dev automake bison flex texinfo help2man libtool sudo apt-get install gawk gperf grep gettext libncurses-dev python python-dev automake bison flex texinfo help2man libtool
- Ubuntu 16.04::
sudo apt-get install gawk gperf grep gettext python python-dev automake bison flex texinfo help2man libtool libtool-bin
- Debian:: - Debian::
TODO TODO
@@ -96,7 +102,7 @@ Download ``crosstool-NG`` and build it::
cd ~/esp cd ~/esp
git clone -b xtensa-1.22.x https://github.com/espressif/crosstool-NG.git git clone -b xtensa-1.22.x https://github.com/espressif/crosstool-NG.git
cd crosstool-NG cd crosstool-NG
./bootstrap && ./configure --prefix=$PWD && make install ./bootstrap && ./configure --enable-local && make install
Build the toolchain:: Build the toolchain::

View File

@@ -89,7 +89,7 @@ Download ``crosstool-NG`` and build it::
cd ~/esp cd ~/esp
git clone -b xtensa-1.22.x https://github.com/espressif/crosstool-NG.git git clone -b xtensa-1.22.x https://github.com/espressif/crosstool-NG.git
cd crosstool-NG cd crosstool-NG
./bootstrap && ./configure --prefix=$PWD && make install ./bootstrap && ./configure --enable-local && make install
Build the toolchain:: Build the toolchain::

View File

@@ -45,7 +45,7 @@ void phy_tlk110_check_phy_init(void)
{ {
while((esp_eth_smi_read(BASIC_MODE_STATUS_REG) & AUTO_NEGOTIATION_COMPLETE ) != AUTO_NEGOTIATION_COMPLETE) while((esp_eth_smi_read(BASIC_MODE_STATUS_REG) & AUTO_NEGOTIATION_COMPLETE ) != AUTO_NEGOTIATION_COMPLETE)
{}; {};
while((esp_eth_smi_read(PHY_STATUS_REG) & AUTO_NEGTIATION_STATUS ) != AUTO_NEGTIATION_STATUS) while((esp_eth_smi_read(PHY_STATUS_REG) & AUTO_NEGOTIATION_STATUS ) != AUTO_NEGOTIATION_STATUS)
{}; {};
while((esp_eth_smi_read(CABLE_DIAGNOSTIC_CONTROL_REG) & DIAGNOSTIC_DONE ) != DIAGNOSTIC_DONE) while((esp_eth_smi_read(CABLE_DIAGNOSTIC_CONTROL_REG) & DIAGNOSTIC_DONE ) != DIAGNOSTIC_DONE)
{}; {};
@@ -108,7 +108,7 @@ void phy_tlk110_init(void)
while (esp_eth_smi_read(PHY_IDENTIFIER_REG) != OUI_MSB_21TO6_DEF) { while (esp_eth_smi_read(PHY_IDENTIFIER_REG) != OUI_MSB_21TO6_DEF) {
} }
esp_eth_smi_write(SOFTWARE_STRAP_CONTROL_REG, DEFAULT_PHY_CONFIG |SW_STRAP_CONFIG_DONE); esp_eth_smi_write(SW_STRAP_CONTROL_REG, DEFAULT_PHY_CONFIG | SW_STRAP_CONFIG_DONE);
ets_delay_us(300); ets_delay_us(300);

View File

@@ -13,7 +13,7 @@
#define PARTNER_ASM_DIR BIT(11) #define PARTNER_ASM_DIR BIT(11)
#define PARTNER_PAUSE BIT(10) #define PARTNER_PAUSE BIT(10)
#define SOFTWARE_STRAP_CONTROL_REG (0x9) #define SW_STRAP_CONTROL_REG (0x9)
#define SW_STRAP_CONFIG_DONE BIT(15) #define SW_STRAP_CONFIG_DONE BIT(15)
#define AUTO_MDIX_ENABLE BIT(14) #define AUTO_MDIX_ENABLE BIT(14)
#define AUTO_NEGOTIATION_ENABLE BIT(13) #define AUTO_NEGOTIATION_ENABLE BIT(13)
@@ -23,7 +23,7 @@
#define RMII_ENHANCED_MODE BIT(9) #define RMII_ENHANCED_MODE BIT(9)
#define PHY_STATUS_REG (0x10) #define PHY_STATUS_REG (0x10)
#define AUTO_NEGTIATION_STATUS BIT(4) #define AUTO_NEGOTIATION_STATUS BIT(4)
#define DUPLEX_STATUS BIT(2) #define DUPLEX_STATUS BIT(2)
#define SPEED_STATUS BIT(1) #define SPEED_STATUS BIT(1)