MPU [memory protection unit] is not working for all the access permissions.

MPU is enabled with GPIO sample code for nucleo_l552ze_q successfully, But the behavior of the MPU access permissions are not expected. I am able to read and write the MPU ram region from both privilege and unprivileged space for read-only access permission. Below code is able to write data into mpu region even for read only access. Kindly reply with your valuable suggestions to make it work for all the access permissions.

Please find the below attached code snippet:

{
/*Disable MPU */
ARM_MPU_Disable();


ARM_MPU_SetRegion_NS(0UL,
ARM_MPU_RBAR(0x20000000UL, ARM_MPU_SH_NON, 1UL, 1UL, 0UL), /* Non-shareable , read-only=1, privileged=0/unprivilege=1, execute-never */
ARM_MPU_RLAR(0x20040000UL, 0UL) /* 1MB memory block using Attr 0 */
);

/*Enable MPU */
ARM_MPU_Enable(1);

uint32_t *mpu_ptr = (uint32_t*)0x20000000 ;
*mpu_ptr = 10;
}