Skip to content
Snippets Groups Projects
Unverified Commit 907b7617 authored by Sebastian Meiling's avatar Sebastian Meiling Committed by GitHub
Browse files

Merge pull request #10792 from gschorcht/esp8266_esp_wifi_netdev

esp8266: esp_wifi netdev driver
parents a65fede8 e6cf33eb
No related branches found
No related tags found
No related merge requests found
Showing with 3141 additions and 26 deletions
...@@ -7,4 +7,8 @@ DIRS += periph ...@@ -7,4 +7,8 @@ DIRS += periph
DIRS += sdk DIRS += sdk
DIRS += vendor DIRS += vendor
ifneq (, $(filter esp_wifi, $(USEMODULE)))
DIRS += esp-wifi
endif
include $(RIOTBASE)/Makefile.base include $(RIOTBASE)/Makefile.base
...@@ -2,6 +2,14 @@ ...@@ -2,6 +2,14 @@
ifneq (, $(filter esp_sdk, $(USEMODULE))) ifneq (, $(filter esp_sdk, $(USEMODULE)))
USEMODULE += core_thread_flags USEMODULE += core_thread_flags
LINKFLAGS += -Wl,-wrap=malloc
LINKFLAGS += -Wl,-wrap=free
LINKFLAGS += -Wl,-wrap=calloc
LINKFLAGS += -Wl,-wrap=realloc
LINKFLAGS += -Wl,-wrap=_malloc_r
LINKFLAGS += -Wl,-wrap=_free_r
LINKFLAGS += -Wl,-wrap=_realloc_r
LINKFLAGS += -Wl,-wrap=mallinfo
endif endif
ifneq (, $(filter esp_spiffs, $(USEMODULE))) ifneq (, $(filter esp_spiffs, $(USEMODULE)))
...@@ -10,6 +18,13 @@ ifneq (, $(filter esp_spiffs, $(USEMODULE))) ...@@ -10,6 +18,13 @@ ifneq (, $(filter esp_spiffs, $(USEMODULE)))
USEMODULE += vfs USEMODULE += vfs
endif endif
ifneq (, $(filter esp_wifi, $(USEMODULE)))
CFLAGS += -DLWIP_OPEN_SRC
INCLUDES += -I$(ESP8266_SDK_DIR)/third_party/include
LINKFLAGS += -Wl,-wrap=ethernet_input
USEMODULE += netdev_eth
endif
ifneq (, $(filter lua, $(USEPKG))) ifneq (, $(filter lua, $(USEPKG)))
USEMODULE += newlib_syscalls_default USEMODULE += newlib_syscalls_default
USEMODULE += xtimer USEMODULE += xtimer
......
...@@ -33,6 +33,12 @@ ifneq (, $(filter esp_sw_timer, $(USEMODULE))) ...@@ -33,6 +33,12 @@ ifneq (, $(filter esp_sw_timer, $(USEMODULE)))
USEMODULE += esp_sdk USEMODULE += esp_sdk
endif endif
ifneq (, $(filter esp_now esp_wifi, $(USEMODULE)))
$(eval GNRC_NETIF_NUMOF=$(shell echo $$(($(GNRC_NETIF_NUMOF)+1))))
USEMODULE += esp_sdk
USEMODULE += netopt
endif
ifneq (, $(filter esp_gdbstub, $(USEMODULE))) ifneq (, $(filter esp_gdbstub, $(USEMODULE)))
USEMODULE += esp_gdb USEMODULE += esp_gdb
endif endif
......
...@@ -27,14 +27,17 @@ ...@@ -27,14 +27,17 @@
6. [Timers](#esp8266_timers) 6. [Timers](#esp8266_timers)
7. [SPIFFS Device](#esp8266_spiffs_device) 7. [SPIFFS Device](#esp8266_spiffs_device)
8. [Other Peripherals](#esp8266_other_peripherals) 8. [Other Peripherals](#esp8266_other_peripherals)
6. [Preconfigured Devices](#esp8266_preconfigured_devices) 6. [Network Interfaces](#esp8266_network_interfaces)
1. [WiFi Network Interface](#esp8266_wifi_network_interface)
2. [ESP-NOW Network Interface](#esp8266_esp_now_network_interface)
7. [Preconfigured Devices](#esp8266_preconfigured_devices)
1. [Network Devices](#esp8266_network_devices) 1. [Network Devices](#esp8266_network_devices)
2. [SD-Card Device](#esp8266_sd_card_device) 2. [SD-Card Device](#esp8266_sd_card_device)
7. [Application-Specific Configurations](#esp8266_application_specific_configurations) 8. [Application-Specific Configurations](#esp8266_application_specific_configurations)
1. [Application-Specific Board Configuration](#esp8266_application_specific_board_configuration) 1. [Application-Specific Board Configuration](#esp8266_application_specific_board_configuration)
2. [Application-Specific Driver Configuration](#esp8266_application_specific_driver_configuration) 2. [Application-Specific Driver Configuration](#esp8266_application_specific_driver_configuration)
8. [SDK Task Handling](#esp8266_sdk_task_handling) 9. [SDK Task Handling](#esp8266_sdk_task_handling)
9. [QEMU Mode and GDB](#esp8266_qemu_mode_and_gdb) 10. [QEMU Mode and GDB](#esp8266_qemu_mode_and_gdb)
# <a name="esp8266_overview"> Overview </a> &nbsp;&nbsp; [[TOC](#esp8266_toc)] # <a name="esp8266_overview"> Overview </a> &nbsp;&nbsp; [[TOC](#esp8266_toc)]
...@@ -353,9 +356,11 @@ Optional features of ESP8266 can be enabled by ```USEMODULE``` definitions in th ...@@ -353,9 +356,11 @@ Optional features of ESP8266 can be enabled by ```USEMODULE``` definitions in th
Module | Description Module | Description
-------|------------ -------|------------
[esp_gdb](#esp8266_qemu_mode_and_gdb) | Enable the compilation with debug information, which is equivalent to using ```ENABLE_GDB=1``` [esp_gdb](#esp8266_qemu_mode_and_gdb) | Enable the compilation with debug information, which is equivalent to using ```ENABLE_GDB=1```
[esp_now](#esp8266_esp_now_network_interface) | Enable the built-in WiFi module with the ESP-NOW protocol as `netdev` network device
[esp_sdk](#esp8266_sdk_task_handling) | Enable the SDK version, which is equivalent to using ```USE_SDK=1``` [esp_sdk](#esp8266_sdk_task_handling) | Enable the SDK version, which is equivalent to using ```USE_SDK=1```
[esp_spiffs](#esp8266_spiffs_device) | Enable the SPIFFS drive in on-board flash memory [esp_spiffs](#esp8266_spiffs_device) | Enable the SPIFFS drive in on-board flash memory
[esp_sw_timer](#esp8266_timers) | Enable software timer implementation, implies the setting ```USE_SDK=1``` (module ```esp_sdk```) [esp_sw_timer](#esp8266_timers) | Enable software timer implementation, implies the setting ```USE_SDK=1``` (module ```esp_sdk```)
[esp_wifi](#esp8266_wifi_network_interface) | Use the built-in WiFi module as `netdev` network device
</center><br> </center><br>
...@@ -563,6 +568,104 @@ The ESP8266 port of RIOT also supports ...@@ -563,6 +568,104 @@ The ESP8266 port of RIOT also supports
RTC is not yet implemented. RTC is not yet implemented.
# <a name="esp8266_network_interfaces"> Network Interfaces </a> &nbsp;[[TOC](#esp8266_toc)]
ESP8266 provides different built-in possibilities to realize network devices:
- <b>ESP WiFi</b>, usual AP-based wireless LAN (not yet supported)
- <b>ESP-NOW</b>, a WiFi based AP-less and connectionless peer to peer communication protocol
\anchor esp8266_wifi_network_interface
## <a name="esp8266_wifi_network_interface"> WiFi Network Interface </a> &nbsp;[[TOC](#esp8266_toc)]
The RIOT port for ESP8266 implements in module `esp_wifi` a `netdev` driver for
the built-in WiFi interface.
@note Due to symbol conflicts with the `crypto` and `hash` modules of RIOT
in vendor library `libwpa.so`, which is required by module
`esp_wifi`, `esp_wifi` cannot be used for applications that use these modules.
Therefore, module `esp_wifi` is not automatically enabled when module
`netdev_default` is used. Instead, if necessary, the application has to add
the module `esp_wifi` in the Makefile.
```
USEMODULE += esp_wifi
```
Furthermore, the following configuration parameters have to be defined:
<center>
Parameter | Default | Description
:------------------|:--------------------------|:------------
ESP_WIFI_SSID | "RIOT_AP" | SSID of the AP to be used.
ESP_WIFI_PASS | "ThisistheRIOTporttoESP" | Passphrase used for the AP as clear text (max. 64 chars).
ESP_WIFI_STACKSIZE | #THREAD_STACKSIZE_DEFAULT |Stack size used for the WiFi netdev driver thread.
</center>
These configuration parameter definitions, as well as enabling the `esp_wifi`
module, can be done either in the makefile of the project or at make command
line, e.g.:
```
USEMODULE=esp_wifi \
CFLAGS='-DESP_WIFI_SSID=\"MySSID\" -DESP_WIFI_PASS=\"MyPassphrase\"' \
make -C examples/gnrc_networking BOARD=...
```
@note The Wifi network interface (module `esp_wifi`) and the
[ESP-NOW network interface](#esp8266_esp_now_network_interface)
(module `esp_now`) can be used simultaneously, for example, to realize a
border router for a mesh network which uses ESP-NOW.
\anchor esp8266_esp_now_network_interface
## <a name="esp8266_esp_now_network_interface"> ESP-NOW Network Interface </a> &nbsp;[[TOC](#esp8266_toc)]
With ESP-NOW, the ESP8266 provides a connectionless communication technology,
featuring short packet transmission. It applies the IEEE802.11 Action Vendor
frame technology, along with the IE function developed by Espressif, and CCMP
encryption technology, realizing a secure, connectionless communication solution.
The RIOT port for ESP8266 implements in module `esp_now` a `netdev` driver
which uses ESP-NOW to provide a link layer interface to a meshed network of
ESP8266 nodes. In this network, each node can send short packets with up to
250 data bytes to all other nodes that are visible in its range.
@note Due to symbol conflicts in vendor library `libwpa.so` used by the
`esp_now` with RIOT's `crypto` and `hashes` modules, ESP-NOW cannot be used
for application that use these modules. Therefore, the module `esp_now` is
not enabled automatically if the `netdev_default` module is used. Instead,
the application has to add the `esp_now` module in its makefile when needed.<br>
```
USEMODULE += esp_now
```
For ESP-NOW, ESP8266 nodes are used in WiFi SoftAP + Station mode to advertise
their SSID and become visible to other ESP8266 nodes. The SSID of an ESP8266
node is the concatenation of the prefix `RIOT_ESP_` with the MAC address of
its SoftAP WiFi interface. The driver periodically scans all visible ESP8266
nodes.
The following parameters are defined for ESP-NOW nodes. These parameters can
be overriden by [application-specific board configurations](#esp8266_application_specific_board_configuration).
<center>
Parameter | Default | Description
:---------|:--------|:-----------
ESP_NOW_SCAN_PERIOD | 10000000UL | Defines the period in us at which an node scans for other nodes in its range. The default period is 10 s.
ESP_NOW_SOFT_AP_PASS | "ThisistheRIOTporttoESP" | Defines the passphrase as clear text (max. 64 chars) that is used for the SoftAP interface of ESP-NOW nodes. It has to be same for all nodes in one network.
ESP_NOW_CHANNEL | 6 | Defines the channel that is used as the broadcast medium by all nodes together.
ESP_NOW_KEY | NULL | Defines a key that is used for encrypted communication between nodes. If it is NULL, encryption is disabled. The key has to be of type ```uint8_t[16]``` and has to be exactly 16 bytes long.
</center>
@note The ESP-NOW network interface (module `esp_now`) and the
[Wifi network interface](#esp8266_wifi_network_interface) (module `esp_wifi`)
can be used simultaneously, for example, to realize a border router for
a mesh network which uses ESP-NOW.
# <a name="esp8266_preconfigured_devices"> Preconfigured Devices </a> &nbsp;[[TOC](#esp8266_toc)] # <a name="esp8266_preconfigured_devices"> Preconfigured Devices </a> &nbsp;[[TOC](#esp8266_toc)]
The ESP8266 port of RIOT has been tested with several common external devices that can be connected to ESP8266 boards and are preconfigured accordingly. The ESP8266 port of RIOT has been tested with several common external devices that can be connected to ESP8266 boards and are preconfigured accordingly.
......
MODULE=esp_wifi
include $(RIOTBASE)/Makefile.base
/*
* Copyright (C) 2019 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup cpu_esp8266_esp_wifi ESP8266 WiFi netdev interface
* @ingroup cpu_esp8266
* @brief Network device driver for the ESP8266 WiFi interface
*
* @author Gunar Schorcht <gunar@schorcht.net>
This module realizes a `netdev` interface for the built-in WiFi interface
of ESP8266. To enable the WiFi interface, module `esp_wifi` has to be used.
Furthermore, the following configuration parameters have to be defined:
Configuration Parameter | Description
------------------------|------------
ESP_WIFI_SSID | SSID of the AP to be used.
ESP_WIFI_PASS | Passphrase used for the AP as clear text (max. 64 chars).
ESP_WIFI_STACKSIZE | Stack size used for the WiFi netdev driver thread.
These configuration parameter definitions, as well as enabling the `esp_wifi`
module, can be done either in the makefile of the project or at make command
line, e.g.:
```
USEMODULE=esp_wifi \
CFLAGS='-DESP_WIFI_SSID=\"MySSID\" -DESP_WIFI_PASS=\"MyPassphrase\"' \
make -C examples/gnrc_networking BOARD=...
```
@note The Wifi network interface (module `esp_wifi`) and the
\ref esp32_esp_now_network_interface "ESP-NOW network interface" (module `esp_now`)
can be used simultaneously, for example, to realize a border router for
a mesh network which uses ESP-NOW.
*/
This diff is collapsed.
/*
* Copyright (C) 2019 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup cpu_esp8266_esp_wifi
* @{
*
* @file
* @brief Network device driver for the ESP8266 WiFi interface
*
* @author Gunar Schorcht <gunar@schorcht.net>
*/
#ifndef ESP_WIFI_NETDEV_H
#define ESP_WIFI_NETDEV_H
#include "net/netdev.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief State of the WiFi interface
*/
typedef enum {
ESP_WIFI_NOT_WORKING, /**< interface is not working correctly */
ESP_WIFI_DISCONNECTED, /**< interface is not associated to the AP */
ESP_WIFI_CONNECTING, /**< interface is trying an association to the AP */
ESP_WIFI_CONNECTED /**< interface is not associated to the AP */
} esp_wifi_state_t;
/**
* @brief Device descriptor for ESP infrastructure mode WIFI device
*/
typedef struct
{
netdev_t netdev; /**< netdev parent struct */
uint8_t mac[ETHERNET_ADDR_LEN]; /**< MAC address of the device */
uint8_t rx_buf[ETHERNET_MAX_LEN]; /**< receive buffer */
uint16_t rx_len; /**< number of bytes received from lwIP */
esp_wifi_state_t state; /**< indicates the interface state */
mutex_t dev_lock; /**< for exclusive access to buffer in
receive functions */
} esp_wifi_netdev_t;
#ifdef __cplusplus
}
#endif
#endif /* ESP_WIFI_NETDEV_H */
/** @} */
/*
* Copyright (C) 2019 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup cpu_esp8266_esp_wifi
* @ingroup cpu_esp8266_conf
* @{
*
* @file
* @brief Parameters for the ESP8266 WiFi netdev interface
*
* @author Gunar Schorcht <gunar@schorcht.net>
*/
#ifndef ESP_WIFI_PARAMS_H
#define ESP_WIFI_PARAMS_H
#if MODULE_ESP_WIFI || DOXYGEN
/**
* @name Set default configuration parameters for the ESP WIFI netdev driver
* @{
*/
/**
* @brief The size of the stack used for the ESP WIFI netdev driver thread.
*/
#ifndef ESP_WIFI_STACKSIZE
#define ESP_WIFI_STACKSIZE (1536)
#endif
/**
* @brief The priority of the ESP WiFi netdev driver thread. Should not be changed.
*/
#ifndef ESP_WIFI_PRIO
#define ESP_WIFI_PRIO (GNRC_NETIF_PRIO)
#endif
/**
* @brief SSID of the AP to be used.
*/
#ifndef ESP_WIFI_SSID
#define ESP_WIFI_SSID "RIOT_AP"
#endif
/**
* @brief Passphrase used for the AP (max. 64 chars).
*/
#ifndef ESP_WIFI_PASS
#define ESP_WIFI_PASS "ThisistheRIOTporttoESP"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* MODULE_ESP_WIFI || DOXYGEN */
#endif /* ESP_WIFI_PARAMS_H */
/**@}*/
...@@ -47,6 +47,9 @@ extern "C" { ...@@ -47,6 +47,9 @@ extern "C" {
#define THREAD_STACKSIZE_MAIN (3072) #define THREAD_STACKSIZE_MAIN (3072)
#endif #endif
#ifndef GNRC_IPV6_STACK_SIZE
#define GNRC_IPV6_STACK_SIZE (1536)
#endif
#ifndef GNRC_PKTDUMP_STACKSIZE #ifndef GNRC_PKTDUMP_STACKSIZE
#define GNRC_PKTDUMP_STACKSIZE (THREAD_STACKSIZE_DEFAULT) #define GNRC_PKTDUMP_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
#endif #endif
...@@ -74,6 +77,9 @@ extern "C" { ...@@ -74,6 +77,9 @@ extern "C" {
#define THREAD_STACKSIZE_MAIN (3072) #define THREAD_STACKSIZE_MAIN (3072)
#endif #endif
#ifndef GNRC_IPV6_STACK_SIZE
#define GNRC_IPV6_STACK_SIZE (1536)
#endif
#ifndef GNRC_PKTDUMP_STACKSIZE #ifndef GNRC_PKTDUMP_STACKSIZE
#define GNRC_PKTDUMP_STACKSIZE (THREAD_STACKSIZE_DEFAULT) #define GNRC_PKTDUMP_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
#endif #endif
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <sys/reent.h> #include <sys/reent.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <malloc.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -87,13 +88,13 @@ int /* IRAM */ printf(const char* format, ...) ...@@ -87,13 +88,13 @@ int /* IRAM */ printf(const char* format, ...)
return ret; return ret;
} }
#ifdef SDK_HEAP_USED #ifdef MODULE_ESP_SDK
/** /**
* Map memory management functions to SDK memory management functions. * Map memory management functions to SDK memory management functions.
* This is necessary to use the same heap as the SDK internally does. * This is necessary to use the same heap as the SDK internally does.
* Furthermore, these functions do at least avoid interrupts during the * Furthermore, these functions at least avoid interrupts during the
* execution of memory management functions. Memory management function * execution of memory management functions. Memory management functions
* of ETS are not used and have not to considered therefore. * of ETS are not used and have not to be considered therefore.
*/ */
extern void *pvPortMalloc (size_t size, const char *, unsigned); extern void *pvPortMalloc (size_t size, const char *, unsigned);
extern void vPortFree (void *ptr, const char *, unsigned); extern void vPortFree (void *ptr, const char *, unsigned);
...@@ -102,7 +103,16 @@ extern void *pvPortCalloc (size_t nmemb, size_t size, const char *, unsigned); ...@@ -102,7 +103,16 @@ extern void *pvPortCalloc (size_t nmemb, size_t size, const char *, unsigned);
extern void *pvPortRealloc (void *ptr, size_t size, const char *, unsigned); extern void *pvPortRealloc (void *ptr, size_t size, const char *, unsigned);
extern unsigned int xPortGetFreeHeapSize(void); extern unsigned int xPortGetFreeHeapSize(void);
void* IRAM malloc(size_t size) void *__real_malloc(size_t size);
void __real_free(void *ptr);
void *__real_calloc(size_t nmemb, size_t size);
void *__real_realloc(void *ptr, size_t size);
void *__real__malloc_r (struct _reent *r, size_t size);
void __real__free_r (struct _reent *r, void *ptr);
void *__real__realloc_r (struct _reent *r, void *ptr, size_t size);
struct mallinfo __real_mallinfo(void);
void* IRAM __wrap_malloc(size_t size)
{ {
#if MEMLEAK_DEBUG #if MEMLEAK_DEBUG
static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__;
...@@ -112,7 +122,7 @@ void* IRAM malloc(size_t size) ...@@ -112,7 +122,7 @@ void* IRAM malloc(size_t size)
#endif #endif
} }
void IRAM free(void *ptr) void IRAM __wrap_free(void *ptr)
{ {
#if MEMLEAK_DEBUG #if MEMLEAK_DEBUG
static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__;
...@@ -122,7 +132,7 @@ void IRAM free(void *ptr) ...@@ -122,7 +132,7 @@ void IRAM free(void *ptr)
#endif #endif
} }
void* IRAM calloc(size_t nmemb, size_t size) void* IRAM __wrap_calloc(size_t nmemb, size_t size)
{ {
#if MEMLEAK_DEBUG #if MEMLEAK_DEBUG
static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__;
...@@ -132,7 +142,7 @@ void* IRAM calloc(size_t nmemb, size_t size) ...@@ -132,7 +142,7 @@ void* IRAM calloc(size_t nmemb, size_t size)
#endif #endif
} }
void* IRAM realloc(void *ptr, size_t size) void* IRAM __wrap_realloc(void *ptr, size_t size)
{ {
#if MEMLEAK_DEBUG #if MEMLEAK_DEBUG
static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__;
...@@ -142,14 +152,19 @@ void* IRAM realloc(void *ptr, size_t size) ...@@ -142,14 +152,19 @@ void* IRAM realloc(void *ptr, size_t size)
#endif #endif
} }
void* IRAM _malloc_r (struct _reent *r, size_t size) void* IRAM __wrap__malloc_r (struct _reent *r, size_t size)
{ {
return malloc (size); return __wrap_malloc (size);
} }
void IRAM _free_r (struct _reent *r, void *ptr) void IRAM __wrap__free_r (struct _reent *r, void *ptr)
{ {
free (ptr); __wrap_free (ptr);
}
void IRAM *__wrap__realloc_r (struct _reent *r, void *ptr, size_t size)
{
return __wrap_realloc (ptr, size);
} }
unsigned int get_free_heap_size (void) unsigned int get_free_heap_size (void)
...@@ -157,14 +172,37 @@ unsigned int get_free_heap_size (void) ...@@ -157,14 +172,37 @@ unsigned int get_free_heap_size (void)
return xPortGetFreeHeapSize(); return xPortGetFreeHeapSize();
} }
void IRAM syscalls_init (void) {} extern uint8_t _eheap; /* end of heap (defined in esp8266.riot-os.app.ld) */
extern uint8_t _sheap; /* start of heap (defined in esp8266.riot-os.app.ld) */
struct mallinfo __wrap_mallinfo(void)
{
struct mallinfo mi;
mi.arena = &_eheap - &_sheap;
mi.fordblks = get_free_heap_size();
mi.uordblks = mi.arena - mi.fordblks;
mi.keepcost = mi.fordblks;
return mi;
}
void heap_stats(void)
{
struct mallinfo minfo = __wrap_mallinfo();
ets_printf("heap: %d (used %d, free %d)\n",
minfo.arena, minfo.uordblks, minfo.fordblks);
}
void IRAM syscalls_init (void)
{
}
#else /* SDK_HEAP_USED */ #else /* MODULE_ESP_SDK */
/* /*
* To use the same heap SDK memory management functions have to be replaced by * To use the same heap as SDK internally does, SDK memory management
* newlib memory functions. In that case the _malloc_lock/_unlock functions * functions have to be replaced by newlib memory functions. In that case,
* have to be defined. Memory management functions of ETS are not used and * the _malloc_lock/_unlock functions have to be defined. Memory management
* have not to considered here. * functions of ETS are not used and have not to be considered here.
*/ */
void* IRAM pvPortMalloc (size_t size, const char *file, unsigned line) void* IRAM pvPortMalloc (size_t size, const char *file, unsigned line)
...@@ -227,9 +265,11 @@ size_t IRAM xPortGetFreeHeapSize (void) ...@@ -227,9 +265,11 @@ size_t IRAM xPortGetFreeHeapSize (void)
} }
/* /*
* Following function implement the lock mechanism in newlib. The only static * Following functions implement the lock mechanism in newlib. The only static
* mutex defined here is the __malloc_recursive_mutex to avoid that memory * mutex defined here is the __malloc_recursive_mutex to avoid that memory
* management functions try to lock before RIOT's threads are running. * management functions try to lock before RIOT's threads are running.
* These lock/unlock functions cannot be used in the SDK version since some ISR
* in SDK use malloc/free which does not work in interrupt context.
*/ */
extern _lock_t __malloc_recursive_mutex; extern _lock_t __malloc_recursive_mutex;
...@@ -342,6 +382,7 @@ void IRAM _lock_release_recursive(_lock_t *lock) ...@@ -342,6 +382,7 @@ void IRAM _lock_release_recursive(_lock_t *lock)
extern char *heap_top; extern char *heap_top;
extern char _eheap; /* end of heap (defined in esp8266.riot-os.app.ld) */ extern char _eheap; /* end of heap (defined in esp8266.riot-os.app.ld) */
extern char _sheap; /* start of heap (defined in esp8266.riot-os.app.ld) */
#else /* MODULE_NEWLIB_SYSCALLS_DEFAULT */ #else /* MODULE_NEWLIB_SYSCALLS_DEFAULT */
...@@ -380,8 +421,6 @@ void* IRAM _sbrk_r (struct _reent *r, ptrdiff_t incr) ...@@ -380,8 +421,6 @@ void* IRAM _sbrk_r (struct _reent *r, ptrdiff_t incr)
return (void*) _cheap_old; return (void*) _cheap_old;
} }
#endif /* MODULE_NEWLIB_SYSCALLS_DEFAULT */ #endif /* MODULE_NEWLIB_SYSCALLS_DEFAULT */
unsigned int IRAM get_free_heap_size (void) unsigned int IRAM get_free_heap_size (void)
...@@ -389,7 +428,15 @@ unsigned int IRAM get_free_heap_size (void) ...@@ -389,7 +428,15 @@ unsigned int IRAM get_free_heap_size (void)
return (_cheap) ? &_eheap - _cheap : 0; return (_cheap) ? &_eheap - _cheap : 0;
} }
#endif /* SDK_HEAP_USED */ void heap_stats(void)
{
struct mallinfo minfo = mallinfo();
ets_printf("heap: %u (free %u), ", &_eheap - &_sheap, get_free_heap_size());
ets_printf("sysmem: %d (used %d, free %d)\n",
minfo.arena, minfo.uordblks, minfo.fordblks);
}
#endif /* MODULE_ESP_SDK */
#if !defined(MODULE_NEWLIB_SYSCALLS_DEFAULT) #if !defined(MODULE_NEWLIB_SYSCALLS_DEFAULT)
......
This diff is collapsed.
...@@ -3,6 +3,7 @@ include ../Makefile.tests_common ...@@ -3,6 +3,7 @@ include ../Makefile.tests_common
# lwIP's memory management doesn't seem to work on non 32-bit platforms at the # lwIP's memory management doesn't seem to work on non 32-bit platforms at the
# moment. # moment.
BOARD_BLACKLIST := arduino-uno arduino-duemilanove arduino-mega2560 chronos \ BOARD_BLACKLIST := arduino-uno arduino-duemilanove arduino-mega2560 chronos \
esp8266-esp-12x esp8266-olimex-mod esp8266-sparkfun-thing \
msb-430 msb-430h telosb waspmote-pro wsn430-v1_3b \ msb-430 msb-430h telosb waspmote-pro wsn430-v1_3b \
wsn430-v1_4 z1 jiminy-mega256rfr2 mega-xplained wsn430-v1_4 z1 jiminy-mega256rfr2 mega-xplained
BOARD_INSUFFICIENT_MEMORY := airfy-beacon hifive1 nrf6310 nucleo-f031k6 nucleo-f042k6 \ BOARD_INSUFFICIENT_MEMORY := airfy-beacon hifive1 nrf6310 nucleo-f031k6 nucleo-f042k6 \
......
...@@ -3,6 +3,7 @@ include ../Makefile.tests_common ...@@ -3,6 +3,7 @@ include ../Makefile.tests_common
# lwIP's memory management doesn't seem to work on non 32-bit platforms at the # lwIP's memory management doesn't seem to work on non 32-bit platforms at the
# moment. # moment.
BOARD_BLACKLIST := arduino-uno arduino-duemilanove arduino-mega2560 chronos \ BOARD_BLACKLIST := arduino-uno arduino-duemilanove arduino-mega2560 chronos \
esp8266-esp-12x esp8266-olimex-mod esp8266-sparkfun-thing \
msb-430 msb-430h telosb waspmote-pro wsn430-v1_3b \ msb-430 msb-430h telosb waspmote-pro wsn430-v1_3b \
wsn430-v1_4 z1 jiminy-mega256rfr2 mega-xplained wsn430-v1_4 z1 jiminy-mega256rfr2 mega-xplained
BOARD_INSUFFICIENT_MEMORY = nucleo-f031k6 nucleo-f042k6 nucleo-l031k6 nucleo-f030r8 \ BOARD_INSUFFICIENT_MEMORY = nucleo-f031k6 nucleo-f042k6 nucleo-l031k6 nucleo-f030r8 \
......
...@@ -3,6 +3,7 @@ include ../Makefile.tests_common ...@@ -3,6 +3,7 @@ include ../Makefile.tests_common
# lwIP's memory management doesn't seem to work on non 32-bit platforms at the # lwIP's memory management doesn't seem to work on non 32-bit platforms at the
# moment. # moment.
BOARD_BLACKLIST := arduino-uno arduino-duemilanove arduino-mega2560 chronos \ BOARD_BLACKLIST := arduino-uno arduino-duemilanove arduino-mega2560 chronos \
esp8266-esp-12x esp8266-olimex-mod esp8266-sparkfun-thing \
msb-430 msb-430h telosb waspmote-pro wsn430-v1_3b \ msb-430 msb-430h telosb waspmote-pro wsn430-v1_3b \
wsn430-v1_4 z1 jiminy-mega256rfr2 mega-xplained wsn430-v1_4 z1 jiminy-mega256rfr2 mega-xplained
BOARD_INSUFFICIENT_MEMORY = blackpill bluepill nucleo-f031k6 nucleo-f042k6 \ BOARD_INSUFFICIENT_MEMORY = blackpill bluepill nucleo-f031k6 nucleo-f042k6 \
......
...@@ -3,6 +3,7 @@ include ../Makefile.tests_common ...@@ -3,6 +3,7 @@ include ../Makefile.tests_common
# lwIP's memory management doesn't seem to work on non 32-bit platforms at the # lwIP's memory management doesn't seem to work on non 32-bit platforms at the
# moment. # moment.
BOARD_BLACKLIST := arduino-uno arduino-duemilanove arduino-mega2560 chronos \ BOARD_BLACKLIST := arduino-uno arduino-duemilanove arduino-mega2560 chronos \
esp8266-esp-12x esp8266-olimex-mod esp8266-sparkfun-thing \
msb-430 msb-430h telosb waspmote-pro wsn430-v1_3b \ msb-430 msb-430h telosb waspmote-pro wsn430-v1_3b \
wsn430-v1_4 z1 jiminy-mega256rfr2 mega-xplained wsn430-v1_4 z1 jiminy-mega256rfr2 mega-xplained
BOARD_INSUFFICIENT_MEMORY = nucleo-f031k6 nucleo-f042k6 nucleo-l031k6 nucleo-f030r8 \ BOARD_INSUFFICIENT_MEMORY = nucleo-f031k6 nucleo-f042k6 nucleo-l031k6 nucleo-f030r8 \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment