S32G274A-M7 DTCM and Cache interaction

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32G274A-M7 DTCM and Cache interaction

1,386 Views
nakrachi
Contributor II

Hello,

I'm investigating a strange bug that makes some function calls on the M7 core to spike from ~3us to up to 2ms (according to the measurements using the tracing module)

I disabled Data Cache (for testing) and it seems to make the issue go away, which got me thinking this might be a cache coherency issue ?

After digging a little bit more I noticed that the DTCM is used as a stack for each of the M7 cores, and the MPU region for it was set as cacheable - bufferable , which I think should not be the case ? I disabled the cache in the MPU entry, when I did that I started getting alignment exceptions (all from DTCM).

My question is, why cache as an effect on DTCM even if they are not sharing the same bus ?

Why having the DTCM MPU region set as cache-on masks the unaligned access errors ?

Also is it okay to use the DTCM for the stack? as GCC generates unaligned access instructions to the TCM memory.  

Thank you

0 Kudos
Reply
3 Replies

1,357 Views
nakrachi
Contributor II

Hi Joey!

I am using the S32G2 in multi-core, the A53 are running Linux, and the M7 have a custom baremetal running on them. 

Unfortunately I cannot share the code, but I can try to explain in detail what I am noticing. 

The MPU entry for the DTCM was "mistakenly" set to cacheable, when I did set it to cacheable I started seeing unaligned access exceptions, after looking into the assembly, GCC was indeed generating unaligned word access on the DTCM (used as stack). 

I then added -mno-unaligned-access to my gcc options and now I can set the DTCM MPU region to uncacheable without generating any exceptions. 

It also seems to solve the bug I was after, trace data showed no spikes in function execution time. 

But I am still puzzled by the effect of cache on the DTCM, 

  • Why having the MPU region set to cacheable "masks" the unaligned access exceptions ?
  • Why disabling the cache, while keeping the MPU region as cacheable does not generate unaligned exceptions? and also as side effect, solve the execution time spikes? 
0 Kudos
Reply

1,289 Views
Joey_z
NXP Employee
NXP Employee

hi, nakrachi

Thank you for your reply.

I'm glad to hear that your problem has been solved. This issue should be caused by incompatibility between the MCU and MPU in setting the DTCM area.

BR

Joey

0 Kudos
Reply

1,360 Views
Joey_z
NXP Employee
NXP Employee

hi,nakrachi

Thank you for your question.

are you using the S32G2 on the multi-core? Do you use any demo and code for testing?

Could you share more information for us?

BR

Joey

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2136090%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32G274A-M7%20DTCM%20and%20Cache%20interaction%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2136090%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3EI'm%20investigating%20a%20strange%20bug%20that%20makes%20some%20function%20calls%20on%20the%20M7%20core%20to%20spike%20from%20~3us%20to%20up%20to%202ms%20(according%20to%20the%20measurements%20using%20the%20tracing%20module)%3C%2FP%3E%3CP%3EI%20disabled%20Data%20Cache%20(for%20testing)%20and%20it%20seems%20to%20make%20the%20issue%20go%20away%2C%20which%20got%20me%20thinking%20this%20might%20be%20a%20cache%20coherency%20issue%20%3F%3C%2FP%3E%3CP%3EAfter%20digging%20a%20little%20bit%20more%20I%20noticed%20that%20the%20DTCM%20is%20used%20as%20a%20stack%20for%20each%20of%20the%20M7%20cores%2C%20and%20the%20MPU%20region%20for%20it%20was%20set%20as%20cacheable%20-%20bufferable%20%2C%20which%20I%20think%20should%20not%20be%20the%20case%20%3F%20I%20disabled%20the%20cache%20in%20the%20MPU%20entry%2C%20when%20I%20did%20that%20I%20started%20getting%20alignment%20exceptions%20(all%20from%20DTCM).%3C%2FP%3E%3CP%3EMy%20question%20is%2C%20why%20cache%20as%20an%20effect%20on%20DTCM%20even%20if%20they%20are%20not%20sharing%20the%20same%20bus%20%3F%3C%2FP%3E%3CP%3EWhy%20having%20the%20DTCM%20MPU%20region%20set%20as%20cache-on%20masks%20the%20unaligned%20access%20errors%20%3F%3C%2FP%3E%3CP%3EAlso%20is%20it%20okay%20to%20use%20the%20DTCM%20for%20the%20stack%3F%20as%20GCC%20generates%20unaligned%20access%20instructions%20to%20the%20TCM%20memory.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2137862%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32G274A-M7%20DTCM%20and%20Cache%20interaction%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2137862%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3Ehi%2C%26nbsp%3B%3CSPAN%3Enakrachi%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThank%20you%20for%20your%20reply.%3C%2FP%3E%0A%3CP%3EI'm%20glad%20to%20hear%20that%20your%20problem%20has%20been%20solved.%20This%20issue%20should%20be%20caused%20by%20incompatibility%20between%20the%20MCU%20and%20MPU%20in%20setting%20the%20DTCM%20area.%3C%2FP%3E%0A%3CP%3EBR%3C%2FP%3E%0A%3CP%3EJoey%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2136537%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32G274A-M7%20DTCM%20and%20Cache%20interaction%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2136537%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20Joey!%3C%2FP%3E%3CP%3EI%20am%20using%20the%20S32G2%20in%20multi-core%2C%20the%20A53%20are%20running%20Linux%2C%20and%20the%20M7%20have%20a%20custom%20baremetal%20running%20on%20them.%26nbsp%3B%3C%2FP%3E%3CP%3EUnfortunately%20I%20cannot%20share%20the%20code%2C%20but%20I%20can%20try%20to%20explain%20in%20detail%20what%20I%20am%20noticing.%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20MPU%20entry%20for%20the%20DTCM%20was%20%22mistakenly%22%20set%20to%20cacheable%2C%20when%20I%20did%20set%20it%20to%20cacheable%20I%20started%20seeing%20unaligned%20access%20exceptions%2C%20after%20looking%20into%20the%20assembly%2C%20GCC%20was%20indeed%20generating%20unaligned%20word%20access%20on%20the%20DTCM%20(used%20as%20stack).%26nbsp%3B%3C%2FP%3E%3CP%3EI%20then%20added%26nbsp%3B%3CEM%3E-mno-unaligned-access%26nbsp%3B%3C%2FEM%3Eto%20my%20gcc%20options%20and%20now%20I%20can%20set%20the%20DTCM%20MPU%20region%20to%20uncacheable%20without%20generating%20any%20exceptions.%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20also%20seems%20to%20solve%20the%20bug%20I%20was%20after%2C%20trace%20data%20showed%20no%20spikes%20in%20function%20execution%20time.%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20I%20am%20still%20puzzled%20by%20the%20effect%20of%20cache%20on%20the%20DTCM%2C%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3EWhy%20having%20the%20MPU%20region%20set%20to%20cacheable%20%22masks%22%20the%20unaligned%20access%20exceptions%20%3F%3C%2FLI%3E%3CLI%3EWhy%20disabling%20the%20cache%2C%20while%20keeping%20the%20MPU%20region%20as%20cacheable%20does%20not%20generate%20unaligned%20exceptions%3F%20and%20also%20as%20side%20effect%2C%20solve%20the%20execution%20time%20spikes%3F%26nbsp%3B%3C%2FLI%3E%3C%2FUL%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2136512%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32G274A-M7%20DTCM%20and%20Cache%20interaction%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2136512%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3Ehi%2C%3CSPAN%3Enakrachi%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThank%20you%20for%20your%20question.%3C%2FP%3E%0A%3CP%3Eare%20you%20using%20the%20S32G2%20on%20the%20multi-core%3F%20Do%20you%20use%20any%20demo%20and%20code%20for%20testing%3F%3C%2FP%3E%0A%3CP%3ECould%20you%20share%20more%20information%20for%20us%3F%3C%2FP%3E%0A%3CP%3EBR%3C%2FP%3E%0A%3CP%3EJoey%3C%2FP%3E%3C%2FLINGO-BODY%3E