cancel
Showing results for 
Search instead for 
Did you mean: 

Undeclared Identifier CoreDebug for STM32f446

JRodg.13.259
Associate III

I am creating a new project for STM32F446, and trying to access the CoreDebug registers. I am including the device header....

 

 

#include "cmsis_os2.h"                   // ARM::CMSIS:RTOS:Keil RTX
#include "Board_LED.h"                  // ::Board Support:LED
#include "Board_Buttons.h"              // ::Board Support:Buttons
#include "stm32f4xx.h"                  // Device header

 

 

 

In main I try and access CoreDebug:

 

 

int main (void) {
    if( CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk )
        {
            // Debugger is connected
        }

 

 

But I get a comiler error:

RTX_Blinky.c(92): error: use of undeclared identifier 'CoreDebug'
92 | if( CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk )

RTX_Blinky.c(92): error: use of undeclared identifier 'CoreDebug_DHCSR_C_DEBUGEN_Msk'
92 | if( CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk )

This may seem simple, but I have got to here as I am trying to use EventRecorder in an RTOS2 Keil RTX5 project, and so also getting similar errors for the eventrecorder, but trying to solve the simple case hoping it will lead to solving the EventRecorder problems:

C:/Users/cider/AppData/Local/Arm/Packs/Keil/ARM_Compiler/1.7.2/Source/EventRecorder.c(1063): error: use of undeclared identifier 'CoreDebug'
1063 | CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
| ^
C:/Users/cider/AppData/Local/Arm/Packs/Keil/ARM_Compiler/1.7.2/Source/EventRecorder.c(1063): error: use of undeclared identifier 'CoreDebug_DEMCR_TRCENA_Msk'
1063 | CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;

 

I see that Evebt Recorder uses: #include CMSIS_device_header

And so I checked that in RTE_Components.h that we have: #define CMSIS_device_header "stm32f4xx.h"

I have been through all the Options for Target, checking to see if I need to turn something on etc. Been looking at this for a few hours now, and also Googled CoreDebug etc and found the reference in the 

I have checked that they exist in this micro in the STM32f446 reference manual:

image.png

Tearing my hear out over what should be something very simple that I am not seeing!

Thanks for any help in advance!

6 REPLIES 6
TDK
Guru

CoreDebug is defined in core_cm4.h which is included from stm32f446xx.h provided you have the correct define set up for your processor. Should be a definition of STM32F446xx or similar.

If you feel a post has answered your question, please click "Accept as Solution".
JRodg.13.259
Associate III

Thank you for your response TDK. I do have core_cm4.h...

 

image.png

But it does not include 'CoreDebug' - I can see the register definitions, but different from the code sample I posed above, and as what is used in EventRecorder.c :

if( CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk )

Where as in my core_cm4 I have the debug enable mask defined as: 

#define DCB_DHCSR_C_DEBUGEN_Pos 0U /*!< DCB DHCSR: Debug enable control Position */
#define DCB_DHCSR_C_DEBUGEN_Msk (1UL /*<< DCB_DHCSR_C_DEBUGEN_Pos*/) /*!< DCB DHCSR: Debug enable control Mask */

so the core_cm4.h that I have is not using the 'CoreDebug...' syntax that is being used by EventRecorder.c. I searched for @CoreDebug' in the core_cm4.h file, there were no matches, as can be seen in the above screenshot.

Thanks for any help you can give, I am tearing what's left of my hair out!

JRodg.13.259
Associate III

Also just found this relating to different cores:

JRodg13259_0-1704729628720.png

But should I change my readonly files EventRecorder.c? I am not sure how you even go about changing a readonly file, do I have to do it outside the IDE?

 

TDK
Guru

The CoreDebug definition is in the latest core_cm4.h file in the Cube repository.

https://github.com/STMicroelectronics/STM32CubeF4/blob/5983d9348e9b0c230cbe9cd2170159675f8753c6/Drivers/CMSIS/Include/core_cm4.h#L1566

I don't know where your file came from, but if it doesn't have CoreDebug, and you need it, update your library files to the latest version.

Typically this requires replacing all files, but it's possible you can get away with only replacing core_cm4.h.

If you feel a post has answered your question, please click "Accept as Solution".
JRodg.13.259
Associate III

Thank you again TDK. I was trying to avoid using the STMcube or MX at all. and so this is the file provided by ARM/Keil : C:\Users\myuser\AppData\Local\Arm\Packs\ARM\CMSIS\6.0.0\CMSIS\Core\Include\core_cm4.h

It's bad form that there are such differences between the two versions!

I'll go and make a CubeMX project and then add in the RTX5 from Keil once I set up the project, and let you know how I get on.

JRodg.13.259
Associate III

I have now uninstalled MDK539 and all its packs etc and went back to MDK538a. There I can copy the example project for the nucleo board I have, and change over to RTOS2 and in the RTE select the EventRecorder and not it will compile ok!

C:\Users\cider\AppData\Local\Arm\Packs\ARM\CMSIS\5.9.0\CMSIS\Core\Include\core_cm4.h from CMSIS 5.9 contains:

JRodg13259_0-1704736702766.png

So it seems that Arm/Keil are moving from CoreDebug to DCB from thier move from CMSIS 5.9 to 6, but the EventRecorder.c is still looking for CoreDebug!