Hi,
I receive
Error Status: 0x80010133 Code: 307 Module: 1
Error Message: Mutex: 0x200019CC, Not allowed in ISR context
when I change
std::string s1 = to_string(5);
to
std::string s1 = to_string(5.1);
inside an ISR context for my serial output.
How can I circumvent this?
Thank you!
Code:
#include “ThisThread.h”
#include “mbed.h”
#include “cstddef”
#include “iostream”
#include “string”
#include “iomanip”// Maximum number of element the application buffer can contain
#define MAXIMUM_BUFFER_SIZE 32InterruptIn button(SW2);
DigitalOut led(LED1);// Create a BufferedSerial object with a default baud rate.
static UnbufferedSerial SerialPort(USBTX, USBRX);// Application buffer to receive the data
char buf[MAXIMUM_BUFFER_SIZE] = {0};
uint8_t bufPos;void sendMotorStatusMessage(double speed)
{
bufPos = 0;
std::string s1 = to_string(5.1);
strncpy(buf + bufPos, s1.c_str(), s1.length());
bufPos += s1.length();buf[bufPos] = '\0'; SerialPort.write(buf, sizeof(buf)); memset(buf, 0, sizeof(buf));
}
void flip()
{
led = !led;
sendMotorStatusMessage(0);
}int main(void)
{
// Set desired properties (9600-8-N-1).
SerialPort.baud(115200);
SerialPort.format(
/* bits / 8,
/ parity / BufferedSerial::None,
/ stop bit */ 1
);
button.rise(&flip);while (1) { ThisThread::sleep_for(250ms); }
}