<div dir="ltr">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 <font color="#000000">condition between DMA and CPU access.</font><div><font color="#000000" face="arial, sans-serif">The problem has just reappeared as a result of updating from arm-none-eabi-gcc-9.2.1-1.1 </font><span style="color:rgb(0,0,0);font-family:arial,sans-serif">to arm-none-eabi-gcc-10.3.1-2.3. </span><div><font color="#000000" face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif" color="#000000">After a few pokes at the code I've narrowed the issue down to whether a volatile struct element is </font><span style="color:rgb(0,0,0);font-family:arial,sans-serif">initialized</span><span style="color:rgb(0,0,0);font-family:arial,sans-serif"> statically  or at run time. Interestingly the issue is inverted between compiler versions</span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif">The buffer referenced by the structure element 'DataBuffer'  is defined and instantiated in a reserved section of memory that has the correct cache attributes</span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif"><br></span></div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(86,156,214)">typedef</span> <span style="color:rgb(86,156,214)">struct</span></div><div>{</div><div>  <span style="color:rgb(78,201,176)">uint8_t</span> <span style="color:rgb(156,220,254)">State</span>;  </div><div>  <span style="color:rgb(78,201,176)">uint8_t</span> *<span style="color:rgb(156,220,254)">DataBuffer</span>;</div><div>  <span style="color:rgb(78,201,176)">uint32_t</span> <span style="color:rgb(156,220,254)">DataBufferSize</span>;</div><div>}<span style="color:rgb(78,201,176)">JPEG_Data_BufferTypeDef</span>;</div></div></div><div><div style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;line-height:19px;white-space:pre"><div style="background-color:rgb(30,30,30);color:rgb(212,212,212)"><span style="color:rgb(86,156,214)">uint8_t</span> <span style="color:rgb(156,220,254)">JPEG_Data_InBuffer</span>[CHUNK_SIZE_IN]<span style="color:rgb(220,220,170)">__attribute__</span>((<span style="color:rgb(220,220,170)">section</span>(<span style="color:rgb(206,145,120)">".MCU_Data_section"</span>)));<br></div><div style="line-height:19px"><div style=""><font color="#000000" style="background-color:rgb(255,255,255)">original code - works with gcc-9; fails with gcc-10:</font></div><div style="background-color:rgb(30,30,30);color:rgb(212,212,212)">volatile JPEG_Data_BufferTypeDef Jpeg_IN_BufferTab = {JPEG_BUFFER_EMPTY, JPEG_Data_InBuffer, <span style="color:rgb(181,206,168)">0</span>};</div><font style="background-color:rgb(255,255,255)" color="#000000">current code fails with gcc-9 works with gcc-10:</font></div><div style="line-height:19px"><div style="background-color:rgb(30,30,30);line-height:19px"><div style=""><font color="#569cd6">volatile</font><font color="#d4d4d4"> </font><span style="color:rgb(78,201,176)">JPEG_Data_BufferTypeDef</span><font color="#d4d4d4"> </font><span style="color:rgb(156,220,254)">Jpeg_IN_BufferTab</span><font color="#d4d4d4"> =  {</font><span style="color:rgb(181,206,168)">0</span><font color="#d4d4d4">, </font><span style="color:rgb(181,206,168)">0</span><font color="#d4d4d4">, </font><span style="color:rgb(181,206,168)">0</span><font color="#d4d4d4">};</font></div><div style=""><font color="#d4d4d4">...</font></div><div style=""><div style="color:rgb(212,212,212);line-height:19px"><div>   <span style="color:rgb(156,220,254)">Jpeg_IN_BufferTab</span>.<span style="color:rgb(156,220,254)">DataBufferSize</span> = <span style="color:rgb(181,206,168)">0</span>;</div><div>   <span style="color:rgb(156,220,254)">Jpeg_IN_BufferTab</span>.<span style="color:rgb(156,220,254)">State</span> = <span style="color:rgb(86,156,214)">JPEG_BUFFER_EMPTY</span>;</div><div>   <span style="color:rgb(156,220,254)">Jpeg_IN_BufferTab</span>.<span style="color:rgb(156,220,254)">DataBuffer</span> = <span style="color:rgb(156,220,254)">JPEG_Data_InBuffer</span>;</div></div></div></div></div></div></div><div><br></div><div>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 ;)</div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Robin Gilks<div><br></div></div></div></div></div>