Dears
I compiled the Hse_Send() function to 0x0041E400 using a compilation macro instruction, with a space size of 6kb. The map file generated after compilation indicates that the above operation was successful.
Before executing the encryption service, I first copied the HSE_send function to the address 0x2043E800, and used a pointer function to jump to the corresponding address to execute the function. The screenshot of the situation is as follows:
When executing the above assembly instructions in a single step, the PC register will be reset to 0.
Question: Is this issue due to my software operation? Is the way I copied the code to the RAM address incorrect?
When a debugger shows PC as zero, it's typically caused by fact that the debugger is not able to parse the fault context. As I wrote before, it looks like you executed position dependent code from wrong address - this always leads to crash because some relative jumps won't be correct. This obviously caused a fault or rather a series of faults.
Regards,
Lukas
Dears
Thanks for your support, but I still need know Why it jumping to 0x0 like below?
I need to find the reason for the problem to avoid risks, wait for your feedback.
It looks like the function is simply forced to text section but the compiler does not know that it should compile the function to RAM address. It's not position independent code. You can take a a look at this article for details:
But because RTD has already prepared memory mapping files and linker file for this, there's no reason to do that in another way.
Regards,
Lukas
Dears
Thanks, It works with your solution, but can you let me know why the way I copy the code to RAM can't works? Due to the S32DS does't support this way? Or RTD has limitation to this way?
And one note: if a function you want to force to RAM calls other functions, you may need to force them to RAM too.
Hi @Ali22
I can see you use memory mapping file from RTD. In this case, it's quite simple in RTD project, you do not need to create own section, you do not need to copy the code manually.
For example, let's say we want to force Hse_Ip_ServiceRequest function to RAM. Open HSE_Ip.c and HSE_Ip.h and find the definition/declaration of this function.
If you take closer look at the files, you will see that all the code is forced to flash using this at the beginning:
#define CRYPTO_43_HSE_START_SEC_CODE
#include "Crypto_43_HSE_MemMap.h"
and at the end:
#define CRYPTO_43_HSE_STOP_SEC_CODE
#include "Crypto_43_HSE_MemMap.h"
To force only one function to RAM, we have to stop this default section in front of our function, use RAMCODE section and then use the default section again. In header file, it can look like this:
...
#define CRYPTO_43_HSE_STOP_SEC_CODE
#include "Crypto_43_HSE_MemMap.h"
#define CRYPTO_43_HSE_START_SEC_RAMCODE
#include "Crypto_43_HSE_MemMap.h"
hseSrvResponse_t Hse_Ip_ServiceRequest
(
uint8 u8MuInstance,
uint8 u8MuChannel,
Hse_Ip_ReqType* pRequest,
hseSrvDescriptor_t* pHseSrvDesc
);
#define CRYPTO_43_HSE_STOP_SEC_RAMCODE
#include "Crypto_43_HSE_MemMap.h"
#define CRYPTO_43_HSE_START_SEC_CODE
#include "Crypto_43_HSE_MemMap.h"
...
Do the same in *.c file. Then the function is copied to RAM automatically by startup code, you do not need to copy the code manually.
Regards,
Lukas