Baremetal flashing not working in release for project referencing another project

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Baremetal flashing not working in release for project referencing another project

Jump to solution
2,646 Views
rvigneault
Contributor III

Hi!

We are trying to separate our baremetal sources into projects where the is one project containing our sources (let's call it application project) is referencing another project containing all the MCUXpresso SDK-generated for our MCU (MIMXRT1024CAG4A) and generating a library.

+-- Application project (generates an executable)
|
+-- MCUXpresso SDK project (generates a library)

The application project links to the library generated by the MCUXpresso SDK project and both use the same defines and the NewlibNano library.

The project only traces on the UART (we are using the UART for debug messages), the main, in the application project, being the following (almost identical to the one generated by default):

int main(void) {

    /* Init board hardware. */
    BOARD_ConfigMPU();
    BOARD_InitBootPins();
    BOARD_InitBootClocks();
    BOARD_InitBootPeripherals();
#ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL
    /* Init FSL debug console. */
    BOARD_InitDebugConsole();
#endif

    PRINTF("Hello "
#if defined(DEBUG)
    		"Debug "
#elif defined(NDEBUG)
    		"Release "
#endif
    		"World2\n");

    /* Force the counter to be placed into memory. */
    volatile static int i = 0 ;
    /* Enter an infinite loop, just incrementing a counter. */
    while(1) {
        if (i%10000000 == 0)
        {
        	PRINTF("%i\n",
        		   i);
        }
        i++ ;
        /* 'Dummy' NOP to allow source level single stepping of
            tight while() loop */
        __asm volatile ("nop");
    }
    return 0 ;
}

 This work well in debugging mode but when when attempting to flash the release mode image it does not work (i.e. no log is seen).

I tried to put all sources in one project and then it works in debugging and when flashing the release mode image.

What can be the problem with the release mode project separated in 2 projects?

Labels (1)
0 Kudos
Reply
1 Solution
2,094 Views
rvigneault
Contributor III

Hi @jingpan ,

So that means that we cannot put all the MCUXpresso SDK in a library when the executable is to be flashed as-is. The only project type that can be selected in that case when creating the project using the wizard is "C Project". "C Static Library" cannot be selected.

rvigneault_0-1688736428666.png

Thanks!

View solution in original post

0 Kudos
Reply
17 Replies
2,407 Views
rvigneault
Contributor III

Hi!

A thing I noticed today is that, for the files generated from the two-projects build, flashing the debug .axf file also does nothing (i.e. same behaviour than for the release build).

I tried, from the same workspace to flash the debug and release .axf files generated from the one-project build and it worked so it looks like the problem is in the generated file for the two-projects build and not in the workspace and/or flashing settings.

Thanks!

0 Kudos
Reply
2,538 Views
rvigneault
Contributor III

Hi!

Today I found out that, by comparing the map files of the "all sources project" with the one separated in 2 projects (application+MCUXpresso SDK projets) that the 2 projects does not have the following achive linked (and everything it links) in the first section:

c:/nxp/mcuxpressoide_11.7.1_9221/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.7.1.202301190959/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard\libc_nano.a(lib_a-malloc.o)
./drivers/fsl_common.o (malloc)

I had a look and I see that the SDK_Malloc function in fsl_common.c is compiled. I am wondering where it is supposed to be used so that the linker is not removing it.

Any idea?

Thanks!

0 Kudos
Reply
2,465 Views
rvigneault
Contributor III

OK so malloc does not seem to be an issue here since when I remove the SDK_Malloc fonction in the one-project build malloc is removed from the map file but the release build is still working.

0 Kudos
Reply
2,580 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @rvigneault ,

Is the project address same? What's the difference of the debug and release version?

 

Regards,

Jing

0 Kudos
Reply
2,542 Views
rvigneault
Contributor III

Hi @jingpan !

The paths for the projects related too each other are

CommonFolder/Application/ (contains Application project)
CommonFolder/Application/Debug/ (contains files generated when building in debug)
CommonFolder/Application/Release/ (contains files generated when building in debug)
CommonFolder/Application/Sources/ (contains application source files)

CommonFolder/McuxpressoSdkLibrary/ (contains MCUXpresso SDK project)
CommonFolder/McuxpressoSdkLibrary/Debug/ (contains files generated when building in debug)
CommonFolder/McuxpressoSdkLibrary/Release/ (contains files generated when building in release)
CommonFolder/McuxpressoSdkLibrary/*/ (folders generated from SDK - e.g. board, CMSIS, CMSIS_driver, component, etc.)

The executable is executed at default addresses (no configuration were changed related to that).

The only difference between debug and release should be the defines and should be the same for all projects.

Comparing all options, I see this difference:

Debug             Release
-DDEBUG -DNDEBUG
-O0 -Os
-g3 -g
-fmerge-constants

 All options for Application project.

Debug (I replaced spaces by line-change to ease reading:

-std=c17
-DCPU_MIMXRT1024CAG4A
-DCPU_MIMXRT1024CAG4A_cm7
-DSDK_OS_BAREMETAL
-DSERIAL_PORT_TYPE_UART=1
-DSDK_DEBUGCONSOLE=1
-DSDK_DEBUGCONSOLE_UART
-DXIP_EXTERNAL_FLASH=1
-DXIP_BOOT_HEADER_ENABLE=1
-D__MCUXPRESSO
-D__USE_CMSIS
-DDEBUG
-D__NEWLIB__
-I"<abolutePath>\Bootloader\Bootloader\Sources"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\board"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\CMSIS"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\CMSIS_driver"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\component\lists"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\component\serial_manager"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\component\uart"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\device"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\drivers"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\utilities"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\xip"
-O0
-fno-common
-g3
-Wall
-c
-ffunction-sections
-fdata-sections
-ffreestanding
-fno-builtin
-fmerge-constants
-fmacro-prefix-map="$(<D)/"=
-mcpu=cortex-m7
-mfpu=fpv5-d16
-mfloat-abi=hard
-mthumb
-D__NEWLIB__
-fstack-usage
-specs=nano.specs

 Release:

-std=c17
-DCPU_MIMXRT1024CAG4A
-DCPU_MIMXRT1024CAG4A_cm7
-DSDK_OS_BAREMETAL
-DSERIAL_PORT_TYPE_UART=1
-DSDK_DEBUGCONSOLE=1
-DSDK_DEBUGCONSOLE_UART
-DXIP_EXTERNAL_FLASH=1
-DXIP_BOOT_HEADER_ENABLE=1
-D__MCUXPRESSO
-D__USE_CMSIS
-DNDEBUG
-D__NEWLIB__
-I"<abolutePath>\Bootloader\Bootloader\Sources"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\board"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\CMSIS"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\CMSIS_driver"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\component\lists"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\component\serial_manager"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\component\uart"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\device"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\drivers"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\utilities"
-I"<abolutePath>\Bootloader\McuxpressoSdkLibrary\xip"
-Os
-fno-common
-g
-Wall
-c
-ffunction-sections
-fdata-sections
-ffreestanding
-fno-builtin
-fmacro-prefix-map="$(<D)/"=
-mcpu=cortex-m7
-mfpu=fpv5-d16
-mfloat-abi=hard
-mthumb
-D__NEWLIB__
-fstack-usage
-specs=nano.specs

 I hope this helps,

Thanks!

0 Kudos
Reply
2,481 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @rvigneault ,

Here is a guide of creating to a library project. You can refer to it.

https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/Creating-and-Linking-to-Library-Projects/m-p/469212

 

Regards,

Jing

0 Kudos
Reply
2,467 Views
rvigneault
Contributor III

Hi @jingpan !

I tried both ways mentioned in the link (liblinks.xml and manual links) and it I get the same result than before.

Thanks!

0 Kudos
Reply
2,434 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @rvigneault ,

Or you can refer to the examples in MCUXpressoIDE_11.7.1_9221\ide\Examples\Flashdrivers\NXP\iMXRT. These project is divided into two part, a library and an application.

 

Regards,

Jing 

0 Kudos
Reply
2,355 Views
rvigneault
Contributor III

Hi @jingpan !

To be sure that I did everything right, because I had to do many things to be able to compile, here is what I needed to do to be able to build an example (I used iMXRT1020_QSPI since it was the one with the closest MCU model to ours):

  1. Import the projects
    1. File --> Import...
    2. General --> Existing Projects into Workspace
    3. Next
    4. Select root directory and select the directory containing the iMXRT1020_QSPI and LPCXFlashDriverLib folders.
    5. Check both iMXRT1020_QSPI and LPCXFlashDriverLib projects.
    6. Finish.
  2. Select the build configuration:
    1. Right-click iMXRT1020_QSPI in the Project Explorer
    2. Build configurations --> Set Active --> MIMXRT1020-EVK_IS25LP064
  3. Right-click the liblinks.xml file in the LPCXFlashDriverLib project
    1. Smart update --> Smart update
    2. Select projects to update: select iMXRT1020_QSPI
  4. Add references:
    1. Right-click iMXRT1020_QSPI in the Project Explorer
    2. Properties
    3. C/C++ General --> Paths and Symbols --> References
    4. Select LPCXFlashDriverLib --> Release
    5. Apply and Close
  5. Fix Library search path:
    1. Right-click iMXRT1020_QSPI in the Project Explorer
    2. Properties
    3. C/C++ Build --> Settings --> MCU Linker --> Libraries
    4. In Libraries, change FlashDriverLib for LPCXFlashDriverLib.
    5. In Library search path, change "${workspace_loc:/FlashDriverLib/Release}" for "${workspace_loc:/LPCXFlashDriverLib/Release}"
  6. Build:
    1. Project --> Build All

Is anything wrong or missing with what I did?

I can't run this on my target (can I if I do modifications?) though so I can just assume everything is right, which seems a bit special since I had to do many manipulations to make this compile right.

Thanks!

0 Kudos
Reply
2,331 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @rvigneault ,

Just compile  LPCXFlashDriverLib in release mode. Don't change anything else. Compile the iMXRT1020_QSPI project in debug mode.

 

Regards,

Jing

0 Kudos
Reply
2,317 Views
rvigneault
Contributor III

Thanks @jingpan !

It compiles but I cannot flash it because the target is not the same MCU than we use (i.MX RT1024).

I modified my project to fit to its configuration without success.

I am sending you my projects in case you can see something.

Note that we are redirecting printf to UART3.

When starting the .axf in debug mode it starts (the application can be compiled using debug or release build - both work) but when flashing using the GUI Flash Tool the application does not start (again, may it be compiled using debug or release build it gives the same behaviour).

When using one project to contain all the sources, the GUI Flash Tool works but we need to reset the MCU (e.g. remove and put back power) for it to run.

All projects are created using the SDK Wizard for MIMXRT1024xxxxx (SDK 2.13.0) with no board.

Thanks!

0 Kudos
Reply
2,215 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @rvigneault ,

I guess your image is lack of header data, such as FCB/IVT. So it can't boot by ROM.

 

Regards,

Jing 

0 Kudos
Reply
2,159 Views
rvigneault
Contributor III

Hi @jingpan ,

Where should I look for this?

I can't find "Firmware Configuration Block" nor IVT nor "Image Vector Table" in the MCUXpresso IDE help and the only place I find FCB is in the following sentence where I assume it is not for the same thing: "The tool is available for all SEMC and FCB peripheralsand can be used after selecting these peripherals from the list in the Peripheralsview.".

Another question: shouldn't the FCB and IVT be correctly generated by projects created using the SDK wizard?

Thanks!

0 Kudos
Reply
2,126 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @rvigneault ,

Please see the evkmimxrt1020_flexspi_nor_config.c and fsl_flexspi_nor_boot.c. When you change linker script or address, they may disappear from linker file.

 

Regards,

Jing

0 Kudos
Reply
2,115 Views
rvigneault
Contributor III

Hi @jingpan !

We did not modify the linker scripts that are automatically generated by MCUXpresso IDE (i.e. "Manage linker script" is checked in MCU Linker-->Managed Linker Script). When comparing the generated *.ld files from the two-projects build and the one-project build (i.e. working one) they are the same (only the generation date in the comment is different).

In the 2-project build, I tried to move the xip-related MCUXpresso SDK files from the library project to the application project and the flashed file is started when unplugging and replugging alimentation! Again, the generated .ld files are identical excluding the date.

This leads me to this question: is there a way to use sections from a library while linking the executable?

Thanks!

0 Kudos
Reply
2,102 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @rvigneault ,

It seems couldn't. You can put these data in your second project.

 

Regards,

Jing

0 Kudos
Reply
2,095 Views
rvigneault
Contributor III

Hi @jingpan ,

So that means that we cannot put all the MCUXpresso SDK in a library when the executable is to be flashed as-is. The only project type that can be selected in that case when creating the project using the wizard is "C Project". "C Static Library" cannot be selected.

rvigneault_0-1688736428666.png

Thanks!

0 Kudos
Reply