Compile errors with core_cmFunc.h

Status
Not open for further replies.

Burdalfis

Member
So! I'm porting codec2 over to work on the teensy, and it's moving along, but I have finally encountered an error that no amount of googling can solve.

Here is where I am right now. Codec2 uses FFTs to compress audio, so it uses core_cm4.h. For some reason, core_cm4.h tries to include core_cmFunc.h, but it doesn't exist. No worries, downloaded it, put it in the teensy3 folder, and hit compile. But, it's giving me another error.

Code:
In file included from /home/velo/arduino-1.8.5/hardware/teensy/avr/cores/teensy3/core_cm4.h:155:0,
                 from /tmp/arduino_build_452940/sketch/codec2_fft.h:19,
                 from /tmp/arduino_build_452940/sketch/quantise.h:29,
                 from /tmp/arduino_build_452940/sketch/pack.c:19,
                 from /root/Arduino/SerialAudio/SerialAudio.ino:4:
/home/velo/arduino-1.8.5/hardware/teensy/avr/cores/teensy3/core_cmFunc.h:278:74: error: macro "__enable_irq" passed 1 arguments, but takes just 0
 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void)
                                                                          ^
/home/velo/arduino-1.8.5/hardware/teensy/avr/cores/teensy3/core_cmFunc.h:288:75: error: macro "__disable_irq" passed 1 arguments, but takes just 0
 __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void)

I've tried commenting it out, but it gives me another mish mosh of errors, I don't know if they're related or not.

Code:
In file included from /tmp/arduino_build_452940/sketch/codec2_fft.h:19:0,
                 from /tmp/arduino_build_452940/sketch/quantise.h:29,
                 from /tmp/arduino_build_452940/sketch/pack.c:19,
                 from /root/Arduino/SerialAudio/SerialAudio.ino:4:
/home/velo/arduino-1.8.5/hardware/teensy/avr/cores/teensy3/core_cm4.h:1452:37: error: variable or field 'NVIC_EnableIRQ' declared void
 __STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)

                                     ^
/home/velo/arduino-1.8.5/hardware/teensy/avr/cores/teensy3/core_cm4.h:1452:37: error: 'IRQn_Type' was not declared in this scope
/home/velo/arduino-1.8.5/hardware/teensy/avr/cores/teensy3/core_cm4.h:1465:38: error: variable or field 'NVIC_DisableIRQ' declared void
 __STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)

                                      ^
/home/velo/arduino-1.8.5/hardware/teensy/avr/cores/teensy3/core_cm4.h:1465:38: error: 'IRQn_Type' was not declared in this scope
/home/velo/arduino-1.8.5/hardware/teensy/avr/cores/teensy3/core_cm4.h:1481:45: error: 'NVIC_GetPendingIRQ' declared as an 'inline' variable
 __STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)

                                             ^

And many more errors after that, all very similar to what I show here.
 
Good idea, my core_cm4.h & core_cmFunc.h are attached below, as well as a zip of the whole project.

It seems that your sketch uses 'arm_cfft_f32' which is AFAIK not supported by teensy cores. So, a lot of definitions are missing, or are incompatible.
What I have done is it create my own CMSIS library where I copied the files needed from CMSIS (e.g. arm_cfft_f32).

In order to overwrite the core arm_math.h include
I use a helper h-file
Code:
#ifndef CMSIS_H_
#define CMSIS_H_

#include "arm_math.h"
#include "arm_const_structs.h"

#endif /* CMSIS_H_ */
that is included in this private library and therefore takes precedence to the cores includes
 
Aha! That'd do it! I genuinely appreciate you going through my code to figure out what's up.

I know the source code had features to run on an ARM Cortext M4, which is the type of chip the Teensy 3.X has, but the intended chip is the STM32F030x8.

I assume I need to install CMSIS to compile this?
 
Aha! That'd do it! I genuinely appreciate you going through my code to figure out what's up.

I know the source code had features to run on an ARM Cortext M4, which is the type of chip the Teensy 3.X has, but the intended chip is the STM32F030x8.

I assume I need to install CMSIS to compile this?

I simply downloaded the CMSIS https://github.com/ARM-software/CMSIS_5 package and copied the required functions and includes from there to my local library.
I do not recall if I did some further editing on header files, but if you run into compile problems, let us know.

There are other attempts reported on this forum on how to integrate CMSIS_5 into teensyduino. Message is, it can easily be done.
 
I've downloaded the CMSIS source code, and whenever I get an "undeclared" error I use grep to find what file defines it, and copy it over. I've copied arm_common_tables.h&c, arm_const_structs.h&c, arm_math.h, arm_cfft_f32.c, arm_cfft_q31.c, arm_cfft_q15.c so far, I know I'll need a few more, but I just cannot get rid of this error:

Code:
arm_const_structs.c:45: error: unknown type name 'arm_cfft_instance_f32'
 const arm_cfft_instance_f32 arm_cfft_sR_f32_len16 = {

No matter how I edit the files or change the order of how I'm including my files, I can't fix it. I'll admit, I'm above my knowledge here, in a bit over my head. I like to think I'm okay with C code, I am terrible with C++, and includes with arduino. Including files in regular C code for my linux machine is fine, but arduino seems to be way crankier about them. Note that I have many many other errors too, but one at a time I guess. The one I posted is the first error in the list.
 
I've downloaded the CMSIS source code, and whenever I get an "undeclared" error I use grep to find what file defines it, and copy it over. I've copied arm_common_tables.h&c, arm_const_structs.h&c, arm_math.h, arm_cfft_f32.c, arm_cfft_q31.c, arm_cfft_q15.c so far, I know I'll need a few more, but I just cannot get rid of this error:

Code:
arm_const_structs.c:45: error: unknown type name 'arm_cfft_instance_f32'
 const arm_cfft_instance_f32 arm_cfft_sR_f32_len16 = {

No matter how I edit the files or change the order of how I'm including my files, I can't fix it. I'll admit, I'm above my knowledge here, in a bit over my head. I like to think I'm okay with C code, I am terrible with C++, and includes with arduino. Including files in regular C code for my linux machine is fine, but arduino seems to be way crankier about them. Note that I have many many other errors too, but one at a time I guess. The one I posted is the first error in the list.

where did you copy the files?
it may be that the compiler looks for the wrong arm_math.h
to test this simply change extension (in teensy3/core) arm_math.h to arm_math.ho
 
Ah! Progress! Kind of. I'm kinda back to square one, but you were absolutely right about the arm_math.h directory, I was just copying it to the sketch folder, but I threw it into the teensy3 folder and it seemed to take it just fine. I also copied core_cm4.h, and cmsis_gcc.h, it hasn't said I'm missing cmsis_compiler.h so I have yet to copy that. But, I now have the same issue with the cmsis_gcc.h file than I did with the core_cmFunc.h file in my OP.

Code:
/home/velo/arduino-1.8.5/hardware/teensy/avr/cores/teensy3/cmsis_gcc.h:58:74: error: macro "__enable_irq" passed 1 arguments, but takes just 0
 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void)

                                                                          ^
/home/velo/arduino-1.8.5/hardware/teensy/avr/cores/teensy3/cmsis_gcc.h:69:75: error: macro "__disable_irq" passed 1 arguments, but takes just 0
 __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void)
 
I would not copy all the files into cores/teensy3
I would create my own library in the Arduino sketch folder say ./libraries/myCMSIS and copy all files into it. (removing all but original CMSIS core files)

Anyhow, I have in cmsis_gcc around line 70
Code:
  // following are macros in kinetis.h
#undef __enable_irq
#undef __disable_irq

So, I DID edit the include files (I did it 1 year ago)
 
Sigh. Seems like it's going in circles, I've added the code you suggested, that fixed the previous error, but it needed core_cmSimd.h, so I copied that over, and that gave me even more errors. All redefinitions of the built in teensy asm commands, like NOP and the like. So I commented all the conflicts out in the core_cmSmid.h file. But now I'm getting the same error I got earlier:

Code:
arm_const_structs.c:45: error: unknown type name 'arm_cfft_instance_f32'
 const arm_cfft_instance_f32 arm_cfft_sR_f32_len16 = {

I have yet to copy the extra CMSIS files back to my sketch folder, but once we get over this issue, I'll implement whatever fix it is, compile, and then move the files, and compile again to see if I've screwed something up. I'm not too worried about breaking my teensy install, I was running it stock anyways and I can make multiple arduino installs, one for this project and another for everything else for instance.

I really appreciate your patience and assistance with this, it's a huge help.
 
IMO,
the best thing is NOT to break teensy core, as there are consistencies to be maintained with standard teensy libraries.
I would revert to original teensy install
and maybe as a start download my own local cmsis-library https://github.com/WMXZ-EU/wmxzDSP and place it under local Arduino/libraries
maybe it compiles.
I not please give also traceback of error (which routine the compiler was working on)
 
Alrighty, so I've done a clean install of arduino & teensy core, and I downloaded your library.

I had to get core_cmFunc.h, and comment a ton of ASM declares out of cmsis_gcc.h from your library, but I am still getting similar issues. I did test all of your examples, and they compiled just fine out of the box.

Here is the error window in it's entirety:

Code:
In file included from /tmp/arduino_build_372034/sketch/codec2.c:36:0:
codec2_fft.h:44: error: unknown type name 'arm_rfft_fast_instance_f32'
       arm_rfft_fast_instance_f32* instance;
       ^
codec2_fft.h:51: error: unknown type name 'arm_cfft_instance_f32'
         const arm_cfft_instance_f32* instance;
               ^
codec2_fft.h: In function 'codec2_fftr':
codec2_fft.h:65: warning: implicit declaration of function 'arm_rfft_fast_f32' 
     arm_rfft_fast_f32(cfg->instance,in,(float*)out,cfg->inverse);
     ^
codec2_fft.h: In function 'codec2_fft':
codec2_fft.h:93: error: request for member 'fftLen' in something not a structure or union
     memcpy(out,in,cfg->instance->fftLen*2*sizeof(float));
                                ^
codec2_fft.h:94: warning: implicit declaration of function 'arm_cfft_f32' 
     arm_cfft_f32(cfg->instance,(float*)out,cfg->inverse,0);
     ^
codec2_fft.h:102: warning: implicit declaration of function 'arm_scale_f32' 
         arm_scale_f32((float*)out,cfg->instance->fftLen,(float*)out,cfg->instance->fftLen*2);
         ^
codec2_fft.h:102: error: request for member 'fftLen' in something not a structure or union
         arm_scale_f32((float*)out,cfg->instance->fftLen,(float*)out,cfg->instance->fftLen*2);
                                                ^
codec2_fft.h:102: error: request for member 'fftLen' in something not a structure or union
         arm_scale_f32((float*)out,cfg->instance->fftLen,(float*)out,cfg->instance->fftLen*2);
                                                                                  ^

EDIT: Just saw your second post, do you want it in it's current form? I've removed a few CMSIS includes from the sketch folder since your library seems to have them included.
 
Last edited:
I'm trying myself with your seralAudio sketch.
will report if I succeed to compile

OK,
I opened serialAudio in Arduino, removed the arm_const_structs.h file
inserted #include "cmsis.h" IN FRONT of #include "Audio.h"
I edited codec2_fft.h
Code:
#ifdef ARM_MATH_CM4
  //#include "stm32f4xx.h"
#include "cmsis.h"
//  #include "core_cm4.h"
//  #include "arm_math.h"
//  #include "arm_const_structs.h"
#endif

Audio.h includes arm_math.h which does not include all arm structures and inhibits successive calls to arm_math.h
The cmsis.h is defined in my own DSP libray and provides a local link to f32 CMSIS routines

compiled with success
but link failed due to missing OS function (stm32?)

I hope this helps to move on
 
Aw jeez, I guess it helps when you actually include the library you need. I've done the edits you did, and I am getting errors, but it seems to get a lot further,

Do these errors line up with what you got?

Code:
In file included from /root/Arduino/libraries/wmxzDSP-master/src/cmsis_compiler.h:48:0,
                 from /root/Arduino/libraries/wmxzDSP-master/src/core_cm4.h:160,
                 from /root/Arduino/libraries/wmxzDSP-master/src/arm_math.h:309,
                 from /root/Arduino/libraries/wmxzDSP-master/src/cmsis.h:11,
                 from /root/Arduino/SerialAudio/SerialAudio.ino:2:
/root/Arduino/libraries/wmxzDSP-master/src/cmsis_gcc.h:850:1: warning: multi-line comment [-Wcomment]
 //#if ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
 ^
In file included from /root/Arduino/SerialAudio/SerialAudio.ino:10:0:
/tmp/arduino_build_372034/sketch/defines.h:45:0: warning: "TWO_PI" redefined
 #define TWO_PI     6.283185307 /* mathematical constant                */
 ^
In file included from /home/velo/arduino-1.8.5/hardware/teensy/avr/cores/teensy3/WProgram.h:45:0,
                 from /home/velo/arduino-1.8.5/hardware/teensy/avr/cores/teensy3/Arduino.h:3,
                 from /tmp/arduino_build_372034/sketch/SerialAudio.ino.cpp:1:
/home/velo/arduino-1.8.5/hardware/teensy/avr/cores/teensy3/wiring.h:97:0: note: this is the location of the previous definition
 #define TWO_PI 6.283185307179586476925286766559
 ^
/tmp/arduino_build_372034/sketch/codec2_fft.c.o: In function `codec2_fftr_alloc':
/tmp/arduino_build_372034/sketch/codec2_fft.c:109: undefined reference to `arm_rfft_fast_init_f32'
/tmp/arduino_build_372034/sketch/newamp1.c.o: In function `rate_K_mbest_encode':
/tmp/arduino_build_372034/sketch/newamp1.c:177: undefined reference to `newamp1vq_cb'
/tmp/arduino_build_372034/sketch/newamp1.c:177: undefined reference to `newamp1_energy_cb'
Multiple libraries were found for "SD.h"/tmp/arduino_build_372034/sketch/quantise.c.o: In function `lsp_bits':

/tmp/arduino_build_372034/sketch/quantise.c:65: undefined reference to `lsp_cb'
 Used: /root/Arduino/libraries/SD/tmp/arduino_build_372034/sketch/quantise.c.o: In function `lspd_bits':

 Not used: /home/velo/arduino-1.8.5/hardware/teensy/avr/libraries/SD/tmp/arduino_build_372034/sketch/quantise.c:69: undefined reference to `lsp_cbd'

/tmp/arduino_build_372034/sketch/quantise.c.o: In function `mel_bits': Not used: /home/velo/arduino-1.8.5/libraries/SD

/tmp/arduino_build_372034/sketch/quantise.c:74: undefined reference to `mel_cb'
/tmp/arduino_build_372034/sketch/quantise.c.o: In function `lspmelvq_cb_bits':
/tmp/arduino_build_372034/sketch/quantise.c:78: undefined reference to `lspmelvq_cb'
/tmp/arduino_build_372034/sketch/quantise.c.o: In function `lsp_pred_vq_bits':
/tmp/arduino_build_372034/sketch/quantise.c:89: undefined reference to `lsp_cbjvm'
/tmp/arduino_build_372034/sketch/quantise.c.o: In function `encode_lspds_scalar':
/tmp/arduino_build_372034/sketch/quantise.c:205: undefined reference to `lsp_cbd'
/tmp/arduino_build_372034/sketch/quantise.c.o: In function `lspmelvq_mbest_encode':
/tmp/arduino_build_372034/sketch/quantise.c:659: undefined reference to `lspmelvq_cb'
/tmp/arduino_build_372034/sketch/quantise.c.o: In function `quantise':
/tmp/arduino_build_372034/sketch/quantise.c:133: undefined reference to `lsp_cb'
/tmp/arduino_build_372034/sketch/quantise.c:129: undefined reference to `mel_cb'
/tmp/arduino_build_372034/sketch/quantise.c.o: In function `find_nearest_weighted':
/tmp/arduino_build_372034/sketch/quantise.c:492: undefined reference to `lsp_cbjvm'
/tmp/arduino_build_372034/sketch/quantise.c.o: In function `encode_WoE':
/tmp/arduino_build_372034/sketch/quantise.c:1994: undefined reference to `ge_cb'
collect2: error: ld returned 1 exit status
Error compiling for board Teensy 3.2 / 3.1.
 
Aw jeez, I guess it helps when you actually include the library you need. I've done the edits you did, and I am getting errors, but it seems to get a lot further,

Do these errors line up with what you got?

Yes, that is what I get (OK they are still compile errors and not link errors)
there is one routine missing 'arm_rfft_fast_init_f32' (Which I'm not using) so you should copy that
Some warnings that can be handled or ignored
and undefined references that seem to be sketch specific (missing code book? etc)
 
Yep! Copied over my arm_rfft_fast_init_f32 and that's all fixed, and you were spot on about the codebooks. However, the codebook files don't share the same variable names, and there are different codebook files. I'm going to have another look tomorrow, I've been awake for 20 hours now so I'm pretty out of it. Productivity has definitely fallen. But, if you can gleam anything from this, it'd be great. I've attached a zip of the codebooks, they are all apparently used by "quantise.c", judging by the errors.

View attachment codebook.zip
 
Yep! Copied over my arm_rfft_fast_init_f32 and that's all fixed, and you were spot on about the codebooks. However, the codebook files don't share the same variable names, and there are different codebook files. I'm going to have another look tomorrow, I've been awake for 20 hours now so I'm pretty out of it. Productivity has definitely fallen. But, if you can gleam anything from this, it'd be great. I've attached a zip of the codebooks, they are all apparently used by "quantise.c", judging by the errors.

I copied the codebooks and most errors disappeared
still missing are
-codebookmel.c
-codebooklspmelvq.c

that are to be generated with ?CMake? (see CMakeLists.txt in codec2/src as found on some github)
 
Last edited:
Aha! I got it! I copied over all the codebook files, even though there are no references to the variables used in the codebooks, or in quantise.c. But alas, it compiles! Whether it works or not is another story, but it compiled. Only one problem, it compiles into 299428 bytes of program memory, even when I've got it on the smallest code optimization setting. So it won't fit in my teensy 3.2s, so I guess that's a good excuse to get the new teensy 3.5 or 3.6! Thanks so much for your help!
 
Status
Not open for further replies.
Back
Top