section type conflict

UHF

Well-known member
Hello I'm getting a section type conflict error when I compile on T4.1 : VELOCITY causes a section type conflict with CHORD_DETUNE_STR


If I add another declaration marked PROGMEM in one file, I get the conflict with the declaration in another.

In Velocity.h:
Code:
const static float VELOCITY[5][128] PROGMEM = {
  {1.0f, 1.0f, ................cut out.......................   1.00f, 1.00f}
};


In Detune.h:
Code:
const static String CHORD_DETUNE_STR[128] PROGMEM = {"Major", ..........cut out.............. "Oct - 1 - 2"};


Any help appreciated thanks.
 
Maybe you have more PROGMEM elsewhere in the same file? Just a blind guess, maybe you're also using PROGMEM on functions? (where you should use FLASHMEM only for functions and PROGMEM only for variables)
 
Yes, I've got more PROGMEMs. Adding another in Detune.h caused it. No PROGMEM on functions but I've got FLASHMEM on a number of functions in several files. Trying to allow more memory!
 
I ran into this as well once in some sample code I was doing. Not sure how I resolved it. I may have punted and removed the progmem... Or maybe I removed the word static...

Again I don't remember how I resolved it.
 
It'd be quite a miracle if anyone could figure this one out from only the info on this thread. If you want us to help more, you're going to have to show us the complete code.

Please consider the way we're albe to help falls into 3 broad categories. We can reproduce the problem, or we can see the problem even if we don't have enough code to reproduce it, or we can only guess the problem because we can't see enough of the info. So far, this is definitely into the guesswork range.

If you want better help, give us complete code we can copy it into Arduino and reproduce the error message.
 
Like KurtE, I have also run into this but can't remember which sketch or how I fixed it.

But this compiles:
velocity.h
Code:
const static float VELOCITY[2][5] PROGMEM = {
  {1.0f, 1.0f, 1.00f, 1.00f, 1.00f },
  {1.0f, 1.0f, 1.00f, 1.00f, 1.00f },
};

detune.h
Code:
const static String CHORD_DETUNE_STR[2] PROGMEM = {"Major", "Oct - 1 - 2"};

sketch
Code:
#include "velocity.h"
#include "detune.h"

void setup(void)
{
  Serial.begin(9600);
  while(!Serial);
  delay(1000);

  Serial.println(CHORD_DETUNE_STR[0]);
  Serial.printf("%8.3f\n",VELOCITY[0]);
}

void loop(void)
{
}

Pete
 
I downloaded the code and looked briefly. But when I try to find the place to add PROGMEM to reproduce the problem, I can't find "CHORD_DETUNE_STR" anywhere in the code. Looks like you changed it to CDT_STR and the data type is very different from what's been discussed on this thread.
 
I did manage to reproduce the error by adding PROGMEM to CDT_STR. To avoid the section type conflict, you need the pointers values to be const. As defined, the pointers point to const data, but the pointers themselves are not const. They could be changed at runtime to point to any other const char data. That is why the compiler is not willing to put your array into flash memory!

This is the definition you need:

Code:
static const char * const CDT_STR[128] PROGMEM = { /*....*/

The first "const" means the data the pointer references must not change. The pointer can't be used to alter whatever it points to. The second "const" means the pointer can never be changed to point to anything else. For placing the pointer in flash, this second const is what really matters.

However, this only places the array of pointers into flash memory. The string constants aren't necessarily in flash memory. To understand why, here's a small program to run.

Code:
static const char * const list[3] PROGMEM = {
  "test1", "test2", "test3"
};

void setup() {
  while (!Serial) ; // wait
  Serial.print("list[0] value is: ");
  Serial.println(list[0]);
  Serial.print("list[0] location is: ");
  Serial.println((int)list[0], HEX);
  Serial.print("list location is: ");
  Serial.println((int)list, HEX);
}

void loop() {
}

If you try this on Teensy 4.1, you'll see it prints this to the serial monitor:

list[0] value is: test1
list[0] location is: 20000014
list location is: 600019E4

The array of pointers is actually in flash memory (which starts at 60000000), but the string it points to is located in DTCM RAM (which starts at 20000000).

To get both the array of pointers and the strings they reference all into flash memory, you would need this much less convenient syntax:

Code:
static const char str0[] PROGMEM = "test1";
static const char str1[] PROGMEM = "test2";
static const char str2[] PROGMEM = "test3";

static const char * const list[3] PROGMEM = {
  str0, str1, str2
};

void setup() {
  while (!Serial) ; // wait
  Serial.print("list[0] value is: ");
  Serial.println(list[0]);
  Serial.print("list[0] location is: ");
  Serial.println((int)list[0], HEX);
  Serial.print("list location is: ");
  Serial.println((int)list, HEX);
}

void loop() {
}

Each string needs a PROGMEM to force it to be placed in flash memory. Then you can create the array of pointers and put that into flash memory too. For the array, the compiler just puts a list of memory addresses into the array. Even though the array definition has PROGMEM, that PROGMEM on the array doesn't have any effect actual memory address numbers which the compiler puts into the array. It only means the list itself will be put into flash. The addresses on the list could be anything. You could even have some of the pointers to strings in PROGMEM and other string in RAM. To get the strings themselves into flash, each one needs an explicit definition so you can use PROGMEM.
 
Hallo Paul

I used VS 2022 and vMicro with Teensy 4.1. I have many tables. VS show many errors with PROGMEM and const static float or const static uint16_t Errors. I don't know what's wrong!?

Code:
// Waveshaper Table-No: 0 (linear -1.0 - 1.0) 
const static float WAVESHAPER_TABLE1[3] = PROGMEM {
    -1.0, 0.0, 1.0
};

// Arbitrary Waveform Bank A
const static uint16_t PROGMEM ArbBankA[16384] = {
    0x00ca, 0x02dc, 0x04de, 0x06d5, 0x08e6, 0x0ad3, 0x0ce0, 0x0ed4,
    0x10cf, 0x12cc, 0x14c5, 0x16bb, 0x18ba, 0x1aaa, 0x1ca4, 0x1e99,
    0x208d, 0x2280, 0x2471, 0x2668, 0x284c, 0x2a44, 0x2c2a, 0x2e15,
...

);

VS error.jpg

I have no problems with Microchip Studio. Thanks for help. Greetings :)
 
Last edited:
Hallo Paul

I used VS 2022 and vMicro with Teensy 4.1. I have many tables. VS show many errors with PROGMEM and const static float or const static uint16_t Errors. I don't know what's wrong!?

Code:
// Waveshaper Table-No: 0 (linear -1.0 - 1.0) 
const static float WAVESHAPER_TABLE1[3] = PROGMEM {
    -1.0, 0.0, 1.0
};

// Arbitrary Waveform Bank A
const static uint16_t PROGMEM ArbBankA[16384] = {
    0x00ca, 0x02dc, 0x04de, 0x06d5, 0x08e6, 0x0ad3, 0x0ce0, 0x0ed4,
    0x10cf, 0x12cc, 0x14c5, 0x16bb, 0x18ba, 0x1aaa, 0x1ca4, 0x1e99,
    0x208d, 0x2280, 0x2471, 0x2668, 0x284c, 0x2a44, 0x2c2a, 0x2e15,
...

);

View attachment 27492

I have no problems with Microchip Studio. Thanks for help. Greetings :)

Sorry I am not Paul...

Hard to say for sure without seeing more code...

But it looks like you are passing in a pointer to a const object into a method/function that is not marked for const * object which compiler does not like.

Or another way to phrase it, you are passing something to the function that says I can not be changed, to a function that says I might change it...

Couple options:
Mark the method Shape to say that it is const....
Or cast the calls to say it is not const and hope it is as sketch will fault if you try to write to PROGMEM...
 
Haalo Kurt

Thanks for your nice support :)

I think I found the mistake. In my Waveshaper table, the value is defined as const static float. But the waveshape.shaper only expects float. So I defined the table values as static float. There are no more mistakes. But the question is whether the table is really in flash or in precious RAM :confused: i will check this. See you later! Rolf
 
Mmmm :confused:

PROGMEM is diffrent in VS 2020 and Microchip Studio.

VS 2022: const static float WAVESHAPER_TABLE2[129] PROGMEM= ... error
VS 2022: static float WAVESHAPER_TABLE2[129] PROGMEM= ... ok

MStudio: const static float WAVESHAPER_TABLE2[129] PROGMEM= ... build with "!"
MStudio: static float WAVESHAPER_TABLE2[129] PROGMEM= ... error
 
But the question is whether the table is really in flash or in precious RAM :confused:

You could cast the table address to uint32_t and print it to check. Maybe something like:

Serial.println((uint32_t)WAVESHAPER_TABLE2, HEX);


PROGMEM is diffrent in VS 2020 and Microchip Studio.

I hope you can understand I can really only answer regarding the software PJRC supplies, which is neither of these programs. Especially if you use software like Microchip Studio, which probably isn't even the same compiler, of course you can expect all sorts of different results. (are you even targeting Teensy with Microchip Studio, or some other hardware?)

Maybe you could use Arduino 1.8.19 with Teensyduino 1.56, if not for your project, to at least to verify how the officially supported software behaves?

If you are using VS using the Visual Micro software, and it gives different results than Arduino+Teensyduino, that would be an issue to bring up on the Visual Micro forum. As with this forum, and any forum, posting a small but complete program to demonstrate the problem is considers proper etiquette when reporting a compiler or toolchain problem.
 
I am working on a large synthesizer project with Teensy4.1 Board. Editing with Arduino Editor is very cumbersome. It's good for small projects. I am currently still working with Microchip Studio and would like to switch to Visual Studio 2020. VS it's a very comfortable editor ! I'm new to Visual Studio and have installed vMicro for Arduino.
 
I am working on a large synthesizer project with Teensy4.1 Board. Editing with Arduino Editor is very cumbersome. It's good for small projects. I am currently still working with Microchip Studio and would like to switch to Visual Studio 2020. VS it's a very comfortable editor ! I'm new to Visual Studio and have installed vMicro for Arduino.

Try using Visual Studio 2020 with VisualMicro
I use it all the time with Teensy.
 
Yes i do this ! The problem is the table pointer. Teensy waveshaper.shape expects float and my tables are in flash memory with PROGMEM types

Code:
//*************************************************************************
// set Waveshaper Table
//*************************************************************************
FLASHMEM void setWaveShaperTable(uint8_t tableNo) {


	// -1.0 - 1.0
	if (tableNo == 0) {
		waveshaper1.shape(WAVESHAPER_TABLE1,3);
		waveshaper2.shape(WAVESHAPER_TABLE1,3);
		waveshaper3.shape(WAVESHAPER_TABLE1,3);
		waveshaper4.shape(WAVESHAPER_TABLE1,3);
		waveshaper5.shape(WAVESHAPER_TABLE1,3);
		waveshaper6.shape(WAVESHAPER_TABLE1,3);
		waveshaper7.shape(WAVESHAPER_TABLE1,3);
		waveshaper8.shape(WAVESHAPER_TABLE1,3);	
	}
	// -0.5 - 0.5
	else if (tableNo == 1) {
		waveshaper1.shape(WAVESHAPER_TABLE2, 129);
		waveshaper2.shape(WAVESHAPER_TABLE2, 129);
		waveshaper3.shape(WAVESHAPER_TABLE2, 129);
		waveshaper4.shape(WAVESHAPER_TABLE2, 129);
		waveshaper5.shape(WAVESHAPER_TABLE2, 129);
		waveshaper6.shape(WAVESHAPER_TABLE2, 129);
		waveshaper7.shape(WAVESHAPER_TABLE2, 129);
		waveshaper8.shape(WAVESHAPER_TABLE2, 129);
	}
	// -0.3 - 0.3
	else if (tableNo == 2) {
		waveshaper1.shape(WAVESHAPER_TABLE3, 129);
		waveshaper2.shape(WAVESHAPER_TABLE3, 129);
		waveshaper3.shape(WAVESHAPER_TABLE3, 129);
		


// Waveshaper Table-No: 0 (linear -1.0 - 1.0) 
const static float PROGMEM WAVESHAPER_TABLE1[3] = {
	-1.0f, 0.0f, 1.0f
};


// Waveshaper Table-No: 1 (CLIP 0.8)
const static float PROGMEM WAVESHAPER_TABLE2[129] = {
	-0.8,
	-0.799759054956963,
	-0.799036364964138,
	-0.797832365342952,
	-0.796147781337758,
	-0.793983627678968,
	-0.791341207971825,
	-0.788222113911153,
 
The Arduino IDE has a "use external editor" feature in File > Preferences. In this mode, Arduino's editor shuts off and when you click Verify or Upload, it will notice any changes you have made to the files with your favorite editor.
 
When I started Arduino and Atmel Studio (Microchip Studio) I did like this. But after a long time it is a bit cumbersome and I used the plugin vMicro :)
 
I often use sublime-text to do most of my editing and building on Windows.

I use the TSET stuff of defragster and Frank, which sets up a batch file, that you can then choose the build commands and it will launch it using the same build process as Arduino (i.e. you point it to Arduino)...

It tries to locate the errors and position you to them...

Again if you are having something like:
const static float WAVESHAPER_TABLE1[3] = PROGMEM {

And you are passing it to a function like shape(WAVESHAPER_TABLE1);

And shape is defined something like:

Code:
void shape(float *table);

You will run into the error messages.
Bu if you do something like:
Code:
void shape(const float *table);

Then hopefully the errors disappear.
 
Hallo Kurt
Now it works in VS 2020 :eek: But Microchip Studio makes a build error :confused:

Code:
//************************************
// Waveshaper Table-No: 0 (linear -1.0 - 1.0)
//************************************

static float WAVESHAPER_TABLE1[3] PROGMEM = { 
    -1.0f, 0.0f, 1.0 f 
}; 


//************************************
// select waveshaper table
//******************** ***************
FLASHMEM void setWaveShaperTable(uint8_t tableNo) { 

    // -1.0 - 1.0 
    if (tableNo == 0) { 
        waveshaper1.shape(WAVESHAPER_TABLE1,3); 
        waveshaper2.shape (WAVESHAPER_TABLE1,3); 
        waveshaper3.shape (WAVESHAPER_TABLE1,3);
        waveshaper4.shape (WAVESHAPER_TABLE1,3); 
        waveshaper5.shape (WAVESHAPER_TABLE1,3); 
        waveshaper6.shape (WAVESHAPER_TABLE1,3); 
        waveshaper7.shape (WAVESHAPER_TABLE1,3); 
        waveshaper8.shape (WAVESHAPER_TABLE1,3);    
    }
 
Last edited:
I had the same error using DMAMEM on a Teensy 4.1. To fix the error I made sure all variables/arrays I had marked DMAMEM were also marked `static const`, and the error went away. Hope this helps someone!
 
Hi, I am also getting a section type error with the following code. Was asked to post this here

C-like:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <math.h>

#include <AMY-Arduino.h>
#include <MIDI.h>

MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, MIDI);

AudioPlayQueue           queue_l;
AudioPlayQueue           queue_r;
AudioOutputI2S           i2s1;
AudioConnection          patchCord1(queue_r, 0, i2s1, 1);
AudioConnection          patchCord2(queue_l, 0, i2s1, 0);
AudioControlSGTL5000     sgtl5000_1;     //xy=349.3333282470703,327.3333282470703

int16_t samples_l[AMY_BLOCK_SIZE];
int16_t samples_r[AMY_BLOCK_SIZE];

AMY amy;

void myHandleNoteOn(byte channel, byte note, byte velocity) {
  Serial.println(String("Note On:  ch=") + channel + ", note=" + note + ", velocity=" + velocity);
  // float a = 440;
  // float freq = (a / 32.0f) * pow(2, ((note - 9) / 12.0f));
  // waveform1.frequency(freq);
  struct event e = amy.default_event();
  strcpy(e.voices, "0");
  e.midi_note = note;
  e.velocity = (float)velocity/127.0;
  amy.add_event(e);
}

void myHandleNoteOff(byte channel, byte note, byte velocity) {
  Serial.println(String("Note Off:  ch=") + channel + ", note=" + note + ", velocity=" + velocity);
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  AudioMemory(10);
  queue_l.setMaxBuffers(4);
  queue_r.setMaxBuffers(4);

  amy.begin(/* cores= */ 1, /* reverb= */ 0, /* chorus= */ 0);


  sgtl5000_1.enable();
  sgtl5000_1.volume(0.32);

  MIDI.begin(MIDI_CHANNEL_OMNI);
  // Serial.begin(57600);
  Serial.println("MIDI Input Test");

  MIDI.setHandleNoteOn(myHandleNoteOn);
  MIDI.setHandleNoteOff(myHandleNoteOff);

  // Setup the voice with a Juno patch
  struct event e = amy.default_event();
  e.load_patch = 0; // Juno Patch 0
  strcpy(e.voices, "0");
  amy.add_event(e);
}

void loop() {
  int16_t * samples = amy.render_to_buffer();
  for(int16_t i=0;i<AMY_BLOCK_SIZE;i++) {
    samples_l[i] = samples[i*2];
    samples_r[i] = samples[i*2+1];
  }
  queue_l.play(samples_l, AMY_BLOCK_SIZE);
  queue_r.play(samples_r, AMY_BLOCK_SIZE);

  MIDI.read();

}


This gives the error
Code:
In file included from c:\Users\chris\Documents\Arduino\libraries\amy\src\patches.c:5:
c:\Users\chris\Documents\Arduino\libraries\amy\src\patches.c: In function 'patches_load_patch':
c:\Users\chris\Documents\Arduino\libraries\amy\src\patches.h:263:23: error: 'patch_oscs' causes a section type conflict with 'patch_commands'
  263 | const static uint16_t patch_oscs[256] PROGMEM = {
      |                       ^~~~~~~~~~
In file included from c:\Users\chris\Documents\Arduino\libraries\amy\src\patches.c:5:
c:\Users\chris\Documents\Arduino\libraries\amy\src\patches.h:5:21: note: 'patch_commands' was declared here
    5 | const static char * patch_commands[256] PROGMEM = {
      |                     ^~~~~~~~~~~~~~
 
Last edited:
Back
Top