Skip to main content
Associate III
June 15, 2026
Solved

STM32N6 initializing JPEG causes HardFault

  • June 15, 2026
  • 3 replies
  • 66 views

Hi everyone

 

I have a bit trouble initializing the JPEG peripheral on the N6. See the stack trace:

 

 

I feel like this has something to do with the RIF? I don’t know, this chip is very new to me. If anyone can help me, it’d be greatly appreciated.

 

Best regards

Best answer by rphii

Okay, so I essentially fixed the initialization issue.

 

The Problem

In my case, I added the JPEG code to an existing application that made use of the NPU via. generated files from STM32Cube AI Studio. To make use of that generated code, I had to expand my linker script with the provided one by the AI Studio; so I basically expanded my MEMORY region, to match that of the generated .ld file:


/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x34000000, LENGTH = 0x100000
AXISRAM3_4_5_6 (xrw) : ORIGIN = 0x34270000, LENGTH = 0x0
ROM (xrw) : ORIGIN = 0x70100400, LENGTH = 0x6ffc00
EXTFLASH (rx) : ORIGIN = 0x70180000, LENGTH = 0x7e80000
}

/* Sections */
SECTIONS
{

/* Add Memory Area for AXIFLEXMEM */
.AI_AXIFLEXMEM (NOLOAD):
{
. = ALIGN(4);
KEEP(*(.AI_AXIFLEXMEM))
. = ALIGN(4);
} >RAM
/* Add Memory Area for AXISRAM1 */
.AI_AXISRAM1 (NOLOAD):
{
. = ALIGN(4);
KEEP(*(.AI_AXISRAM1))
. = ALIGN(4);
} >RAM
/* Add Memory Area for xSPI2 */
.AI_XSPI2 :
{
. = ALIGN(4);
KEEP(*(.AI_XSPI2))
. = ALIGN(4);
} >EXTFLASH
/* Add Memory Area for EXTFLASH */
.AI_EXTFLASH :
{
. = ALIGN(4);
KEEP(*(.AI_EXTFLASH))
. = ALIGN(4);
} >EXTFLASH

/* ... the rest of the ld file ... */

The Fix

I didn’t see that the generated .ld file also increased the _Min_Heap_Size and _Min_Stack_Size, so I additionally updated those:

_Min_Heap_Size = 2048; /* required amount of heap */
_Min_Stack_Size = 8192; /* required amount of stack */

 

3 replies

ST Technical Moderator
June 15, 2026

Hello ​@rphii 

Please refer to the article below to debug your Hardfault. 

How to debug a HardFault on an Arm® Cortex®-M STM32 | Community

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
rphiiAuthor
Associate III
June 15, 2026

Hi ​@Saket_Om 

 

Thanks for the suggestion, I will look into that. In the meantime, I tried to use the example ‘JPEG_EncodingFromOSPI_DMA’ and that also HardFaults at the same location… 

 

=> Which is because of my linker script, lol

rphiiAuthorBest answer
Associate III
June 15, 2026

Okay, so I essentially fixed the initialization issue.

 

The Problem

In my case, I added the JPEG code to an existing application that made use of the NPU via. generated files from STM32Cube AI Studio. To make use of that generated code, I had to expand my linker script with the provided one by the AI Studio; so I basically expanded my MEMORY region, to match that of the generated .ld file:


/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x34000000, LENGTH = 0x100000
AXISRAM3_4_5_6 (xrw) : ORIGIN = 0x34270000, LENGTH = 0x0
ROM (xrw) : ORIGIN = 0x70100400, LENGTH = 0x6ffc00
EXTFLASH (rx) : ORIGIN = 0x70180000, LENGTH = 0x7e80000
}

/* Sections */
SECTIONS
{

/* Add Memory Area for AXIFLEXMEM */
.AI_AXIFLEXMEM (NOLOAD):
{
. = ALIGN(4);
KEEP(*(.AI_AXIFLEXMEM))
. = ALIGN(4);
} >RAM
/* Add Memory Area for AXISRAM1 */
.AI_AXISRAM1 (NOLOAD):
{
. = ALIGN(4);
KEEP(*(.AI_AXISRAM1))
. = ALIGN(4);
} >RAM
/* Add Memory Area for xSPI2 */
.AI_XSPI2 :
{
. = ALIGN(4);
KEEP(*(.AI_XSPI2))
. = ALIGN(4);
} >EXTFLASH
/* Add Memory Area for EXTFLASH */
.AI_EXTFLASH :
{
. = ALIGN(4);
KEEP(*(.AI_EXTFLASH))
. = ALIGN(4);
} >EXTFLASH

/* ... the rest of the ld file ... */

The Fix

I didn’t see that the generated .ld file also increased the _Min_Heap_Size and _Min_Stack_Size, so I additionally updated those:

_Min_Heap_Size = 2048; /* required amount of heap */
_Min_Stack_Size = 8192; /* required amount of stack */