Is there anything that is necessary for I2C to work properly besides wrapping the code with vSuspendeAll() and xResumeAll()? I am porting a code that works perfectly linearly, but in freeRTOS both the communication with the OLED display and the analog converter with DMA do not want to work.
The code is in the repository, in case someone can help me.
github @ ArvoreDosSaberes/magnectostricao
Thanks
Why would you wrap with vSuspendAll()? I/O like I2C should be done using interrupts, and you want a mutex to guard against two tasks asking for operations at the same time.
Basic advice, many vendor libraries just don’t work in an RTOS because they aren’t written to be thread safe, so you may need to study them to figure out how to do the I/O properly. If they have Interrupt based routines, those may be easier to adapt.
Since I have a tight deadline for this project, I didn’t have time to delve too deeply into how this library works, but there’s not much besides two calls to SDK functions for communication with I2C.
As for the choice of vSuspendAll(), it’s precisely so that there is no context switching when I2C communication begins.
A single task handles I2C communication, since only one peripheral (OLED Display) is maintained by it.
I thought about adding a mutex, but it seemed more complex and unnecessary since only one task will manage the resource.
The issue is that if your system can just have the scheduler disabled, you didn’t need to be using an RTOS and can just be a bare-metal program.
IF only one task will use the using the I2C bus, then yes, you don’t need to have a mutex to protect it, but in general, the I2C driver will want one, since it can’t know that in general.
See, the existence of the vSuspendAll/xResumeAll pairs is precisely to handle code blocks that require atomicity, and in this case it is necessary for such blocks to be executed without being disturbed by the scheduler. This is not the only task running in the system, there are others that share the processor in their time, and this one in particular, when it has its turn to be executed, needs to do so without being disturbed precisely in these small blocks.
The approach may even be improved, but the use of vSuspendAll/xResumeAll does not eliminate the need for an RTOS.