Chat freely about anything...

User avatar
By rith87
#58239 I see a few warnings in the SDK documentation:

We suggest using a timer to check periodically, if users need to call os_delay_us or
function while, or function for in timer callback, please do not occupy CPU more than 15
ms.


Does the latter mean that there is a 15 ms time limit even for software timer callbacks? Why 15 ms?

Read and write RAM has to be aligned by 4 bytes, so please do not cast pointer directly,
for example, please use os_memcpy instead of float temp = *((float*)data);.


Does this apply only if data was some (void *) or (uint8_t *)? Or do they mean that assignment to a dereferenced pointer is invalid? (i.e if data was a float * already, is it still invalid? seem crazy if it is...)
User avatar
By rith87
#58282 I'm really not sure how valid the 4 byte RAM write/read is. I have something like this

Code: Select alltypedef struct {
   uint16_t size;
   uint16_t source;
   uint16_t destination;
   uint8_t payload[MAX_PAYLOAD_SIZE];
} Data_Packet;

uint8_t buf[100];


I receive the Data_Packet via UART and store it in buf and then I cast the buf into a Data_Packet. And then I cast the payload into the desired data structure. I do this in a few places in my code but my code runs fine most of the time (one crash every few hours). Or is the warning something that may cause problems only occasionally...?
User avatar
By piersfinlayson
#58328
rith87 wrote:I see a few warnings in the SDK documentation:

We suggest using a timer to check periodically, if users need to call os_delay_us or
function while, or function for in timer callback, please do not occupy CPU more than 15
ms.


Does the latter mean that there is a 15 ms time limit even for software timer callbacks? Why 15 ms?



Yes, it does. The ESP8266 only has a single core and the non-os SDK is only single threaded. The device is not just running your code, it's also running other stuff, like keeping the WiFi association(s) alive. I assume 15ms is, give or take, how frequently it needs to do this.


Read and write RAM has to be aligned by 4 bytes, so please do not cast pointer directly,
for example, please use os_memcpy instead of float temp = *((float*)data);.


Does this apply only if data was some (void *) or (uint8_t *)? Or do they mean that assignment to a dereferenced pointer is invalid? (i.e if data was a float * already, is it still invalid? seem crazy if it is...)


What this is essentially saying is that when accessing some data types, these must be aligned on a 4-byte boundary in RAM. This applies to for example a 4 byte int type. So if you cast an arbitrary piece of memory to an int there a 3 in 4 chance this won't be 4 byte aligned, so the processor will throw an exception.

In reality it may be much less likely, or much more likely, than 3 in 4 depending on the precise code - or it may not happen at all.

You can resolve your problem by declaring your buf to be 4 byte aligned:

Code: Select alluint8_t __attribute__((aligned(4))) buf[100];