Ivan Grokhotkov [Mon, 12 Jun 2017 11:51:17 +0000 (19:51 +0800)]
esp32: make time monotonic across resets
Small changes to clock calibration value will cause increasing errors
the longer the device runs. Consider the case of deep sleep, assuming
that RTC counter is used for timekeeping:
- before sleep:
time_before = rtc_counter * calibration_val
- after sleep:
time_after = (rtc_counter + sleep_count) * (calibration_val + epsilon)
where 'epsilon' is a small estimation error of 'calibration_val'.
The apparent sleep duration thus will be:
time_after - time_before = sleep_count * (calibration_val + epsilon)
+ rtc_counter * epsilon
Second term on the right hand side is the error in time difference
estimation, it is proportional to the total system runtime (rtc_counter).
To avoid this issue, this change makes RTC_SLOW_CLK calibration value
persistent across restarts. This allows the calibration value update to
be preformed, while keeping time after update same as before the update.
wangmengyang [Thu, 15 Jun 2017 07:48:20 +0000 (15:48 +0800)]
component/bt: add constraint in Kconfig to enable SMP_ENABLE when using classic BT
1. For now, some security related functions used in classic Bluetooth are controlled by "SMP_ENABLE". This commit fixes the dependency.
2. The two options, "CLASSIC_BT_ENABLED" and "SMP_ENABLED" The two options will be decoupled in the future.
Ivan Grokhotkov [Thu, 15 Jun 2017 10:11:58 +0000 (18:11 +0800)]
libsodium: don’t link tests when TEST_ALL=1 is used
Currently libsodium tests add about 800kB to the binary, which is too
much for a partition table constrained to 2MB. Disable libsodium tests
until we start building multiple unit test apps for different subsets.
Ivan Grokhotkov [Wed, 14 Jun 2017 10:07:15 +0000 (18:07 +0800)]
esp32: reset APP CPU when doing esp_restart
This fixes a bug introduced by !848, where APP CPU would not be reset
during esp_restart, if esp_restart was called from a task running on APP
CPU, and wouldn’t be reset by PRO CPU on startup.
This change replaces stalling APP CPU with resetting it.
Ivan Grokhotkov [Wed, 14 Jun 2017 10:00:26 +0000 (18:00 +0800)]
esp32: disable DPORT access protection when doing esp_restart
DPORT access protection can not work when the other CPU is stalled.
Writes to DPORT registers in esp_restart caused the program to hang due
to access protection, and the reset happened due to RTC_WDT, not SW_RST.
This change adds esp_dport_access_int_deinit function and calls it from
esp_restart once the other core is stalled.
Ivan Grokhotkov [Wed, 14 Jun 2017 09:56:32 +0000 (17:56 +0800)]
bootloader: workaround for clock switching bug in ESP32 rev. 0
In ESP32 rev. 0, switching between 240MHz and 80MHz (even via an
intermediate frequency of 40MHz) may cause the chip to lock up.
The bootloader used to enable 80MHz CPU clock at startup, which could
cause lock up after software reset. With this change, if 240MHz CPU
clock is enabled in menuconfig, bootloader will also use 240MHz to avoid
lock-up.
island [Sun, 11 Jun 2017 13:59:49 +0000 (21:59 +0800)]
component/bt: Fix bug while writing slave's service change characteristic
- Fix slave initiate service discovery procedure
- Fix master re-discovery every time connection established
- Optimize service discovery char ccc write procedure
- Optimize esp_log_buffer function
- Modify default supervision timeout from 20s to 2s
Angus Gratton [Thu, 8 Jun 2017 05:27:50 +0000 (15:27 +1000)]
panic handler: Print backtraces with calling address not return address
This seems to clean up some of the more wrong addr2line output results (not
sure why, something to do with optimisations I think - perhaps the return
address may also be a jump target from some earlier line of the code.)
Angus Gratton [Thu, 8 Jun 2017 05:21:03 +0000 (15:21 +1000)]
abort handler: Fix abort stack trace when abort() called in ISR
Previously, this resulted in task stack frames turning up incorrectly in the backtrace, ie
Backtrace: 0x400d22a0:0x3ffb0fa0 0x40085a3c:0x3ffb0fc0 0x400f32c4:0x3ffb0fe0 0x40081965:0x3ffb1010
0x400d22a0: esp_vApplicationIdleHook at /home/esp/esp-idf/components/esp32/./freertos_hooks.c:
52
0x40085a3c: prvIdleTask at /home/esp/esp-idf/components/freertos/./tasks.c:4431
0x400f32c4: i2c_isr_handler_default at /home/esp/esp-idf/components/driver/./i2c.c:598
0x40081965: _xt_lowint1 at xtensa_vectors.o:?
Fix is to implement abort() via an unhandled exception rather than a breakpoint, I think
because of relative priority of exception types.
Another approach would be to assign a software-only INUM to abort()ing and defined a
PANIC_RSN_ABORTED, but this is more complex and interrupt numbers are more scarce than RAM!
Ivan Grokhotkov [Fri, 19 May 2017 03:37:16 +0000 (11:37 +0800)]
syscalls: fix wraparound of RTC time
This change removes the erroneous cast to uint32_t (which caused time to
wrap around after 1 hour) and splits the multiplication into two terms
to remove the wraparound after 13 days.
Ivan Grokhotkov [Mon, 12 Jun 2017 07:16:57 +0000 (15:16 +0800)]
esp32: don’t reset APP CPU if it was already reset by OpenOCD
When ‘reset halt’ command is executed, OpenOCD will take the APP CPU
out of reset and enable the clock. At this point, user can set a
breakpoint on code which will run on APP CPU. Previously, app startup
code would do another reset of APP CPU, thereby removing any breakpoints
which may have been set. This change makes APP CPU reset conditional on
DPORT_APPCPU_CLKGATE_EN bit, which is 0 by default but is set to 1 by
OpenOCD after reset.
* Writing >4 bytes to unaligned offsets would fail
* Writiing data from flash would fail (wrong buffer was used)
* Writing >8192 bytes from RAM would over-write data multiple times