beginner dtcm

Status
Not open for further replies.

Whstark

New member
I'm old vet/Va disabled and full electronic experience and a lot of asm 8080 and others, and pc wise since 8080 altair/imsai, even some ,macro 11 and c etc. and some degree in web/programmer. some asm in some micros. But always a hardware person mostly.

I guess dtcm? is my problem, thought it had 512k of fast ram as datasheet but should it be in flash. is there some statement to be made on a teensy 4.0 with sound board to make this compile. seems wave tables should be in fast flash why ,wave tables in flash.? what determines what goes where. just want some midi device to work with a sequencer on pc.
Did't hook up buttons and switches cause I put female dip socket on audio (all i had) and pins on 4.o board, as if i Knew how to I DO but easy if needed,
program is midi synth large.. problem dtcm error. maybe some one can help. sorry about background. thought it help. dtcm ? Takes allot to comprehend this processor. Esp all the timers and dma channels, looked into minix arm, as a diversion and 8080 z80 emulators.

William
 
Last edited:
There is a Teensy 4.0 page here on PJRC with a "Memory Layout" section :: pjrc.com/store/teensy40.html

There is a post that lead to that page as well to find if more info would be helpful.

The 1 MB of RAM is split as shown, half is TCM at full processor speed where ITCM and DTCM reside. That is code not marked FLASHMEM moves to the Instruction TCM are and all Compile time (STATIC or 'global') allocations not marked PROGMEM [for const data] move to Data TCM. And the Stack 'local' memory comes and goes with functions() out of the DTCM memory.

The other 512KB is DMAMEM allocated or runtime allocated with malloc() and runs at 25% of processor speed ( but is covered by cache )

With those notes in mind hopefully the linked page completes the picture?
 
Thanks for the info,
Would the article https://www.kernel.org/doc/Documentation/arm/tcm.txt outdated somewhat be relevant. Seems the cpu architecture for ram split, let alone the the I/O are somewhat complicated (well maybe not as bad as banked I/O on pic micros or the arm instruction set to begin with. So I would think now wave tables and program not changed could be allocated as progmem by compiler or designated, does the dtcm need to be used because dma controller data has to be in that area for this synth program to have the speed. C and arm processor hide some things going on.
William
 
Hi and welcome,

As @defragster mentioned there some good overview data on the T4 page up on PJRC website. As he also mentioned I started a thread a year plus ago, trying to understand the different memory regions and the like, which can be found at: https://forum.pjrc.com/threads/57326-T4-0-Memory-trying-to-make-sense-of-the-different-regions

I could not tell from your post if you had an issue with building? Such as not enough memory?

As @defragster mentioned if it is because of the code being brought into the ITCM area than marking as many functions as you can with FLASHMEM may help reduce how many of the 16 32KB chunks of the faster memory to code (ITCM = Instruction Tightly Coupled Memory) and leaves more to DTCM (DATA ...)

As for Data you have at least three different places to store data.
a) Your normal variables wither initialized or unitialized (set to zero) in the DTCM (The remaining part of the fast 512kb - ITCM)
b) The other 512kb of memory. You can get this by marking the variables DMAMEM. Note: There are no initialization of variables in this region. And the rest of this area is allocated by malloc and new.
c) If you have constant data, like tables and the like, you can leave these in flash and not use up the RAM by marking these tables/variables with const ... PROGMEM.

Hope that helps.
 
Whew, so many questions packed into 1 message. I'm going to focus on just 2 for the moment...

what determines what goes where.

The simple answer is (almost) everything tries to use that 512K tightly coupled memory, unless you add specific keywords to make it use other memory. This includes code you write. The 512K is divided into ITCM for code and DTCM for variables. That partition happens at 32K chunks, so if you have 33K of code needing ITCM, 64K must be allocated, leaving 448K for DTCM. Ordinary global & static variables are allocated at the beginning of the DTCM and the stack with local variables starts at the end of DTCM and grows downward as you call more functions which have local variables.

C malloc() and C++ new are the exception. Those give you memory in the other 512K of RAM.

Code can be removed by ITCM and run directly from (slower) flash by added FLASHMEM. Likewise, read-only variables can be placed only on flash by added PROGMEM. Usually this is only needed for large arrays of constant data, like sound clips, fonts, image bitmaps, etc.


The much more complex, not-simple-at-all answer involves the linker script. Ultimately those special names you use like FLASHMEM and PROGMEM are defines which have linker section names. The linker is the part of the compiler toolchain which ultimately assigns all the various pieces of your program to their actual memory locations and fills in all the actual address numbers throughout all the compiled code. How the linker actually works, and learning the arcane format of the linker scripts is a deep dive down an extremely long rabbit hole. If you really want to know all that highly technical toolchain detail, you certainly can see everything since it's all open source. But in the end, the pragmatic result is you just end of using those names like FLASHMEM & PROGMEM and trust that the compiler will actually do the things you're telling it to do.


program is midi synth large.. problem dtcm error. maybe some one can help.

Yes, we can probably help you. If you look over the many threads on this forum, you'll see we help solve these sorts of problems regularly. Generally speaking, there are 3 ways we can help.

1: If we're able to reproduce the problem, usually we can pinpoint the specific cause of trouble and offer a quick solution.

2: If we're able to at least see the problem, but not reproduce it, often we're able to make good suggestions that lead to a fix.

3: If we can't even see the problem, sometimes we manage anyway by blind guessing.

Especially in a case like this, where the problem is merely a compile error which anyone could reproduce without having to actually run the code on a Teensy with special hardware connected, your best way to get help is letting us reproduce the problem.

But for a first blind guess, if you're getting an error saying you don't have enough memory, a very likely cause is you make have some large array of constant data like sound clips or waveforms. Just adding PROGMEM to those sorts of arrays is usually the solution.
 
Can you please just give us an alternate linker script that follows the more standard paradigm of "Flash for instructions unless marked FASTRUN"? As someone who uses several third party libraries to drive external sensors or provide graphics functions, going through dozens and dozens of source files and finding each function and marking it FLASHMEM is tedious, time consuming and something that has to be done every time the library is updated by the vendor, some of whom are on a 2 to 4 week release cycle, all for zero benefit, and every time I read "just mark everything else as FLASHMEM" I want to throw my monitor at the poster :) The vast majority of my code, and third party library code, is not performance critical, and this in my experience is generally true of most systems. For the critical path, I'll mark them FASTRUN. This is a standard paradigm for good reason. To reverse it and just puts tons of work onto us, for no benefit, is frustrating. Even if the default linker script still stays the same, an alternate that follows the standard paradigm would be a godsend. @KurtE tried this a while ago I think, but it isn't up-to-date. I've tried myself with nothing but spectacular failures because, in the words of the wise, "learning the arcane format of the linker scripts is a deep dive down an extremely long rabbit hole". I need the DTCM for data to make my app perform, not for code that isn't performant critical. Thank you. Please!
 
Status
Not open for further replies.
Back
Top