SDRAM section Attribute

Hi, I’m working on a looper and using the DSY_SDRAM_BSS section attribute on an array of floats to specify the array’s location in memory (to hold the loop itself). This was working when the array was a global variable, but I have since defined it as a member of a loopChannel class but this results in an error during upload: section attribute not allowed for ‘loop’. Classes (and C++ in general) are new to me so I’m not sure why I’d be getting this error. After trying some google searching, I’m still unable to find anything that has pointed me in the right direction.

My questions are

  1. Why does the array’s declaration as a member of the class or as a global variable make a difference to the section attribute?
  2. What would I have to do to place the loop array in the SDRAM memory while it is a member of the class?

Here is the relevant code:

class loopChan
	bool first;
	bool rec;
	bool recdd;
	bool play;
	bool reset;
	int pos;
	int mod;
	int len;
	int indexTracker;
	float rateRemainder;
	int pushVal;
	float DSY_SDRAM_BSS loop[MAX_SIZE];
	bool rvrs;
	int stretch;
	float lvl;

		: first(true), 
		// ClearBuffer
		for (int i = 0; i < mod; i++) {
			loop[i] = 0;

I dont think you can use this for local variables.

The docs say:

Use the section attribute with global variables and not local variables, as shown in the example.

Maybe there are other ways to do what you want, but you’ll need someone with more C++/linker/ARM knowledge than me to tell you what they might be.


I see. I guess it will have to be a global variable. Thank you, that link is very helpful.

A workaround that I use for dealing with class members that should be in the SDRAM (large buffers, etc.) is to declare a pointer to an array float, and a size as part of the class, and pass those in during initialization time.

So In your class:

class loopChan {
  float *loop;
  size_t loop_size;

  void Init(float *loopmem, size_t size);

If you try to put that in your constructor as-is you may run into issues with the class trying to access and zero out your buffer before the SDRAM chip has been initialized since the constructors happen before the program reaches main().


Ok. That make sense. Thanks for flagging that potential error, I will work around that.
Im going to experiment with this method vs a global loop variable. Thank you!

1 Like