Errors "not within region DTCM"

Status
Not open for further replies.

ofishal

Well-known member
I am using Windows 8.1, a Teensy 4.0 and a Teensy Audio Shield.

I am running a modified SamplePlayer code which worked well with 8 separate sounds (notes) connected to three mixers (code below).

I am trying to build an electric steel drum and have a way to go since I want to have 29 separate sounds (notes).

I added two additional sounds to mixer 3 (bringing the total number of sounds (notes) to 10) and the program would not compile.

I got three errors, one says "...data' will not fit in region `DTCM'" and two say "...bss' is not within region `DTCM'".

I'm not sure what these mean, am I out of memory?

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>

// WAV files converted to code by wav2sketch
#include "AudioSampleC_drum.h"  //  AudioSampleC_drum (C4) // 1st note into mixer 1
#include "AudioSampleD_drum.h"  //  AudioSampleD_drum (D4) // 2nd note into mixer 1
#include "AudioSampleE_drum.h"  //  AudioSampleE_drum (E4) // 3rd note into mixer 1
#include "AudioSampleF_drum.h"  //  AudioSampleF_drum (F4) // 4th note into mixer 1
#include "AudioSampleG_drum.h"  //  AudioSampleG_drum (G4) // 5th note into mixer 2
#include "AudioSampleA_drum.h"  //  AudioSampleA_drum (A4) // 6th note into mixer 2
#include "AudioSampleB_drum.h"  //  AudioSampleB_drum (B4) // 7th note into mixer 2
#include "AudioSampleC1_drum.h"  // AudioSampleC1_drum (C5) // 8th note into mixer 3
#include "AudioSampleD1_drum.h"  // AudioSampleD1_drum (D5) // 9th note into mixer 3
#include "AudioSampleE1_drum.h"  // AudioSampleE1_drum (E5) // 10th note into mixer 3

// GUItool: begin automatically generated code
AudioPlayMemory          playMem3;       
AudioPlayMemory          playMem4;       
AudioPlayMemory          playMem1;      
AudioPlayMemory          playMem2;      
AudioPlayMemory          playMem5; 
AudioPlayMemory          playMem6; 
AudioPlayMemory          playMem7;  
AudioPlayMemory          playMem8;   // 8th note into mixer 3
AudioPlayMemory          playMem9;   // 9th note into mixer 3
AudioPlayMemory          playMem10;  // 10th note into mixer 3

// Mixers and Output
AudioMixer4              mixer1; 
AudioMixer4              mixer2;  
AudioMixer4              mixer3; // new mixer 3  
AudioOutputI2S           headphones;

// Inputs to Mixer 1
AudioConnection          patchCord3(playMem1, 0, mixer1, 0); // AudioSample C4
AudioConnection          patchCord4(playMem2, 0, mixer1, 1); // AudioSample D4
AudioConnection          patchCord1(playMem3, 0, mixer1, 2); // AudioSample E4
AudioConnection          patchCord2(playMem4, 0, mixer1, 3); // AudioSample F4

// Inputs to Mixer 2
AudioConnection          patchCord5(mixer1, 0, mixer2, 0); // output from mixer 1 into mixer 2
AudioConnection          patchCord6(playMem5, 0, mixer2, 1); // AudioSample G4
AudioConnection          patchCord7(playMem6, 0, mixer2, 2); // AudioSample A4
AudioConnection          patchCord8(playMem7, 0, mixer2, 3); // AudioSample B4

// Inputs to Mixer 3
AudioConnection          patchCord9(mixer2, 0, mixer3, 0); // output from mixer 2 into mixer 3
AudioConnection          patchCord10(playMem8, 0, mixer3, 1); // AudioSample C1
AudioConnection          patchCord11(playMem9, 0, mixer3, 2); // AudioSample D1
AudioConnection          patchCord12(playMem10, 0, mixer3, 3); // AudioSample E1

// Outputs from Audio Shield to headphones
AudioConnection          patchCord13(mixer3, 0, headphones, 0); // changed from mixer 2 to mixer 3
AudioConnection          patchCord14(mixer3, 0, headphones, 1); // changed from mixer 2 to mixer 3

AudioControlSGTL5000     sgtl5000_1;     

//Audio Connections
AudioConnection c1(playMem1, 0, mixer1, 0);  
AudioConnection c2(playMem2, 0, mixer1, 1);  
AudioConnection c3(playMem3, 0, mixer1, 2);  
AudioConnection c4(playMem4, 0, mixer1, 3);
AudioConnection c5(playMem5, 0, mixer2, 1); 
AudioConnection c6(playMem6, 0, mixer2, 2); 
AudioConnection c7(playMem7, 0, mixer2, 3); 
AudioConnection c8(playMem8, 0, mixer3, 1);   // new 8th note into mixer 3 
AudioConnection c9(playMem9, 0, mixer3, 2);   // new 9th note into mixer 3 
AudioConnection c10(playMem10, 0, mixer3, 3); // new 10th note into mixer 3 

//play to both I2S audio board and on-chip DAC
AudioConnection c11(mixer3, 0, headphones, 1); // Changed to mixer 3
AudioOutputAnalog  dac;

//Object to Control Audio Shield
AudioControlSGTL5000 audioShield;

// Bounce objects to read six pushbuttons (pins)
Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5);  // 5 ms debounce time
Bounce button2 = Bounce(2, 5);
Bounce button3 = Bounce(3, 5);
Bounce button4 = Bounce(4, 5); 
Bounce button5 = Bounce(5, 5); 
Bounce button6 = Bounce(6, 5); 
Bounce button9 = Bounce(9, 5);   // pin 9 on Teensy
Bounce button10 = Bounce(10, 5); // pin 10 on Teensy
Bounce button11 = Bounce(11, 5); // pin 11 on Teensy 

void setup() {
// Configure the pushbutton pins for pullups.
// Each button should connect from the pin to GND.
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);  // to Teensy pin 9
pinMode(10, INPUT_PULLUP); // to Teensy pin 10
pinMode(11, INPUT_PULLUP); // to Teensy pin 11

// Audio connections require memory to work.  For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(12); // maybe need to change audiomemory at some point? Can't find MemoryAndCpuUsage example. Was 10; changed to 12

// turn on the output
audioShield.enable();
audioShield.volume(0.5);

// reduce the gain on mixer channels, so more than 1
// sound can play simultaneously without clipping
mixer1.gain(0, 0.4);
mixer1.gain(1, 0.4);
mixer1.gain(2, 0.4);
mixer1.gain(3, 0.4);

mixer2.gain(0, 0.4); //added gains for all channels in mixer 2
mixer2.gain(1, 0.4);
mixer2.gain(2, 0.4);
mixer2.gain(3, 0.4);

mixer3.gain(0, 0.4); // added gains for channels in mixer 3
mixer3.gain(1, 0.4);
mixer3.gain(2, 0.4);
mixer3.gain(3, 0.4);

}

void loop() {
// Update all the button objects
  button0.update();
  button1.update();
  button2.update();
  button3.update();
  button4.update();
  button5.update();
  button6.update(); 
  button9.update(); 
  button10.update(); 
  button11.update();  

 // When the buttons are pressed, just start a sound playing.
  // The audio library will play each sound through the mixers
  // so any combination can play simultaneously.
  //
  if (button0.fallingEdge()) {
    playMem1.play(AudioSampleC_drum);
  }
  if (button1.fallingEdge()) {
    playMem2.play(AudioSampleD_drum);
  }
  if (button2.fallingEdge()) {
    playMem3.play(AudioSampleE_drum);
  }
  if (button3.fallingEdge()) {
    playMem4.play(AudioSampleF_drum);
  }
  if (button4.fallingEdge()) {
    playMem5.play(AudioSampleG_drum);
  }
  if (button5.fallingEdge()) {
    playMem6.play(AudioSampleA_drum);
  }
  if (button6.fallingEdge()) {
    playMem7.play(AudioSampleB_drum);
  }
  if (button9.fallingEdge()) {
    playMem8.play(AudioSampleC1_drum);
  }
  if (button10.fallingEdge()) {
    playMem9.play(AudioSampleD1_drum);
  }
  if (button11.fallingEdge()) {
    playMem10.play(AudioSampleE1_drum);
  }
  }
 
Not sure what the samples look like for definition or size? But declaring them PROGMEM in the header files will keep them on FLASH, otherwise they will reside in RAM which the DTCM portion is some part of 512KB.

I found this in the tree so something like this should work:
Code:
PROGMEM
const unsigned int AudioSampleCashregister[5809] = {
// ...
 
degragster, Thanks for the input. I will do some research on how to use the PROGMEM command in my code. I'm not sure if I need one for each note (sample) or where it should go in the code. I also need to see how it might change other lines that need to be changed.

I used the Teensy Audio Library for the sketch (SamplePlayer) and thought it would work for my project, but perhaps my number of samples is too large for this programming approach.

I'm guessing you are suggesting I use the PROGMEM instead of AudioPlayMemory, or maybe not. I'm just low on the learning curve for PROGMEM and how it might work for the SamplePlayer sketch. But I appreciate the input and will research it.

In terms of my sound samples, each is a single note from a steel drum. I think they run between 12000 and 26000 bits (?). For example, here is the heading of one of them "extern const unsigned int AudioSampleA_drum[12289];" Maybe I need to make them smaller, but I'm not sure about that. I'm new to C++ and Teensy, but working hard to learn my way through the curve to get my project up and running.
 
Each sample is uniquely defined and each will need appropriate 'decoration' with PROGMEM to have it read from FLASH.

The snippet I pulled came from SamplePlayer IIRC - so look to those samples for inspiration if that SamplePlayer example works.

Indeed if at 10 samples you are filling 300+KB of RAM then you may run out before getting all your samples even into FLASH.

AudioPlayMemory is it's own thing - these 'decorations' need to be made at Compile time to get them marked for FLASH storage with PROGMEM. From there they should work as well as the SamplePlayer example. The memory address space is FLAT with a pointer to any place RAM or FLASH so that shouldn't impact - though reading from FLASH not the same speed as RAM access … again it should work as well there as in SamplePlayer.
 
Defragster, There is a discussion where a user (Sandro) said that he solved his memory issue (using SamplePlayer) by soldering a W25Q128FV chip onto his audio board to have sufficient flash memory for more sounds. If, as you say, my samples are filling 300+KB or RAM then this should be a solution for me too, correct?

At least this is what I've believed from assistance I've received from helpful folks in the forum. I ruined one audio board with a bad soldering job and purchased a second. I believe I did a fine job soldering the second chip onto the new audio shield (photo below).

W25Q128FV Chip.jpg

However, when I run serial flash tests, the chip is not identified and I can't understand why. I believe I have oriented the chip correctly, but maybe you can verify this. The chip says Winbond 2SQ128FVSG and 1314. Maybe I am using the wrong chip? I purchased both of the chips from Ebay. Perhaps I've received counterfeit chips?
 
Again for what it is worth, I tried to explain a little about the different sections of memory on the T4 up in the thread: https://forum.pjrc.com/threads/57326-T4-0-Memory-trying-to-make-sense-of-the-different-regions

In that thread (I think posting #3), I link to a little software project I did (started by Frank B, and defragster, and ...) where you can build an executable, and shows you a possible place to put it in platform.txt, that with at least verbose compiles, can display more stuff about your program, and also will abort the build if it finds you exceeded the lower memory range...

An example output, for a test sketch I am playing with that has three 240x320 images built into it:
Code:
FlexRAM section ITCM+DTCM = 512 KB
    Config : aaaaaaaf
    ITCM :  34848 B	(53.17% of   64 KB)
    DTCM :  17088 B	( 3.72% of  448 KB)
    Available for Stack: 441664
OCRAM: 512KB
    DMAMEM:      0 B	( 0.00% of  512 KB)
    Available for Heap: 524288 B	(100.00% of  512 KB)
Flash: 506464 B	(24.93% of 1984 KB)

Now if I removed the PROGMEM from the three images, the ITCM+DTCM would exceed 512K...
 
Defragster, There is a discussion where a user (Sandro) said that he solved his memory issue (using SamplePlayer) by soldering a W25Q128FV chip onto his audio board to have sufficient flash memory for more sounds. If, as you say, my samples are filling 300+KB or RAM then this should be a solution for me too, correct?

At least this is what I've believed from assistance I've received from helpful folks in the forum. I ruined one audio board with a bad soldering job and purchased a second. I believe I did a fine job soldering the second chip onto the new audio shield (photo below).

View attachment 17453

However, when I run serial flash tests, the chip is not identified and I can't understand why. I believe I have oriented the chip correctly, but maybe you can verify this. The chip says Winbond 2SQ128FVSG and 1314. Maybe I am using the wrong chip? I purchased both of the chips from Ebay. Perhaps I've received counterfeit chips?

Filling Flash was just a guess with current usage - KurtE's utility will give a good view of usage - or with manually adding up the byte count of the samples to be used.

The chip placement looks right as long as all the pads are well soldered - and not bothered with rosin remains. A questionable chip is always possible from Ebay sources. Fitting them on the T4 onboard Flash will be faster for access.
 
However, when I run serial flash tests, the chip is not identified and I can't understand why. I believe I have oriented the chip correctly, but maybe you can verify this. The chip says Winbond 2SQ128FVSG and 1314. Maybe I am using the wrong chip? I purchased both of the chips from Ebay. Perhaps I've received counterfeit chips?
When running the SerialFlash examples make sure you have configured the proper SPI pins (6,7,12,14). what does EraseEverything print?
 
Manitou, Thanks for your advice with SerialFlash. I'm not sure what pins you are referring to, in the T4 or the audio shield, but I'm not using some of the pins you mention. I am using the connection diagram provided by PJRC to connect the T4 to the audio shield (photo below). I am not using the 100 ohm resistor because I have a rev c shield.T4 Audio Shield Connections.jpg
 
Manitou, Thanks for your advice with SerialFlash. I'm not sure what pins you are referring to, in the T4 or the audio shield, but I'm not using some of the pins you mention. I am using the connection diagram provided by PJRC to connect the T4 to the audio shield (photo below). I am not using the 100 ohm resistor because I have a rev c shield.

ooops, my bad, i was focused on Winbond chip and forgot earlier context regarding T4. though the diagram doesn't show pin 6 hooked to MEMCS
 
Manitou, No worries....Yeah, I have nothing connected to MEMCS. Is this something I need to connect to get something working that isn't?
 
Manitou, No worries....Yeah, I have nothing connected to MEMCS. Is this something I need to connect to get something working that isn't?

yep, if you look at shield's schematic, you'll see MEMCS is the SPI CS pin on the Winbond chip. hook it to pin 6 (i think SerialFlash examples have pin 6 as CS) Diagram doesn't show T4 MOSI, MISO, SCLK hooked up?
 
Thanks for your help Manitou,

So maybe I am lacking some connections? I only soldered the Winbond flash chip to the audio shield and only connected the wires in the diagram I found somewhere on the PJRC site or in the forum. However, I have nothing connected to pin 6 on the T4 and I have nothing connected to the audio shield's MOSI, MEMCS or SDCS pins.

And not only is the T4 not recognizing my Winbond flash chip, but it is also not recognizing my SD card in my audio shield. So maybe I need more connections?
 
here is my mapping of T4 pins to audio shield
Code:
             T4 adapter holes  continuity
               T4    audio header  silk screen   T4B2R breakout pins
               13 to SCK  (14)
               12    MISO (12)
               10    CS   (10)
               11    MOSI (7)
               23    MCLK    (was 5?)   need 100 ohm for 1062
               21    BCLK    (was 4)
                9    MEMCS
               19    SCL
               18    SDA
               20    LRCLK
                7    Tx      (was 6)
                8    Rx      (was 7)
               15    Vol   A1

SD requires SPI pins too: MOSI,MISO,SCLK and SDCS(pin 10)
 
Manitou, First of all, thanks for the help. I'm sort of excited that things might work out for me if I connect more wires between my T4 and the audio shield. Maybe my flash memory chip and SD card in the audio shield will actually communicate with my T4 if I connect more wires.

I do not have anything connected between my T4 and the audio shield on T4 pins 9, 10, 11, 12 and 13. So here are my questions:

You identify pin 9 on the T4 as MEMCS (the T4 card that came with the board identifies this pin as OUT1C). You are recommending I connect pin 9 on the T4 to pin 6 on the audio shield (MEMCS)?
You identify pin 10 on the T4 as CS (the T4 card that came with the board identifies this pin as CS (SPI) and MQSR). You are recommending I connect pin 10 on the T4 to pin 10 on the audio shiled (SDCS)?
You identify pin 11 on the T4 as MOSI (SPI) (the T4 card that came with the board also identifies this pin as MOSI). You are recommending I connect pin 11 on the T4 to pin 7 on the audio shield (MOSI)?
You identify pin 12 on the T4 as MISO (SPI) (the T4 card that came with the board also identifies this pin as MISO). You are recommending I connect pin 12 on the T4 to pin 12 on the audio shield (MISO)?
You identify pin 13 on the T4 as SCK (the T4 card that came with the board also identifies this pin as SCK). You are recommending I connect pin 13 on the T4 to pin 14 on the audio shield (SCLK)?

If I've understood this correctly (please notify me if not) these five additional connections will make my T4 and audio shield work together in terms of flash memory chip and SD card?

And again, thanks for the help.
 
Status
Not open for further replies.
Back
Top