Hello, I want to ask about setting a process ID for a region while configuring the SMPU.
the SMPU_EnableProcessIdentifier () function present in the smpu_hw_access.h uses WORD4, which is undefined in any of the MPC5744P files, so my question is how to set a process ID for every region using SMPU
Hi @Mennazz
process identifier feature is not available on MPC5744P. The drivers are common for all MPC57xx devices. File xxxx_features.h then says if a feature is available or not:
Or you can check reference manual for the device.
Process identifier feature is available on MPC5748G devices and their derivatives.
Regards,
Lukas
Okay so, do you know how to configure a memory region for specific task in MPC5744P?
There's also core MPU (CMPU) which supports the process identifier.
I checked the SDK but I can't see an option how to configure it in processor expert. I found only this:
c:\NXP\S32DS_Power_v2.1\S32DS\software\S32_SDK_S32PA_RTM_3.0.3\platform\drivers\src\mpu_e200\
It seems that it would be necessary to configure the structures manually.
Another option is to do that without the drivers. I shared this example here:
There's also link to excel tool "CMPU configurator" which can help to generate asm code for initialization. Or you can just use the generated values and then use function from the mentioned driver.
Process identifier is not used in the example. But it shouldn't be a problem - it's just necessary to set TID (and optionally TIDMSK) for your descriptors and then set PID core register as needed at beginning/end of your task. More information can be found in Chapter 10:
https://www.nxp.com/webapp/Download?colCode=E200Z4RM&location=null
Regards,
Lukas
Do you mean that it is possible to configure a process ID for every region using CMPU? If yes, could you please explain how in more detail?
To my knowledge, when exploring the functions used to configure the MPU, they are nearly the same as those used to configure the SMPU and are using the same macro FEATURE_SMPU_HAS_PROCESS_IDENTIFIER
@lukaszadrapa Could you please reply ?
While I am investigating how to configure the CMPU with PID, I found that the MPC5744P_features.h file does not contain anything related to the CMPU, so does it mean that not all CMPU capabilities are available in MPC5744P as it is configured using the SMPU?
Hi @Mennazz
my recommendation is to use mentioned configurator. This is the simplest method. All you need to do is to set TID as needed (and optionally set also mask inTIDMSK if needed).
Entry with TID 0 is considered as global and matches with all tasks. So, just configure the TID in the configurator for each entry:
Regards,
Lukas
Hello @lukaszadrapa
this configurator configure only one region right? so to configure multiple regions I shall generate code for every region separately right ?
could you please explain this register usage in more details ?
and How to integrate this generated assembly code to my c code ?
Hi @Mennazz
attached is example (the one I shared earlier created in GHS) ported to S32DS.
You can use cmpu.s file, just update it as needed. Here's the result when running the code:
It should also explain the ESEL and INST field. There are separate configurations for instruction and data because those are two separate buses:
Notice that the CMPU needs to be enabled by writing MPUEN bit in MPU0CSR0 core register. This can be found at the end of initialization. This is not generated by the configurator.
Regards,
Lukas
I didn't get what ESEL really does. Could you please explain more?
Another question, please: is there a way to rewrite the used assembly code into c-code as we did before while setting the task ID with the mtspr register?
There are 24 descriptors in total:
ESEL is used to select a descriptor you need.
INST says if you are going to use descriptor for instruction region or for data region.
SHD then allows you to use shared regions for both instruction and data.
In the screenshot shared earlier, there are two descriptors used in instruction region (you can use up to 6 descriptors) and three descriptors used in data region (you can use up to 12 descriptors). Shared region is not used there but you can use up to 6 descriptors. So, all the descriptors are selectable by ESEL and by INST and SHD which select between instruction/data/shared regions.
Regards,
Lukas
Okay what about this question is there a way to rewrite the used assembly code into c-code as we did before while setting the task ID with the mtspr register?
Well, you could write the MASx registers in the same way and then call asm function which would execute mpuwe and mpusync instructions. So, yes, this could work too.
Could you explain more with an example since the example sent contains these assembly lines?
e_lis r3, 0xA100
e_or2i r3, 0x0F00
mtspr mas0, r3
Here's an example:
//write one descriptor
mtspr(624, 0xXXXXXXXX); //write MAS0
mtspr(625, 0xXXXXXXXX); //write MAS1
mtspr(626, 0xXXXXXXXX); //write MAS2
mtspr(627, 0xXXXXXXXX); //write MAS3
CMPU_WriteDescriptor();
For CMPU_WriteDescriptor, you can re-use file cmpu.s from previous example, just create a function like this:
CMPU_WriteDescriptor:
mpuwe
mpusync
se_blrl
And then create one more function to enable the CMPU like:
CMPU_Enable:
e_lis r3, 0x0000
e_or2i r3, 0x0001
mtspr 1014, r3
se_blr
And from the example you shared above:
e_lis r3, 0xA100
e_or2i r3, 0x0F00
mtspr mas0, r3
That's value 0xA1000F00 which should be written to MAS0, so:
mtspr(624, 0xA1000F00);//write MAS0
Regards,
Lukas
Looks great !
but what about these lines
mpuwe
mpusync
se_blrl
How to write them in C
As I wrote - you can use cmpu.s file as a template. That's file for asm code.
Or there's second option - you can write the same instructions to C code like this:
To write a descriptor:
asm("mpuwe");
asm("mpusync");
To enable CMPU:
asm("e_lis %r3, 0x0000");
asm("e_or2i %r3, 0x0001");
asm("mtspr 1014, %r3");
Regards,
Lukas
Okay It works Thank you
But could you tell me how to detect violations if a task with a task ID accessed a memory location configured with a different task ID?
Access violation is signaled by ISI or DSI (instruction storage interrupt or data storage interrupt), so Machine Check / IVOR1 should be triggered.
Regards,
Lukas
Can I split the RAM into multiple regions ?
e.g.
Region 1 from 0x4000 0000 to 0x4002 0000 with TID =2
Region 2 from 0x4003 0000 to 0x4004 0000 with TID =3
and so on