Comments (4)
Though a bit of trial and error I discovered that this fixes the problem:
__forceinline void IRAM_ATTR hw_timer1_detach_interrupt(void)
{
hw_timer1_disable();
// ETS_FRC_TIMER1_NMI_INTR_ATTACH(NULL);
ETS_FRC_TIMER1_INTR_ATTACH(NULL, NULL);
}
The ETS_FRC_TIMER1_NMI_INTR_ATTACH
macro calls the SDK function NmiTimSetFunc
. It does two things:
- Sets some bits in a DPORT register.
- Stores the interrupt routine address
Passing a NULL value doesn't actually block interrupts. Espressif's RTOS SDK uses NMI for tick handling and it provides a definition for the relevant register NMI_INT_ENABLE_REG
. To disable NMI interrupts all we need to do is clear that register.
from sming.
Also found a reference to this bug in the SDK "that Timer can not be used with non-NMI interrupt once NMI has been used". esp8266/Arduino#4598 (comment).
from sming.
Here is a modified Basic_Blink
application which I used to test this at a low level.
Note that if the hw_timer1_detach_interrupt
call is removed the LED continues to blink.
However, the rate doesn't change as expected: that means the NMI interrupt is still the active one.
#include <SmingCore.h>
#include <HardwareTimer.h>
/**
* Demonstrate bug switching timer1 from NMI to FRC interrupts.
* The LED will flash 4 times, then stop.
* The 'ALIVE' messages continue to indicate system hasn't actually crashed.
* What happened is that the NMI is still enabled and blocks FRC callbacks.
*/
#define LED_PIN 2
namespace
{
using Timer1TestApi = Timer1Api<TIMER_CLKDIV_16, eHWT_NonMaskable>;
SimpleTimer statusTimer;
bool createMaskedTimer;
const unsigned interval{500};
unsigned ticks;
unsigned count;
void initTimer();
void IRAM_ATTR blink1(void*)
{
digitalWrite(LED_PIN, count & 1);
++count;
if(count % 8 == 0) {
System.queueCallback(initTimer);
}
}
// Blink LED at twice normal rate
void IRAM_ATTR blink2(void*)
{
blink1(nullptr);
hw_timer1_write(ticks / 2);
}
void initTimer()
{
ticks = HardwareTimer::Millis::timeToTicks(interval);
Serial << _F("Initialising timer, source = ") << (createMaskedTimer ? "FRC1" : "NMI") << _F(", Interval = ")
<< interval << _F("ms, ticks = ") << ticks << endl;
auto source = createMaskedTimer ? TIMER_FRC1_SOURCE : TIMER_NMI_SOURCE;
// >>>> This is the call which breaks switching from NMI to FRC
hw_timer1_detach_interrupt();
//<<<<
hw_timer1_attach_interrupt(source, createMaskedTimer ? blink1 : blink2, nullptr);
hw_timer1_enable(TIMER_CLKDIV_16, TIMER_EDGE_INT, true);
hw_timer1_write(ticks);
createMaskedTimer = !createMaskedTimer;
}
} // namespace
void init()
{
Serial.begin(COM_SPEED_SERIAL);
pinMode(LED_PIN, OUTPUT);
statusTimer.initializeMs<1000>([]() { Serial << SystemClock.now() << " ALIVE!" << endl; });
statusTimer.start();
initTimer();
}
from sming.
Tested the above application against various updated SDK versions:
tag v3.0.4 b1c14cdb : no change
tag v3.0.5 7b5b35da : no change
branch release/v3.0.5 38fda5f9 : bootloop crashing
branch master : doesn't boot
Inspection shows all of them have the same NmiTimSetFunc
implementation.
from sming.
Related Issues (20)
- esp32c3 redirection of uart serial to usb serial ? HOT 4
- Can't build for SMING_ARCH=Host in Apple M1 Pro HOT 15
- Websocket server has big delay when sending messages HOT 3
- ESP32C3 WiFi problems HOT 8
- #warning "**Y2038** time_t is only 32-bits in this build configuration stops the build for esp32 due to -Werror=cpp HOT 5
- make flash does not upload modified javascript file HOT 2
- Windows Esp8266 CI build randomly failing due to lwip2 HOT 3
- can't build for Arch host on Fedora 39 HOT 5
- ESP32 builds are massive HOT 4
- HostTests failing for esp32c3, UP timer not zero HOT 2
- Handling TCP connection errors
- DateTime checks failing on esp32 HOT 1
- ESP32 IDF defines different value for LittleFS partitions
- Esp8266 and Esp32 PHY init data storage HOT 1
- Documentation build fails in Windows
- Manual approval required for workflow run 9989247967 HOT 2
- *** Preparation for Release 6.0.0 ***
- [NEWS] Sming appears in the German "Make Magazin"
- Error during compiling HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sming.