MKM34Z256VLx7 Bare Metal Software Drivers  R4.1.6
Reference Manual
GPIO Port's Access Control

This example shows use of the General-Purpose Input/Output (GPIO) port protection mechanism. The GPIOA is configured to allow RW privileged and user secure/non-secure accesses. On the contrary GPIOB is configured for privileged RW accesses only (user secure/non-secure RW accesses are not allowed). Consequently, GPIO_Tgl(FGPIOB,PIN0) and GPIO_Tgl(GPIOB,PIN0) macros don't execute in a user mode to insufficient access level. The IOPORT accesses, demonstrated by GPIO_Tgl(FGPIOB,PIN0) macro, that are not allowed are treated as a RAZ/WI (Read As Zero/Write Ignored). On the contrary accesses via Peripheral Bridge, demonstrated by GPIO_Tgl(GPIOB,PIN0) macro, which are not allowed, terminate by the Hard Fault.

Source code:
/******************************************************************************
* (c) Copyright 2010-2015, Freescale Semiconductor Inc.
* ALL RIGHTS RESERVED.
***************************************************************************/
#include "drivers.h"
void main (void)
{
/* enable clocks to all on chip peripherals */
/* Set bus masters attribute to be controlled internally by the core */
TRUE);
/* User nonsec=Read/Write, User secure=Read/Write, Priv. secure=Read/Write. */
/* User nonsec=None, User secure=None, Priv. secure=Read/Write. */
/* Toggling pins in privileged mode */
GPIO_Tgl (FGPIOA, PIN0); /* passes - access via CPU's IOPORT */
GPIO_Tgl (GPIOA, PIN0); /* passes - access via Peripheral bridge */
GPIO_Tgl (FGPIOB, PIN0); /* passes - access via CPU's IOPORT */
GPIO_Tgl (GPIOB, PIN0); /* passes - access via Peripheral bridge */
/* Toggling in user mode */
GPIO_Tgl (FGPIOA, PIN0); /* passes - access via CPU's IOPORT */
GPIO_Tgl (GPIOA, PIN0); /* passes - access via Peripheral bridge */
GPIO_Tgl (FGPIOB, PIN0); /* RAZ/WI error - access via CPU's IOPORT */
GPIO_Tgl (GPIOB, PIN0); /* hard fault error - access via Peripheral bridge*/
while(1);
}
Toolchain support:
IAR EWARM 7.40.7KEIL uVision 5.15CrossWorks 3.6ATOLLIC TrueStudio 5.3.0Kinetis Design Studio 3.0.0