Skip to content
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

PoC cache configuration control #7060

Merged
merged 89 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
fc63320
PoC cache configuration control
mhightower83 Feb 4, 2020
57043bd
Style corrections
mhightower83 Feb 4, 2020
17ceceb
Merge branch 'master' into poc-cache-config
mhightower83 Feb 7, 2020
7424aed
Added detailed description for Cache_Read_Enable.
mhightower83 Feb 11, 2020
56306d3
Merge branch 'master' into poc-cache-config
mhightower83 Feb 13, 2020
0645923
Style and MMU_SEC_HEAP corrections.
mhightower83 Feb 13, 2020
a6bb5a1
Improved asm register usage.
mhightower83 Feb 14, 2020
5bb3e19
Merge branch 'master' into poc-cache-config
mhightower83 Feb 27, 2020
b443e43
Interesting glitch in boards.txt after github merge. A new board in
mhightower83 Feb 28, 2020
0c661db
Support for 2nd Heap, excess IRAM, through umm_malloc.
mhightower83 Mar 2, 2020
c6eabc5
Merge branch 'master' into poc-cache-config
mhightower83 Mar 2, 2020
70842de
Post push CI cleanup.
mhightower83 Mar 2, 2020
f35290b
Cleanup part II
mhightower83 Mar 3, 2020
71e36cb
Cleanup part III
mhightower83 Mar 3, 2020
edf008a
Updates to support platformio, maybe.
mhightower83 Mar 5, 2020
161e7bc
Added exception C wrapper replacement.
mhightower83 Mar 5, 2020
5ac46f7
Merge branch 'master' into poc-cache-config
mhightower83 Mar 6, 2020
91fc391
CI Cleanup
mhightower83 Mar 6, 2020
eb9882e
CI Cleanup II
mhightower83 Mar 6, 2020
1422b8d
Changes to exc-c-wrapper-handler.S to assemble under platformio.
mhightower83 Mar 6, 2020
b921e11
For platformio, Correction to toolchain-xtensa include path.
mhightower83 Mar 6, 2020
cfb3826
Temporarily added --print-memory-usage to ld parameters for cross-che…
mhightower83 Mar 6, 2020
a1cd3a2
Merge branch 'master' into poc-cache-config
mhightower83 Mar 17, 2020
352a2ed
Merge branch 'poc-cache-config' of github.com:mhightower83/Arduino in…
mhightower83 Mar 17, 2020
062f8dc
Merge branch 'master' into poc-cache-config
mhightower83 Mar 27, 2020
69fdd5b
Merge branch 'master' into poc-cache-config
mhightower83 Apr 9, 2020
d5dac93
Merge branch 'master' into poc-cache-config
mhightower83 Apr 16, 2020
9d3a7de
Merge branch 'poc-cache-config' of github.com:mhightower83/Arduino in…
mhightower83 Apr 28, 2020
ecd826c
undo change to platform.txt
mhightower83 Apr 28, 2020
a9b92e2
correct merge conflict. take 1
mhightower83 Apr 28, 2020
5a99afc
Merge branch 'master' into poc-cache-config
mhightower83 Apr 28, 2020
f51dd82
Merge branch 'master' into poc-cache-config
mhightower83 Apr 29, 2020
71ef229
Merge branch 'master' into poc-cache-config
mhightower83 May 9, 2020
1a9d909
Fixed #if... for building umm_get_oom_count. It was not building when…
mhightower83 May 10, 2020
7b4a8d4
Commented out XMC support. Compatibility issues with PoC when using 1…
mhightower83 May 17, 2020
d9ab27e
Merge branch 'master' into poc-cache-config
mhightower83 May 17, 2020
6d18190
Corrected size.py, DRAM bracketing changed to not include ICACHE with…
mhightower83 May 25, 2020
50fe8a3
Merge branch 'master' into poc-cache-config
mhightower83 May 25, 2020
f62ff0a
Merge branch 'master' into poc-cache-config
mhightower83 May 31, 2020
1847a72
Merge branch 'master' into poc-cache-config
mhightower83 Jun 14, 2020
d3ace64
Added additional _context for support of use of UMM_INLINE_METRICS.
mhightower83 Jun 19, 2020
a43a2a8
Merge branch 'master' into poc-cache-config
mhightower83 Jun 19, 2020
2f47516
Merge branch 'master' into poc-cache-config
mhightower83 Jul 5, 2020
fd8f942
Merge branch 'master' into poc-cache-config
mhightower83 Jul 7, 2020
74df810
Changes to clear errors and warnings from toolchain 10.1
mhightower83 Jul 13, 2020
b767a5d
Isolated incompatable definitions related to _xtos_set_exception_hand…
mhightower83 Jul 14, 2020
e7402d8
Update tools/platformio-build.py
mhightower83 Jul 17, 2020
51ea542
Merge branch 'master' into poc-cache-config
mhightower83 Jul 17, 2020
3ff489c
Merge branch 'master' into poc-cache-config
devyte Jul 18, 2020
232dce4
Requested changes
mhightower83 Jul 19, 2020
a3c9e02
Corrected comment. And added missing include.
mhightower83 Jul 23, 2020
fc5f611
Improve comment.
mhightower83 Jul 23, 2020
bbdf166
style and comment correction
mhightower83 Jul 23, 2020
b88d197
Added draft mmu.rst file and updated index.
mhightower83 Jul 23, 2020
b058f17
Updated mmu.rst
mhightower83 Jul 25, 2020
5e31ed5
Add a default MMU_IRAM_SIZE value for a new CI test to pass.
mhightower83 Jul 25, 2020
a4d28e2
CI appeasement
mhightower83 Jul 26, 2020
d45ceb0
CI appeasement with comment correction.
mhightower83 Jul 27, 2020
4831410
Ensure SYS always runs with DRAM Heap selected.
mhightower83 Jul 28, 2020
f64a7d0
Add/move heap stack overflow/underflow check to Esp.cpp where the eve…
mhightower83 Jul 28, 2020
2238535
Improved comment clarity of purpose for IramReserve.ino. Clean up MMU…
mhightower83 Jul 30, 2020
c070657
Added missing #include
mhightower83 Aug 4, 2020
be71429
Corrected usage of warning
mhightower83 Aug 4, 2020
50ea394
Merge branch 'master' into poc-cache-config
mhightower83 Aug 7, 2020
4d7e1e9
Merge branch 'poc-cache-config' of github.com:mhightower83/Arduino in…
mhightower83 Aug 7, 2020
61afce0
CI appeasement and use #message not #pragma message
mhightower83 Aug 7, 2020
d828d76
Merge branch 'master' into poc-cache-config
mhightower83 Sep 2, 2020
7d4a600
Updated git version of eboot.elf to match build version.
mhightower83 Sep 2, 2020
20d39ee
Merge branch 'master' into poc-cache-config
mhightower83 Sep 4, 2020
f33ed95
Merge branch 'master' into poc-cache-config
mhightower83 Sep 17, 2020
53894c7
Merge branch 'master' into poc-cache-config
mhightower83 Oct 2, 2020
5ee2136
Merge branch 'master' into poc-cache-config
devyte Oct 5, 2020
3f415f8
Remove conditional build option USE_ISR_SAFE_EXC_WRAPPER, always inst…
mhightower83 Oct 6, 2020
addb149
Merge branch 'master' into poc-cache-config
mhightower83 Oct 6, 2020
d7fb4ab
Updated mmu.rst
mhightower83 Oct 6, 2020
c8412a8
Merge branch 'master' into poc-cache-config
mhightower83 Oct 7, 2020
5786ec1
Merge branch 'master' into poc-cache-config
mhightower83 Oct 18, 2020
86c4e5a
Merge branch 'master' into poc-cache-config
mhightower83 Oct 22, 2020
0c9ae16
Merge branch 'master' into poc-cache-config
mhightower83 Oct 23, 2020
2f88e7b
Merge branch 'master' into poc-cache-config
mhightower83 Oct 28, 2020
6c324c1
Merge branch 'master' into poc-cache-config
mhightower83 Nov 11, 2020
929e79b
Merge branch 'master' into poc-cache-config
mhightower83 Nov 19, 2020
1875c73
Merge branch 'master' into poc-cache-config
mhightower83 Nov 20, 2020
d3f9a0a
Expanded and clarified comments.
mhightower83 Dec 1, 2020
e48d95e
Style fixes and more cleanup
mhightower83 Dec 2, 2020
3ab791b
Merge branch 'master' into poc-cache-config
mhightower83 Dec 2, 2020
a3bf35c
Style fix
mhightower83 Dec 2, 2020
1ff2aef
Remove unnessasary IRAM_ATTR from install_non32xfer_exception_handler
mhightower83 Dec 5, 2020
9f9e206
Merge branch 'master' into poc-cache-config
devyte Dec 6, 2020
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
410 changes: 410 additions & 0 deletions boards.txt

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion bootloaders/eboot/eboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ int load_app_from_flash_raw(const uint32_t flash_addr)
load = true;
}

if (address >= 0x40100000 && address < 0x40108000) {
// The final IRAM size, once boot has completed, can be either 32K or 48K.
// Allow for the higher in range testing.
if (address >= 0x40100000 && address < 0x4010C000) {
devyte marked this conversation as resolved.
Show resolved Hide resolved
load = true;
}

Expand Down
Binary file modified bootloaders/eboot/eboot.elf
Binary file not shown.
4 changes: 4 additions & 0 deletions cores/esp8266/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ void optimistic_yield(uint32_t interval_us);
#include <cstdlib>
#include <cmath>


#include "mmu_iram.h"


using std::min;
using std::max;
using std::round;
Expand Down
19 changes: 7 additions & 12 deletions cores/esp8266/Esp-frag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ void EspClass::getHeapStats(uint32_t* hfree, uint16_t* hmax, uint8_t* hfrag)
// 100 * (1 - sqrt(sum(hole-size²)) / sum(hole-size))

umm_info(NULL, false);
uint8_t block_size = umm_block_size();

uint32_t free_size = umm_free_heap_size_core(umm_get_current_heap());
if (hfree)
*hfree = ummHeapInfo.freeBlocks * block_size;
*hfree = free_size;
if (hmax)
*hmax = (uint16_t)ummHeapInfo.maxFreeContiguousBlocks * block_size;
*hmax = (uint16_t)umm_max_block_size_core(umm_get_current_heap());
if (hfrag) {
if (ummHeapInfo.freeBlocks) {
*hfrag = 100 - (sqrt32(ummHeapInfo.freeBlocksSquared) * 100) / ummHeapInfo.freeBlocks;
if (free_size) {
*hfrag = umm_fragmentation_metric_core(umm_get_current_heap());
} else {
*hfrag = 0;
}
Expand All @@ -46,11 +47,5 @@ void EspClass::getHeapStats(uint32_t* hfree, uint16_t* hmax, uint8_t* hfrag)

uint8_t EspClass::getHeapFragmentation()
{
#ifdef UMM_INLINE_METRICS
return (uint8_t)umm_fragmentation_metric();
#else
uint8_t hfrag;
getHeapStats(nullptr, nullptr, &hfrag);
return hfrag;
#endif
return (uint8_t)umm_fragmentation_metric();
}
76 changes: 66 additions & 10 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "cont.h"

#include "coredecls.h"
#include "umm_malloc/umm_malloc.h"
// #include "core_esp8266_vm.h"
#include <pgmspace.h>

extern "C" {
Expand Down Expand Up @@ -516,45 +518,45 @@ uint8_t *EspClass::random(uint8_t *resultArray, const size_t outputSizeBytes) co
{
/**
* The ESP32 Technical Reference Manual v4.1 chapter 24 has the following to say about random number generation (no information found for ESP8266):
*
*
* "When used correctly, every 32-bit value the system reads from the RNG_DATA_REG register of the random number generator is a true random number.
* These true random numbers are generated based on the noise in the Wi-Fi/BT RF system.
* When Wi-Fi and BT are disabled, the random number generator will give out pseudo-random numbers.
*
*
* When Wi-Fi or BT is enabled, the random number generator is fed two bits of entropy every APB clock cycle (normally 80 MHz).
* Thus, for the maximum amount of entropy, it is advisable to read the random register at a maximum rate of 5 MHz.
* A data sample of 2 GB, read from the random number generator with Wi-Fi enabled and the random register read at 5 MHz,
* has been tested using the Dieharder Random Number Testsuite (version 3.31.1).
* The sample passed all tests."
*
*
* Since ESP32 is the sequal to ESP8266 it is unlikely that the ESP8266 is able to generate random numbers more quickly than 5 MHz when run at a 80 MHz frequency.
* A maximum random number frequency of 0.5 MHz is used here to leave some margin for possibly inferior components in the ESP8266.
* It should be noted that the ESP8266 has no Bluetooth functionality, so turning the WiFi off is likely to cause RANDOM_REG32 to use pseudo-random numbers.
*
* It is possible that yield() must be called on the ESP8266 to properly feed the hardware random number generator new bits, since there is only one processor core available.
*
* It is possible that yield() must be called on the ESP8266 to properly feed the hardware random number generator new bits, since there is only one processor core available.
* However, no feeding requirements are mentioned in the ESP32 documentation, and using yield() could possibly cause extended delays during number generation.
* Thus only delayMicroseconds() is used below.
*/
*/

constexpr uint8_t cooldownMicros = 2;
static uint32_t lastCalledMicros = micros() - cooldownMicros;

uint32_t randomNumber = 0;

for(size_t byteIndex = 0; byteIndex < outputSizeBytes; ++byteIndex)
{
if(byteIndex % 4 == 0)
{
// Old random number has been used up (random number could be exactly 0, so we can't check for that)

uint32_t timeSinceLastCall = micros() - lastCalledMicros;
if(timeSinceLastCall < cooldownMicros)
delayMicroseconds(cooldownMicros - timeSinceLastCall);

randomNumber = RANDOM_REG32;
lastCalledMicros = micros();
}

resultArray[byteIndex] = randomNumber;
randomNumber >>= 8;
}
Expand Down Expand Up @@ -969,3 +971,57 @@ String EspClass::getSketchMD5()
result = md5.toString();
return result;
}

void EspClass::enableVM()
{
#ifdef UMM_HEAP_EXTERNAL
if (!vmEnabled)
install_vm_exception_handler();
vmEnabled = true;
#endif
}

void EspClass::setExternalHeap()
{
#ifdef UMM_HEAP_EXTERNAL
if (vmEnabled)
umm_push_heap(UMM_HEAP_EXTERNAL);
#endif
}

void EspClass::setIramHeap()
{
#ifdef UMM_HEAP_IRAM
umm_push_heap(UMM_HEAP_IRAM);
#endif
}

void EspClass::setDramHeap()
{
#if defined(UMM_HEAP_EXTERNAL) && !defined(UMM_HEAP_IRAM)
if (vmEnabled) {
if (!umm_push_heap(UMM_HEAP_DRAM)) {
panic();
}
}
#elif defined(UMM_HEAP_IRAM)
if (!umm_push_heap(UMM_HEAP_DRAM)) {
panic();
}
#endif
}

void EspClass::resetHeap()
{
#if defined(UMM_HEAP_EXTERNAL) && !defined(UMM_HEAP_IRAM)
if (vmEnabled) {
if (!umm_pop_heap()) {
panic();
}
}
#elif defined(UMM_HEAP_IRAM)
if (!umm_pop_heap()) {
panic();
}
#endif
}
10 changes: 9 additions & 1 deletion cores/esp8266/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class EspClass {
uint8_t getBootMode();

#if defined(F_CPU) || defined(CORE_MOCK)
constexpr
constexpr
#endif
inline uint8_t getCpuFreqMHz() const __attribute__((always_inline))
{
Expand Down Expand Up @@ -215,7 +215,15 @@ class EspClass {
#else
uint32_t getCycleCount();
#endif // !defined(CORE_MOCK)
void enableVM();
void setDramHeap();
void setIramHeap();
void setExternalHeap();
void resetHeap();
private:
#ifdef UMM_HEAP_EXTERNAL
bool vmEnabled = false;
#endif
/**
* @brief Replaces @a byteCount bytes of a 4 byte block on flash
*
Expand Down
9 changes: 9 additions & 0 deletions cores/esp8266/StackThunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "debug.h"
#include "StackThunk.h"
#include <ets_sys.h>
#include <umm_malloc/umm_malloc.h>
#include <umm_malloc/umm_heap_select.h>

extern "C" {

Expand All @@ -48,7 +50,14 @@ void stack_thunk_add_ref()
{
stack_thunk_refcnt++;
if (stack_thunk_refcnt == 1) {
DBG_MMU_PRINTF("\nStackThunk malloc(%u)\n", _stackSize * sizeof(uint32_t));
// The stack must be in DRAM, or an Soft WDT will follow. Not sure why,
// maybe too much time is consumed with the non32-bit exception handler.
// Also, interrupt handling on an IRAM stack would be very slow.
// Strings on the stack would be very slow to access as well.
HeapSelectDram ephemeral;
devyte marked this conversation as resolved.
Show resolved Hide resolved
stack_thunk_ptr = (uint32_t *)malloc(_stackSize * sizeof(uint32_t));
DBG_MMU_PRINTF("StackThunk stack_thunk_ptr: %p\n", stack_thunk_ptr);
if (!stack_thunk_ptr) {
// This is a fatal error, stop the sketch
DEBUGV("Unable to allocate BearSSL stack\n");
Expand Down
22 changes: 21 additions & 1 deletion cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ extern "C" {
#include <core_version.h>
#include "gdb_hooks.h"
#include "flash_quirks.h"
#include <umm_malloc/umm_malloc.h>
#include <core_esp8266_non32xfer.h>


#define LOOP_TASK_PRIORITY 1
#define LOOP_QUEUE_SIZE 1
Expand Down Expand Up @@ -204,7 +207,9 @@ static void loop_wrapper() {
static void loop_task(os_event_t *events) {
(void) events;
s_cycles_at_yield_start = ESP.getCycleCount();
ESP.resetHeap();
cont_run(g_pcont, &loop_wrapper);
ESP.setDramHeap();
if (cont_check(g_pcont) != 0) {
panic();
}
Expand Down Expand Up @@ -256,6 +261,7 @@ void init_done() {
std::set_terminate(__unhandled_exception_cpp);
do_global_ctors();
esp_schedule();
ESP.setDramHeap();
}

/* This is the entry point of the application.
Expand Down Expand Up @@ -311,14 +317,22 @@ extern "C" void app_entry_redefinable(void)
cont_t s_cont __attribute__((aligned(16)));
g_pcont = &s_cont;

#ifdef DEV_DEBUG_MMU_IRAM
DBG_MMU_PRINT_STATUS();

DBG_MMU_PRINT_IRAM_BANK_REG(0, "");

DBG_MMU_PRINTF("\nCall call_user_start()\n");
#endif

/* Call the entry point of the SDK code. */
call_user_start();
}

static void app_entry_custom (void) __attribute__((weakref("app_entry_redefinable")));

extern "C" void app_entry (void)
{
umm_init();
return app_entry_custom();
}

Expand All @@ -342,6 +356,12 @@ extern "C" void user_init(void) {

cont_init(g_pcont);

#if defined(NON32XFER_HANDLER) || defined(MMU_IRAM_HEAP)
install_non32xfer_exception_handler();
#endif
#if defined(MMU_IRAM_HEAP)
umm_init_iram();
#endif
preinit(); // Prior to C++ Dynamic Init (not related to above init() ). Meant to be user redefinable.

ets_task(loop_task,
Expand Down
Loading