[chbot] Volatile struct puzzle

Robin Gilks gb7ipd at gmail.com
Sat Feb 5 00:50:29 GMT 2022


Some may recall that a year or 2 ago I had great problems getting the
hardware JPEG encode to work on an STM32 processor. It turned out that the
memory cache attributes manifested as a race condition between DMA and CPU
access.
The problem has just reappeared as a result of updating
from arm-none-eabi-gcc-9.2.1-1.1 to arm-none-eabi-gcc-10.3.1-2.3.

After a few pokes at the code I've narrowed the issue down to whether a
volatile struct element is initialized statically  or at run time.
Interestingly the issue is inverted between compiler versions
The buffer referenced by the structure element 'DataBuffer'  is defined and
instantiated in a reserved section of memory that has the correct cache
attributes

typedef struct
{
uint8_t State;
uint8_t *DataBuffer;
uint32_t DataBufferSize;
}JPEG_Data_BufferTypeDef;
uint8_t JPEG_Data_InBuffer[CHUNK_SIZE_IN]__attribute__((section(
".MCU_Data_section")));
original code - works with gcc-9; fails with gcc-10:
volatile JPEG_Data_BufferTypeDef Jpeg_IN_BufferTab = {JPEG_BUFFER_EMPTY,
JPEG_Data_InBuffer, 0};
current code fails with gcc-9 works with gcc-10:
volatile JPEG_Data_BufferTypeDef Jpeg_IN_BufferTab = {0, 0, 0};
...
Jpeg_IN_BufferTab.DataBufferSize = 0;
Jpeg_IN_BufferTab.State = JPEG_BUFFER_EMPTY;
Jpeg_IN_BufferTab.DataBuffer = JPEG_Data_InBuffer;

Note that NO other changes (apart from the compiler version) were made!!
I'm at a total loss as to what is going on, hopefully someone can shine a
light ;)

-- 
Robin Gilks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20220205/1c97bbf0/attachment.html>


More information about the Chchrobotics mailing list