We are filling up RAM with predefined value (0xDF) after RAM initialization in startup. But as we enable the SVC interrupt for illegal opcode, it gives hard fault interrupt and even if we do not fill up RAM with 0xDF, it gives exception.
Is there any way/sequence to initialize RAM for illegal opcode? How do we debug this issue?
Target MCU - S32K142
S32DS Version - 2.0
SDK version - 0.8.4
Hello Sandip,
Sorry for the late response. If I understood correctly, the hard fault occurs once you install and initialize the SVC interrupt, correct? Where are you calling the function INT_SYS_InstallHandler? Please keep in mind that before calling this function, the RAM memory should be initialized, did you considered this?
I recommend you to take a look at the following community document where one of my coworkers explains how to fill the unused memory.
Hope it helps!
Victor
Hi Victor,
The function INT_SYS_InstallHandler is called in main function after startup.
How do we ensure that RAM memory initialized properly?
I am unable to access community document.
Best Regards,
Sandip
Hello Sandip,
This is a quick post about an interesting thread shared on Kinetis community, this is also applicable for S32DS + S32K1xx, following the below steps, we can fill up the unused memory with any command/data we want. On the other hand, ARM devices have the opcode feature to generate an SVC_Handler (0xDFDF ). So, if R13 goes to an unexpected address and this random address has 0xDFDF there, the CPU will jump to this SVC function. When using this feature we could avoid errors in case the CPU goes to blank memory space.
2.1 . No fill() command involed.
Define segment in MEMORY section:
my_section (rx) : ORIGIN = 0X00000800, LENGTH = 0x20
define output SECTION:
.myData :
{
. = ALIGN(4);
KEEP(*(.myData))
. = ALIGN(4);
}> my_section
In C code, define const variable “my_const” (0xCCCCDDDD)
const int my_const __attribute__((section(".myData"))) = 0xCCCCDDDD;
After the build, we will see only 0xCCCCDDDD in this area in the generated s19 file:
S1070800DDDDCCCC9E
2.2 Use FILL(0xaa) command to fill unused area of my_section with 0xAA.
Here is the modified code in ld file, I highlight the code I add:
.myData :
{
. = ALIGN(4);
KEEP(*(.myData))
. = ALIGN(4);
FILL(0xaa)
. = ORIGIN(my_section) + LENGTH(my_section) ;
}> my_section
Rebuild the project. we will see the rest of the field of my_section is filled with 0xAA in S19 file:
S1130800DDDDCCCCAAAAAAAAAAAAAAAAAAAAAAAA9A
S1130810AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA34
I hope it helps!
Victor
We have issue with SVC interrupt for illegal opcode. As we enable the SVC interrupt for illegal opcode, it gives a hard fault interrupt (Microcontroller S32K142).
Earlier you replied " Where are you calling the function INT_SYS_InstallHandler? Please keep in mind that before calling this function, the RAM memory should be initialized"
How do we verify that RAM is initialized properly.
Regards,
SandipHello Sandip,
Sorry for the misunderstood, I didn't notice that you are using the function: INT_SYS_EnableIRQ(SVCall_IRQn); This is what is causing the problem. This function should be called only for the device-specific interrupts, not for the core interrupts (like the SVC).
In the case of the SVC interrupt you need to call only the function INT_SYS_InstallHandler(SVCall_IRQn, SVC_Handler, (isr_t *)0); The name of the new handler must be the same as the one you assign on the startup, in this case, SVC_Handler.
Regards,
Victor
Hello Sandip,
The example that I mentioned before, can be used for any memory. You just need to define the origin of where you want to start and the length in the variable my_section.
my_section (rx) : ORIGIN = 0X00000800, LENGTH = 0x20
Regards,
Victor
Hello Sandip,
I'm not sure that I understood correctly your question. Do you want to trigger the SVC interrupt? If so, unfortunately, we don't have an example that shows how to trigger this interrupt, but you could try to write directly to the following register
S32_NVIC->ISPR.
Regards,
Victor
we are unable to trigger the SVC interrupt with above methods.
Hi Sandip,
you should use assemlly instruction "svc" to trigger the SVC exception.
information quoted from ARMv7-M Architecture Reference Manual ( DDI 0403E.d (ID070218) ):
An exception caused explicitly by the SVC instruction. Application software uses the SVC instruction
to make a call to an underlying operating system. This is called a Supervisor Call. The SVC
instruction enables the application to issue a Supervisor Call that requires privileged access to the
system and executes in program order with respect to the application. ARMv7-M also supports an
interrupt-driven Supervisor-calling mechanism, PendSV.
This Supervisor Call handles the exception caused by the SVC instruction. SVCall is permanently
enabled and has a configurable priority
Best regard,
Enwei Hu(胡恩伟)
Hi,
what is your target MCU, S32DS Version and SDK version?
Jiri