Exemplo n.º 1
0
Arquivo: main.c Projeto: gstroe/Arm
/**
 *  \brief Application entry point for UART example.
 *
 *  \return Unused (ANSI-C compatibility).
 */
extern int main(void)
{
	uint8_t ucKey;

	/* Disable watchdog */
	WDT_Disable(WDT);

	/* Output example information */
	printf("-- UART Example %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME);

	/* Enable I and D cache */
	SCB_EnableICache();
	SCB_EnableDCache();

	/* Display menu */
	DisplayMenu();

	while (1) {
		ucKey = DBG_GetChar();

		switch (ucKey) {
		case 'h':
			DisplayMenu();
			break;
		case 'i':
		case 'I':
			printf("\n\rSending Tx Buffer.. \n\r");
			UartTransfer();
			break;

		case 'd':
		case 'D':
			memset(pRxBuffer,'X' ,30);
			pRxBuffer[28] = '\n';
			pRxBuffer[29] = '\r';
			printf("\n\rRx Buffer before transfer is \n\r");
			puts((char*)pRxBuffer);
			_UartdConfigLB();
			UARTD_EnableRxChannels(&Uartd, &UartRx);
			UARTD_EnableTxChannels(&Uartd, &UartTx);
			UARTD_RcvData(&Uartd);
			UARTD_SendData(&Uartd);

			printf("\n\rRx Buffer after transfer is \n\r");

			while (Uartd.pRxChannel->sempaphore == 0);
			puts((char*)pRxBuffer);
			UARTD_DisableRxChannels(&Uartd, &UartRx);
			UARTD_DisableTxChannels(&Uartd, &UartTx);
			break;

		default :
			break;
		}
	}
}
Exemplo n.º 2
0
/**
 * Get Dec Input
 * \param numChar Number of character to wait.
 * \param pInt    Pointer to uint32_t for input result.
 * \return 0 if valid data input.
 */
static uint8_t GetDecInput(uint8_t numChar, uint32_t *pInt)
{
    uint8_t key;
    uint32_t  i;
    uint32_t  result = 0;
    for (i = 0; i < numChar;)
    {
        key = DBG_GetChar();
        if (key == 27)
        {
            printf(" Canceled\n\r");
            return key;
        }
        if (key > '9' || key < '0') continue;
        DBG_PutChar(key);
        result = result * 10 + (key - '0');
        i ++;
    }
    if (pInt) *pInt = result;
    return 0;
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: gstroe/Arm
/**
 *  \brief getting-started Application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
extern int main(void)
{
	uint32_t id_offset = 0;
	uint32_t fifo_entries;
	uint32_t button_state = BUTTON_PUSHED;
	uint32_t button_state2 = BUTTON_NOT_PUSHED;
	uint32_t can_mode = CAN_STANDARD;

	/* Disable watchdog */
	WDT_Disable(WDT);

	/* Output example information */
	printf("\n\r-- Controller Area Network (CAN) Example %s --\n\r",
			SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r\n\r", __DATE__, __TIME__);
	printf("-- LED0 toggles on CAN message reception\n\r");
	printf("-- LED1 toggles on CAN message transmission\n\r");
	printf("-- CAN message transmission stopped while SW0 is pushed\n\r");
	printf("-- SW1 pushes alternate between standard CAN and CAN-FD\n\r");

	SCB_EnableICache();
	SCB_EnableDCache();

	/* Configure systick for 1 ms. */
	TimeTick_Configure();

	/* Configure Board LED's */
	LED_Configure(0);
#if 2 == LED_NUM
	LED_Configure(1);
#endif

	/* Configure Timer/Counter for 250msec Tick */
	_ConfigureTc();

	/* Configure Board Push-buttons */
	// SW1 is a ERASE system function, switch it to port function
	MATRIX->CCFG_SYSIO |= (1u << 12);
	/* have to disable the pull down on PB12 for SW1 before the pull up can be
		enabled */
	PIOB->PIO_PPDDR = 1 << 12;
	PIO_Configure(pushbutton, PIO_LISTSIZE(pushbutton));
	/* Adjust pio denounce filter parameters, uses 10 Hz filter. */
	PIO_SetDebounceFilter(&pushbutton[0], 10);
#if 2 == BUTTON_NUM
	PIO_SetDebounceFilter(&pushbutton[1], 10000);
#endif

	SystemCoreClockUpdate();

	MCAN_Init(&mcan1Config);

	MCAN_InitFdBitRateSwitchEnable(&mcan1Config);
	MCAN_InitTxQueue(&mcan1Config);
	MCAN_InitLoopback(&mcan1Config);  // remove to disable loop back mode
	MCAN_Enable(&mcan1Config);

	MCAN_IEnableMessageStoredToRxDedBuffer(&mcan1Config, CAN_INTR_LINE_1);

	txMailbox0 = (uint32_t *)MCAN_ConfigTxDedBuffer(&mcan1Config, TX_BUFFER_0,
			MSG_ID_0, CAN_STD_ID, CAN_DLC_1);
	txMailbox1 = (uint32_t *)MCAN_ConfigTxDedBuffer(&mcan1Config, TX_BUFFER_1,
			MSG_ID_1, CAN_EXT_ID, CAN_DLC_8);
	MCAN_ConfigRxBufferFilter(&mcan1Config, RX_BUFFER_0, FILTER_0, MSG_ID_0,
			CAN_STD_ID);
	MCAN_ConfigRxBufferFilter(&mcan1Config, RX_BUFFER_1, FILTER_0, MSG_ID_1,
			CAN_EXT_ID);
	MCAN_ConfigRxClassicFilter(&mcan1Config, CAN_FIFO_0, FILTER_1, MSG_ID_2,
			CAN_STD_ID, MSG_ID_2_MASK);

	while (1) {
		 if (tick) {
			tick = 0;
			if (PIO_Get(&pushbutton[0]) == BUTTON_NOT_PUSHED) {
				if (button_state2 == BUTTON_NOT_PUSHED) {
					/* periodically transmit messages while SW0 is not pushed */
					// send standard ID from a dedicated buffer
					*txMailbox0 = MSG_ID_0_DATA1;  // write data into CAN mailbox
					MCAN_SendTxDedBuffer(&mcan1Config, TX_BUFFER_0);  // send data
					txdCntr++;
					// send extended ID from a dedicated buffer
					*txMailbox1 = MSG_ID_1_DATA1_4;  // write data into CAN mailbox
					*(txMailbox1 + 1) = MSG_ID_1_DATA5_8; // write data into CAN mailbox
					MCAN_SendTxDedBuffer(&mcan1Config, TX_BUFFER_1); // send the data
					txdCntr++;
					// send from Tx Queue
					MCAN_AddToTxFifoQ(&mcan1Config, MSG_ID_2 + id_offset, CAN_STD_ID,
							CAN_DLC_1, &txData[0]);
					txdCntr++;
					// increment the offset so we send different ID's within the
					// range defined by the mask
					id_offset = (id_offset + 1) & (uint32_t) ~MSG_ID_2_MASK;
					// update data being sent for next time
					txData[0]++;
					button_state2 = BUTTON_NOT_PUSHED;
				}
			} else {
				if (button_state2 == BUTTON_NOT_PUSHED)
					button_state2 = BUTTON_PUSHED;
				else
					button_state2 = BUTTON_NOT_PUSHED;
			}
		}
		/* poll for TX'd message complete */
		 if (MCAN_IsTxComplete(&mcan1Config)) {
			MCAN_ClearTxComplete(&mcan1Config);
			if (MCAN_IsBufferTxd(&mcan1Config, TX_BUFFER_0)) {
		#if 2 == LED_NUM
				LED_Toggle(1);
		#endif
			}
		}
		/* Poll for new CAN messages in RX FIFO */
		do {
			fifo_entries = MCAN_GetRxFifoBuffer(&mcan1Config, CAN_FIFO_0,
					(Mailbox64Type *) &rxMailbox2);
			if (fifo_entries > 0) rxdCntr++;
		} while (fifo_entries > 1);

		/* SW1 used to alternate between standard CAN and CAN-FD operation */
#if 2 == BUTTON_NUM
		if (PIO_Get(&pushbutton[1]) == BUTTON_NOT_PUSHED) {
#else
		if (1) {
#endif
			 button_state = BUTTON_NOT_PUSHED;
		} else {
			if (button_state == BUTTON_NOT_PUSHED ) {
				// Switch on a NOT PUSHED to PUSHED edge
				button_state = BUTTON_PUSHED;
				if (can_mode == CAN_STANDARD) {
					can_mode = CAN_FD;
					MCAN_RequestFdBitRateSwitch( &mcan1Config );
				} else {
					can_mode = CAN_STANDARD;
					MCAN_RequestIso11898_1( &mcan1Config );
				}
			}
		}
#ifdef POLLKEYBOARD
	/* poll for keyboard entry */
	if (DBG_IsRxReady()) {
		keyboard = DBG_GetChar();
		if (((char) keyboard == 'L' ) || ( (char) keyboard == 'l')) {
			if (loopback == 1) {
				MCAN_LoopbackOff(&mcan1Config);
				loopback = 0;
			} else {
				MCAN_LoopbackOn(&mcan1Config);
				loopback = 1;
			}
		}
	}
#endif
	}
}
Exemplo n.º 4
0
Arquivo: main.c Projeto: gstroe/Arm
/**
 * Displays a menu which enables the user to send several commands to the
 * smartcard and check its answers.
 */
static void SendReceiveCommands(void)
{
	uint8_t pMessage[MAX_ANSWER_SIZE];
	uint8_t ucSize;
	uint8_t ucKey;
	uint8_t command;
	uint8_t i;

	/*  Clear message buffer */
	memset(pMessage, 0, sizeof(pMessage));

	/*  Display menu */
	printf("-I- The following three commands can be sent:\n\r");
	printf("  1. ");
	for (i = 0; i < sizeof(testCommand1); i++)
		printf( "0x%X ", testCommand1[i]);
	printf("\n\r  2. ");

	for (i = 0; i < sizeof(testCommand2); i++)
		printf("0x%X ", testCommand2[i]);
	printf("\n\r  3. ");

	for (i = 0; i < sizeof(testCommand3); i++)
		printf("0x%X ", testCommand3[i]);
	printf("\n\r" );

	/*  Get user input */
	ucKey = 0;
	while (ucKey != 'q') {
		printf("\r                        ");
		printf("\rChoice ? (q to quit): ");
		ucKey = DBG_GetChar();
		printf("%c", ucKey);
		command = ucKey - '0';

		/*  Check user input */
		ucSize = 0;
		if (command == 1) {
			printf("\n\r-I- Sending command ");
			for (i = 0; i < sizeof( testCommand1 ); i++)
				printf( "0x%02X ", testCommand1[i]);
			printf("...\n\r");
			ucSize = ISO7816_XfrBlockTPDU_T0(testCommand1, pMessage,
							sizeof( testCommand1));
		} else {
			if (command == 2) {
				printf("\n\r-I- Sending command ");
				for (i = 0; i < sizeof(testCommand2); i++)
					printf("0x%02X ", testCommand2[i]);
				printf("...\n\r");
				ucSize = ISO7816_XfrBlockTPDU_T0(testCommand2, pMessage,
								sizeof( testCommand2));
			} else {
				if (command == 3) {
					printf("\n\r-I- Sending command ");
					for (i = 0; i < sizeof(testCommand3); i++)
						printf("0x%02X ", testCommand3[i]);
					printf("...\n\r");
					ucSize = ISO7816_XfrBlockTPDU_T0(testCommand3, pMessage,
									sizeof(testCommand3));
				}
			}
	   }

		/*  Output smartcard answer */
		if (ucSize > 0) {
			printf("\n\rAnswer: ");
			for (i = 0; i < ucSize; i++)
				printf("0x%02X ", pMessage[i]);
			printf("\n\r");
		}
	}
	printf("Quitting ...\n\r");
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: gstroe/Arm
/**
 *  \brief usart-hw-handshaking Application entry point..
 *
 *  Configures USART in hardware handshaking mode and
 *  Timer Counter 0 to generate an interrupt every second. Then, start the first
 *  transfer on the USART and wait in an endless loop.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main( void )
{
	char pbaud_time[8];
	uint32_t BytesRead, BytesToRead, baudrate, timeout, TxBytesLeft;
	uint8_t AppBufferRollOver = 0;
	uint8_t *pTxBuff;

	/* Disable watchdog*/
	WDT_Disable(WDT);

	printf("-- USART Hardware Handshaking Example %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME);

	/* Enable I and D cache */
	SCB_EnableICache();
	SCB_EnableDCache();

	/* Configure USART pins*/
	PIO_Configure(pins, PIO_LISTSIZE(pins));

	/* Configure systick for 1 ms. */
	TimeTick_Configure();

	NVIC_SetPriority(XDMAC_IRQn , XDMA_NVIC_PRIO);


	printf("\n\rEnter required baudrate:");
	gets(pbaud_time);
	baudrate = (atoi(pbaud_time)) ? (atoi(pbaud_time)): 921600;
	printf("\n\rEnter required timeout (in microsec):");
	gets(pbaud_time);

	timeout = atoi(pbaud_time);
	if (timeout > 1000) {
		timeout /= 1000;
		timeout = ((timeout * baudrate) / 1000);
	} else {
		timeout = (timeout * baudrate) / 1000000;
	}
	timeout = (timeout) ? ((timeout > MAX_RX_TIMEOUT) ? MAX_RX_TIMEOUT : timeout) \
		: MAX_RX_TIMEOUT;
	printf("\n\r");
	/* Configure USART */
	_ConfigureUsart(baudrate, timeout);
	printf("\n\r");

	/*Enable Rx channel of USART */
	USARTD_EnableRxChannels(&Usartd, &UsartRx);

#ifdef FULL_DUPLEX
	/*Enable Tx channel of USART */
	USARTD_EnableTxChannels(&Usartd, &UsartTx);
#endif

	/* Start receiving data and start timer*/
	USARTD_RcvData(&Usartd);

	/*Initialize Ring buffer */
	pUsartBuffer = (RignBuffer_t *)malloc(sizeof(RignBuffer_t));
	_initCircularBuffer(pUsartBuffer);

	pTxBuff = &FirstAppBuff[0];

	TxBytesLeft = 0;

#ifdef USE_MD5_CHECK
	md5_init(&pms);
#endif //USE_MD5_CHECK

#ifdef FULL_DUPLEX
	printf( "\n\r-I- USART is in Full Duplex mode \n\r");
#else
	printf( "\n\r-I- USART is in Half Duplex mode \n\r");
#endif
	printf( "\n\r-I- Please send a file to serial port (USART0) \n\r");
	BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer

	while (1) {
#ifdef USE_MD5_CHECK
		if (DBG_IsRxReady()) {
			ch = DBG_GetChar();
			if (ch == 'm') {
				uint8_t i;
				md5_finish(&pms, md5);
				printf("\r\nmd5:");
				for (i = 0; i < sizeof(md5);i++)
					printf("%.2x",md5[i]);
				printf("\r\n");
				md5_init(&pms);
				TotalbytesReceived = 0;
			}
		}
#endif
		/* Check Application buffer (100 KB)overflow */
		if (((PingPongBufferFlag == 0) &&
			(pTxBuff+BytesToRead) >= &FirstAppBuff[APP_BUFFER]) ||
			(( PingPongBufferFlag == 1) && (pTxBuff+BytesToRead) >=
			&SecondAppBuff[APP_BUFFER])) {
			AppBufferRollOver = 1;
			// Roll over and start copying to the beginning of Application buffer to avoid errors
			if (PingPongBufferFlag)
				BytesToRead = (&SecondAppBuff[APP_BUFFER] - pTxBuff);
			else
				BytesToRead = (&FirstAppBuff[APP_BUFFER] - pTxBuff);
			memory_barrier();
		}
		/* Read ring buffer */
		BytesRead = RingBufferRead(pUsartBuffer, pTxBuff, BytesToRead);
		memory_sync();
		TxBytesLeft += BytesRead;       // number of bytes to send via USART Tx

#ifdef USE_MD5_CHECK
		if (BytesRead > 0)
			md5_append(&pms,pTxBuff,BytesRead);
#endif

		/* check if one of the application buffer is full and ready to send */
		if (AppBufferRollOver && (TxBytesLeft == APP_BUFFER)) {
			AppBufferRollOver = 0;
			TxBytesLeft = 0;
			BytesRead = 0;
			BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer
			while (!UsartTx.dmaProgress);
			if (PingPongBufferFlag) {
				PingPongBufferFlag = 0;
				pTxBuff = &FirstAppBuff[0];
			} else {
				PingPongBufferFlag = 1;
				pTxBuff = &SecondAppBuff[0];
			}
			memory_sync();
#ifdef FULL_DUPLEX
			USARTD_SendData(&Usartd);
#endif
		}
		/* otherwise keep storing in same application buffer from Rx DMA's ring
			buffer */
		else {
			BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer
			pTxBuff += BytesRead;

#ifdef FULL_DUPLEX
			/* Check for Tx timeout, if there is timeout then send the bytes left
				(less than 100 KB) in application buffer */
			if ((GetDelayInTicks(TimeOutTimer, GetTicks()) == USART_TX_TIMEOUT)
				&& TxBytesLeft) {
				// wait for any eventual USART Tx in progress
				while (!UsartTx.dmaProgress);
				FlushTxBuffer(TxBytesLeft);
				TimeOutTimer = GetTicks();
				PingPongBufferFlag = 0;
				TxBytesLeft = 0;
				BytesRead = 0;
				BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer
				pTxBuff = &FirstAppBuff[0];
				_UpdateTxConfig((uint32_t)&FirstAppBuff[0], APP_BUFFER);
				TRACE_INFO_WP(" TX Tiemout \n\r");
			}
#endif
		}
	}
}
Exemplo n.º 6
0
Arquivo: main.c Projeto: gstroe/Arm
/**
 *  \brief Application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
extern int main(void)
{
	uint8_t ucKey;

	/* Disable watchdog */
	WDT_Disable(WDT);

	SCB_EnableICache();
	SCB_EnableDCache();

	/* Output example information */
	printf("-- USART LON Example %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s  With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME);

	/* Configure pins */
	PIO_Configure(pins, PIO_LISTSIZE(pins));
	/* PB4 function selected */
	MATRIX->MATRIX_WPMR = MATRIX_WPMR_WPKEY_PASSWD;
	MATRIX->CCFG_SYSIO |= CCFG_SYSIO_SYSIO4;

	/* Display menu */
	_DisplayMenu();

	/* Configure DMA with IRQ */
	_ConfigureDma();

	Buffer[0] = sizeof(palette) - 1; /* LON Data Length:  */
	Buffer[1] = US_LONL2HDR_BLI(2);
	memcpy(&Buffer[2], palette, sizeof(palette));

	/* configure USART in LON mode*/
	_ConfigureUsart();

	NVIC_EnableIRQ(XDMAC_IRQn);

	while (1) {
		ucKey = DBG_GetChar();
		switch (ucKey) {
		case 't':
		case 'T':
			printf("-I- LON Transmitting ... \n\r");
			USART->US_CR = US_CR_RSTSTA;    /* Reset Status Bits */
			_DmaUsartTx();
			while (!transDone);
			printf("-I- LON Transmitting completed \n\r");
			transDone = 0;
			break;

		case 'r':
		case 'R':
			printf("-I- LON receiving ... \n\r");
			USART->US_CR = US_CR_RSTSTA;    /* Reset Status Bits */
			recvDone = 0;

			_DmaUsartRx();
			while (!recvDone);
			/* successfully received */
			_DumpInfo(pRecvBufferUSART, BUFFER_SIZE - 1);
			printf("\n\r-I- LON Receiving completed \n\r");
			memset(pRecvBufferUSART, 0, sizeof(pRecvBufferUSART));
			break;

		case 'm':
		case 'M':
			_DisplayMenu();
			break;
		}
	}
}
Exemplo n.º 7
0
/**
 *  \brief periph-protect Application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
extern int main(void)
{
    uint8_t cmd;
    uint32_t wpsr;
    uint32_t *pReg;
    const uint32_t dummy = 0x12345678;

    /* Disable watchdog */
    WDT_Disable(WDT);
    /* Enable I and D cache */
    SCB_EnableICache();
    SCB_EnableDCache();

    /* Output example information */
    printf("-- Peripheral Protect Example %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
    _DisplayMenu();

    /* Enable PIO controller peripheral clock */
    PMC_EnablePeripheral(pinwp.id);
    /* Get the address of PIO controller to be write-protected */
    pReg = _GetPioFromPin(&pinwp);

    while (1) {

        cmd = DBG_GetChar();

        switch (cmd) {

            case 'm':
                _DisplayMenu();
                break;

            case 'l':
                PIO_EnableWriteProtect(&pinwp);
                printf("The Write Protect is enabled.\r\n");
                break;

            case 'u':
                PIO_DisableWriteProtect(&pinwp);
                printf("The Write Protect is disabled.\r\n");
                break;

            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                *(pReg + offset[cmd - '0'] / 4) = dummy;
                break;

            case 'a':
            case 'b':
            case 'c':
            case 'd':
            case 'e':
            case 'f':
                *(pReg + offset[cmd - 'a' + 10] / 4) = dummy;
                break;

            default:
                cmd = 'x';
                break;
        }

        if ((cmd != 'x') && (cmd != 'm') && (cmd != 'l') && (cmd != 'u')) {

            /* A write access has been attempted */
            wpsr = PIO_GetWriteProtectViolationInfo(&pinwp);
            if ((wpsr & PIO_WPMR_WPEN_EN) == PIO_WPMR_WPEN_EN) {

                /* Write protect violation is detected */
                printf("Write protect violation is detected!\r\n");
                printf("The offset of the write-protected register is 0x%04x.\r\n", (unsigned int)((wpsr & 0x00FFFF00) >> 8));
            } else {
Exemplo n.º 8
0
Arquivo: main.c Projeto: gstroe/Arm
/**
 *  \brief usart_spi Application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
extern int main(void)
{
	uint8_t ucKey, i;

	/* Disable watchdog */
	WDT_Disable(WDT);

	SCB_EnableICache();
	SCB_EnableDCache();

	/* Configure systick for 1 ms. */
	TimeTick_Configure();

	/* Output example information */
	printf("-- USART SPI Example %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s  With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME);

	/* Display menu */
	_DisplayMainmenu();

	while (1) {
		ucKey = DBG_GetChar();
		switch (ucKey) {
			/*usart as spi master*/
		case 'm':
		case 'M':
			/* Configure pins*/
			PIO_Configure(pins1, PIO_LISTSIZE(pins1));
			/* Configure USART as SPI master */
			_ConfigureUsartAsSpiMaster();

			/* Configure SPi slave */
			_ConfigureSpiSlave();
			printf("-I- Configure USART as spi master ...\n\r");
			SPI_EnableIt(SPI, SPI_IER_RDRF);
			SPI_Enable(SPI);

			USART_EnableIt(USART, UART_IER_RXRDY);

			for (i = 0; (pTxBuffer1[i]!='\0' && pTxBuffer2[i]!='\0'); i++) {
				while ((SPI->SPI_SR & SPI_SR_TXEMPTY) == 0);
				SPI->SPI_TDR = ((uint16_t)pTxBuffer2[i]) | SPI_PCS( 0 );
				USART_Write( USART, pTxBuffer1[i], 0);
			}
			break;

			/*usart as spi slave*/
		case 's':
		case 'S':
			printf("-I- Configure USART as spi slave...\n\r");
			/* Configure pins*/
			PIO_Configure(pins2, PIO_LISTSIZE(pins2));
			/* Configure USART as SPI slave */
			_ConfigureUsartAsSpiSlave();
			/* Configure SPI master */
			_ConfigureSpiMaster();
			USART_EnableIt(USART, UART_IER_RXRDY);
			SPI_EnableIt(SPI, SPI_IER_RDRF);
			SPI_Enable(SPI);
			for (i = 0; (pTxBuffer1[i]!='\0' && pTxBuffer2[i]!='\0'); i++) {
				USART_Write(USART, (uint16_t)pTxBuffer2[i], 0);
				SPI_Write( SPI, 1, (uint16_t)pTxBuffer1[i]);
			}
			break;

		case 'h':
		case 'H':
			_DisplayMainmenu();
			break;
		}
	}
}
Exemplo n.º 9
0
Arquivo: main.c Projeto: gstroe/Arm
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	uint8_t isUsbConnected = 0;
	/* Disable watchdog */
	WDT_Disable(WDT);


	SCB_EnableICache();
	SCB_EnableDCache();

	/* Output example information */
	printf("-- USB Device CDC Serial Project %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ ,
			COMPILER_NAME);

	/* Initialize PIO interrupts */
	PIO_InitializeInterrupts(0);

	/* Interrupt priority */
	NVIC_SetPriority(USBHS_IRQn, 2);

	/* Configure DMA driver */
	_ConfigureDma();

	/* Configure USART */
	_ConfigureUsart();
	_UsartDmaRxSetup();

	/* Initialize OTG clocks */
	_ConfigureUotghs();

	/* CDC serial driver initialization */
	CDCDSerialDriver_Initialize(&cdcdSerialDriverDescriptors);

	/* Help information */
	_DebugHelp();

	// Start USB stack to authorize VBus monitoring
	USBD_Connect();

	/* Driver loop */
	while (1) {
		/* Device is not configured */
		if (USBD_GetState() < USBD_STATE_CONFIGURED) {
			if (isUsbConnected) {
				isUsbConnected = 0;
				isCdcSerialON  = 0;
			}
		} else if (isUsbConnected == 0)
			isUsbConnected = 1;

		/* Serial port ON/OFF */
		if (CDCDSerialDriver_GetControlLineState() & CDCControlLineState_DTR) {
			if (!isCdcSerialON) {
				isCdcSerialON = 1;

				/* Start receiving data on the USART */
				_UsartDmaRx();
				USART_EnableIt(BASE_USART, US_CSR_FRAME | US_CSR_OVRE | US_IER_TIMEOUT);
				USART_EnableRecvTimeOut(BASE_USART, USART_TIMEOUT);
				/* Start receiving data on the USB */
				CDCDSerialDriver_Read(usbBuffer,
									  DATAPACKETSIZE,
									  (TransferCallback) _UsbDataReceived,
									  0);
			}
		} else if (isCdcSerialON)
			isCdcSerialON = 0;

		if (DBG_IsRxReady()) {
			uint8_t key = DBG_GetChar();

			/* ESC: CDC Echo ON/OFF */
			if (key == 27) {
				printf("** CDC Echo %s\n\r",
					   isCdcEchoON ? "OFF" : "ON");
				isCdcEchoON = !isCdcEchoON;
			}
			/* 't': Test CDC writing  */
			else if (key == 't')
				_SendText();
			else {
				printf("Alive\n\r");

				while (CDCDSerialDriver_Write((char *)"Alive\n\r", 8, 0, 0)
					   != USBD_STATUS_SUCCESS);

				_DebugHelp();
			}
		}
	}
}
Exemplo n.º 10
0
Arquivo: main.c Projeto: gstroe/Arm
/**
 * Monitor keyboard buttons & Update key status in HID driver
 */
static void HIDDKeyboardProcessKeys(void)
{
	uint32_t i;
	uint8_t pressedKeys[NUM_KEYS];
	uint8_t pressedKeysSize = 0;
	uint8_t releasedKeys[NUM_KEYS];
	uint8_t releasedKeysSize = 0;

	/* Monitor buttons */
#ifdef NO_PUSHBUTTON

	if (DBG_IsRxReady()) {
		uint8_t key = DBG_GetChar();

		switch (key) {
		case '1': case '2':
			i = key - '1';

			if (keyStatus[i]) {
				/* Key press simulation */
				TRACE_INFO("Key %u pressed\n\r", (unsigned int)i);
				keyStatus[i] = 0;
				pressedKeys[pressedKeysSize] = keyCodes[i];
				pressedKeysSize ++;
				HIDDKeyboard_RemoteWakeUp();
			} else {
				/* Key release simulation */
				TRACE_INFO("Key %u released\n\r", (unsigned int)i);
				keyStatus[i] = 1;
				releasedKeys[releasedKeysSize] = keyCodes[i];
				releasedKeysSize++;
			}

			break;

		default: DBG_PutChar(key);
		}
	}

#else

	for (i = 0; i < PIO_LISTSIZE(pinsPushButtons); i++) {
		/* Check if button state has changed */
		uint8_t isButtonPressed = PIO_Get(&(pinsPushButtons[i]));

		if (isButtonPressed != keyStatus[i]) {
			/* Update button state */
			if (!isButtonPressed)   {
				/* Key has been pressed */
				TRACE_INFO("Key %u has been pressed\n\r", i);
				keyStatus[i] = 0;
				pressedKeys[pressedKeysSize] = keyCodes[i];
				pressedKeysSize++;
				HIDDKeyboard_RemoteWakeUp();
			} else {
				/* Key has been released */
				TRACE_INFO("Key %u has been released\n\r", i);
				keyStatus[i] = 1;
				releasedKeys[releasedKeysSize] = keyCodes[i];
				releasedKeysSize++;
			}
		}
	}

#endif

	/* Update key status in the HID driver if necessary */
	if ((pressedKeysSize != 0) || (releasedKeysSize != 0)) {
		uint8_t status;

		do {
			status = HIDDKeyboard_ChangeKeys(pressedKeys,
											 pressedKeysSize,
											 releasedKeys,
											 releasedKeysSize);
		} while (status != USBD_STATUS_SUCCESS);
	}
}
Exemplo n.º 11
0
Arquivo: main.c Projeto: gstroe/Arm
int main(void)
{
	uint32_t i;
	uint32_t deviceId;
	uint8_t ucKey;
	uint8_t TestPassed = 0;

	/* Disable watchdog */
	WDT_Disable(WDT);

	/* Output example information */
	printf("-- QSPI Serialflash Example %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME);
	SCB_EnableICache();
	SCB_EnableDCache();
	TimeTick_Configure();

	PIO_Configure(Qspi_pins, PIO_LISTSIZE(Qspi_pins));
	ENABLE_PERIPHERAL(ID_QSPI);

	QSPI_UserMenu();

	while (1) {
		ucKey = DBG_GetChar();

		switch (ucKey) {
		case '1' :
			S25FL1D_InitFlashInterface(1);
			TRACE_INFO("QSPI drivers initialized ");
			/* enable quad mode */
			S25FL1D_QuadMode(ENABLE);
			PeripheralInit = 1;
			break;

		case '2' :
			S25FL1D_InitFlashInterface(0);
			TRACE_INFO("QSPI Initialized in SPI mode");
			S25FL1D_QuadMode(DISABLE);
			PeripheralInit = 2;
			break;

		case '3' :
			QSPI_UserMenu();
			PeripheralInit = 0;
			break;

		default:
			break;

		}


		if (PeripheralInit) {
			while (1) {
				deviceId = S25FL1D_ReadJedecId();
				printf("ID read: Manufacture ID = 0x%x, Device Type = 0x%x, \
				Capacity = 0x%x\n\r",
					   (uint8_t)(deviceId), (uint8_t)(deviceId >> 8), (uint8_t)(deviceId >> 16));
				break;
			}

			/* erase entire chip  */
			S25FL1D_EraseChip();

			/* fill up the buffer*/
			_fillupbuffer(TestBuffer, BUFFER_SIZE);
			printf("Writing buffer to Flash memory...... \n\r");

			/* write the buffer to flash memory */
			for (i = 0; i < 0x200000; ) {
				S25FL1D_Write(TestBuffer, BUFFER_SIZE, i, 0);
				i += BUFFER_SIZE;
			}

			TestPassed = _VerifyData(0, 0x200000, TestBuffer, 0);

			printf("Erasing a block(64 KB) @ Add 0x10000 \n\r");
			S25FL1D_Erase64KBlock(0x10000);

			memset(TestBuffer, 0xFFFFFF, BUFFER_SIZE);
			SCB_CleanDCache_by_Addr((uint32_t *)TestBuffer, sizeof(TestBuffer));
			TestPassed = _VerifyData(0x10000, (0x10000 + 64 * 1024), TestBuffer, 0);

			if (TestPassed)
				printf(" \n\r**** Test Failed ***** \n\r");
			else
				printf(" \n\r### Test Passed ###\n\r");
		}

		PeripheralInit = 0;
		QSPI_UserMenu();
	}
}
Exemplo n.º 12
0
Arquivo: main.c Projeto: gstroe/Arm
/**
 * \brief Application entry point for RTT example.
 *
 * Initializes the RTT, displays the current time and allows the user to
 * perform several actions: clear the timer, set an alarm, etc.
 *
 * \return Unused (ANSI-C compatibility).
 */
extern int main( void )
{
	unsigned char c;

	/* Disable watchdog */
	WDT_Disable(WDT);
	
	SCB_EnableICache();
	SCB_EnableDCache();
	
	/* Output example information */
	printf("-- RTT Example %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME);

	/* Configure RTT */
	_ConfigureRtt();

	/* Initialize state machine */
	state = STATE_MAINMENU;
	alarmed = 0;
	_RefreshDisplay();

	/* User input loop */
	while (1) {
		/* Wait for user input */
		c = DBG_GetChar();

		/* Main menu mode */
		if (state == STATE_MAINMENU) {
			/* Reset timer */
			if (c == 'r') {
				_ConfigureRtt();
				_RefreshDisplay();
			}
			/* Set alarm */
			else
				if (c == 's') {
					state = STATE_SETALARM;
					newAlarm = 0;
					_RefreshDisplay();
				}
			/* Clear alarm */
				else {
					if ((c == 'c') && alarmed) {
						alarmed = 0;
						_RefreshDisplay();
					}
				}
		}
		/* Set alarm mode */
		else {
			if (state == STATE_SETALARM) {
				/* Number */
				if ((c >= '0') && (c <= '9')) {
					newAlarm = newAlarm * 10 + c - '0';
					_RefreshDisplay();
				}
				/* Backspace */
				else {
					if (c == 8) {
						newAlarm /= 10;
						_RefreshDisplay();
					}
					/* Enter key */
					else {
						if (c == 13) {
							/* Avoid newAlarm = 0 case */
							if (newAlarm != 0) {
								RTT_SetAlarm(RTT, newAlarm);
							}
							state = STATE_MAINMENU;
							_RefreshDisplay();
						}
					}
				}
			}
		}
	}
}
Exemplo n.º 13
0
/**
 * Disk test
 * \param iMci Controller number.
 * \param clr  Do block clear.
 * \param wr   Do block write.
 * \param rd   Do block read.
 */
static void DiskTest(uint8_t iMci,
        uint8_t clr,
        uint8_t wr,
        uint8_t rd)
{
    sSdCard *pSd = &sdDrv[iMci];
    uint8_t error = 0;
    uint32_t i, errcnt = 0;
    uint32_t multiBlock, block, splitMulti;

    DumpSeperator();
    printf("-!- Test code: 1.clr, 2.wr, 3.rd\n\r");

    /* Perform tests on each block */
    multiBlock = 0;
    for (block = TEST_BLOCK_START;
            block < TEST_BLOCK_END;
            block += multiBlock) {

        /* Perform different single or multiple bloc operations */
        if (multiBlock >= 16)   multiBlock <<= 1;
        else                    multiBlock ++;
        if (multiBlock > NB_MULTI_BLOCKS)
            multiBlock = 1;

        /* Multi-block adjustment */
        if (block + multiBlock > TEST_BLOCK_END) {
            multiBlock = TEST_BLOCK_END - block;
        }

        /* ** Perform single block or multi block transfer */
        printf("\r-I- Testing block [%6u - %6u] ...", (unsigned int)block, (unsigned int)(block + multiBlock -1));

        if (clr) {
            /* - Clear the block */
            memset(pBuffer, 0, SDMMC_BLOCK_SIZE * multiBlock);
            for (i=0; i < SDMMC_BLOCK_SIZE * multiBlock; i++) {
                if (pBuffer[i] != 0) {
                    /* Fatal error */
                    printf("\n\r-F- Data @ %u for write : 0x00 <> 0x%02x\n\r", (unsigned int)i, pBuffer[i]);
                    return;
                }
            }
            error = MMCT_WriteFun(pSd, block, multiBlock, pBuffer);
            if (error) {
                printf("\n\r-E- 1. Write block (%d) #%u\n\r", error, (unsigned int)block);
                if(MaxErrorBreak(0)) return;
                /* Skip following test */
                continue;
            }
            /* - Read back the data to check the write operation */
            memset(pBuffer, 0xFF, SDMMC_BLOCK_SIZE * multiBlock);
            error = MMCT_ReadFun(pSd, block, multiBlock, pBuffer);
            if (error) {
                printf("\n\r-E- 1. Read block (%d) #%u\n\r", error, (unsigned int)block);
                if(MaxErrorBreak(0)) return;
                /* Skip following test */
                continue;
            }
            for (i=0; i < SDMMC_BLOCK_SIZE * multiBlock; i++) {
                if (pBuffer[i] != 0) {
                    printf("\n\r-E- 1. B%u.D[%u] : 0 <> 0x%02X\n\r", (unsigned int)block, (unsigned int)i, (int)pBuffer[i]);
                    if(MaxErrorBreak(0)) return;
                    /* Only find first verify error. */
                    break;
                }
            }
        }

        if (wr) {
            /* - Write a checker board pattern on the block */
            for (i=0; i < SDMMC_BLOCK_SIZE * multiBlock; i++) {
                if ((i & 1) == 0)  pBuffer[i] = (i & 0x55);
                else               pBuffer[i] = (i & 0xAA);
            }
            for (i = 0; i < multiBlock; ) {
                splitMulti = ((multiBlock - i) > NB_SPLIT_MULTI) ?
                    NB_SPLIT_MULTI : (multiBlock - i);
                error = MMCT_WriteFun(pSd,
                        block + i,
                        splitMulti,
                        &pBuffer[i * SDMMC_BLOCK_SIZE]);
                if (error) break;
                i += splitMulti;
            }
            if (error)
            {
                printf("\n\r-E- 2. Write block #%u(%u+%u): %d\n\r",  (unsigned int)(block+i), (unsigned int)block, (unsigned int)i, error);
                if(MaxErrorBreak(0)) return;
                /* Skip Following Test */
                continue;
            }
        }

        if (rd) {
            /* - Read back the data to check the write operation */
            memset(pBuffer, 0, SDMMC_BLOCK_SIZE * multiBlock);
            for (i = 0; i < multiBlock; ) {
                splitMulti = ((multiBlock - i) > NB_SPLIT_MULTI) ?
                    NB_SPLIT_MULTI : (multiBlock - i);
                error = MMCT_ReadFun(pSd,
                        block + i,
                        splitMulti,
                        &pBuffer[i * SDMMC_BLOCK_SIZE]);
                if (error) break;
                i += splitMulti;
            }
            if (error)
            {
                printf("\n\r-E- 2. Read block #%u(%u+%u): %d\n\r", (unsigned int)(block + i), (unsigned int)block, (unsigned int)i, error);
                if(MaxErrorBreak(0)) return;
                /* Skip Following Test */
                continue;
            }
            errcnt = 0;
            for (i=0; i < SDMMC_BLOCK_SIZE * multiBlock; i++) {

                if (!(((i & 1) == 0) && (pBuffer[i] == (i & 0x55))) &&
                        !(((i & 1) != 0) && (pBuffer[i] == (i & 0xAA))) ) {
                    uint32_t j, js;
                    printf("\n\r-E- 2.%d. Data @ %u (0x%x)\n\r", (int)errcnt, (unsigned int)i, (unsigned int)i);
                    printf("  -Src:");
                    js = (i > 8) ? (i - 8) : 0;
                    for (j = js; j < i + 8; j ++)
                        printf(" %02x", (unsigned int)(((j & 1)!= 0) ? (j & 0xAA):(j & 0x55)));
                    printf("\n\r  -Dat:");
                    for (j = js; j < i + 8; j ++)
                        printf("%c%02x", (i == j) ? '!' : ' ', pBuffer[j]);
                    printf("\n\r");
                    if(MaxErrorBreak(0)) return;
                    // Only find first 3 verify error.
                    if (errcnt ++ >= 3)
                        break;
                }
            }
        }

        if (DBG_IsRxReady()) {
            switch(DBG_GetChar()) {
                /* Skip 100M */
                case 'k':
                    block += TEST_BLOCK_SKIP;
                    if (block > TEST_BLOCK_END) {
                        block -= 5 + multiBlock;
                    }
                    printf("\n\r");
                    break;
                    /* Cancel */
                case 'c':
                    return;
            }
        }
    }

    printf("All block tested!\n\r");
}
Exemplo n.º 14
0
/**
 *  \brief hsmci_multimedia_card Application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
    uint8_t connected = 0;

    /* Disable watchdog */
    WDT_Disable( WDT ) ;
    
    SCB_EnableICache();        
    SCB_EnableDCache();
    TimeTick_Configure();

    /* Output example information*/
    printf("-- MultiMedia Card Example %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
    bMciID = 0;
    /* Initialize PIO pins */
    _ConfigurePIOs();

    /* Initialize drivers */
    _ConfigureDrivers();


    /* Card insert detection loop */
    for(;;) {

        if (CardIsConnected(bMciID)) {
            if (connected == 0) {
                connected = 1;
                /* Delay before card initialize */
                Wait(300);
                /* Do card test */
                CardInit(bMciID);
                DumpMenu();
            }
        }
        else if (connected) {
            connected = 0;
            printf("** Card Disconnected\n\r");
        }


        if (DBG_IsRxReady()) 
        {
            uint8_t key = DBG_GetChar();
            switch(key) 
            {
                /* Change performance test block size */
                case 'c':
                case 'C': 
                    {   
                        if (performanceMultiBlock >= NB_MULTI_BLOCKS)
                            performanceMultiBlock = 1;
                        else
                            performanceMultiBlock <<= 1;
                        printf("-!- Performance Multi set to %d\n\r", (int)performanceMultiBlock);
                    }
                    break;
                /* Show help information */
                default:
                    if (!connected) 
                    {
                        DumpMenu();
                    }
                    else 
                    {
                        switch(key){
                            /* Dump block contents */
                            case 'd':
                            case 'D':
                                BlockDump(bMciID);  
                                break;
                            /* Initialize the card again */
                            case 'I':  
                            case 'i':    
                                CardInit(bMciID);   
                                break;
                            /* Run test on whole disk */
                            case 't':
                            case 'T':
                                if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDIO)
                                    SdioTest(bMciID);
                                if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDMMC)
                                    DiskTest(bMciID, 1, 1, 1);
                                printf("\n\r");  
                                break;
                            /* Run performance test */
                            case 'P':
                            case 'p':
                                if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDIO)
                                    SdioPerformanceTest(bMciID);
                                if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDMMC)
                                    DiskPerformanceTest(bMciID, 1, 1, 0);
                                printf("\n\r");
                                break;
                            /* Read/Verify ONLY test */
                            case 'r': 
                            case 'R':
                                DiskTest(bMciID, 0, 0, 1);
                                printf("\n\r");
                                break;
                            /* Read/Verify ONLY performance test */
                            case 'V':
                            case 'v':
                                DiskPerformanceTest(bMciID, 0, 1, 1);
                                printf("\n\r");
                                break;
                            /* Show help information */
                            default:   
                                DumpMenu();
                        }
                    }
                    break;
            }
        }
    }
}
Exemplo n.º 15
0
Arquivo: main.c Projeto: gstroe/Arm
/**
 *  \brief Application entry point for MPU example.
 *
 *  \return Unused (ANSI-C compatibility).
 */
extern int main( void )
{
	uint8_t ucChoice = 0;

	/* Disable watchdog */
	WDT_Disable(WDT);

	uint32_t *pdw = (uint32_t *)MPU_SRAM_PRIVILEGE_START_ADDRESS;

	/* Output example information */
	printf("\n\r\n\r\n\r");
	printf("-- MPU Example %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME);

	LED_Configure(LED_YELLOW0);

	/* Set up the default memory regions */
	_SetupMPU();

	/* Set the environment to thread mode */
	__set_CONTROL(USER_MODE);

	while (ucChoice != '9') {
		printf("----------------------------------------\n\r");
		printf("    Choose an option below:\n\r");
		printf("    1. Protect the Yellow LED region\n\r");
		printf("    2. UN-protect the Yellow LED region\n\r");
		printf("    3. Toggle the green LED\n\r");
		printf("    4. Set the RAM region to read only \n\r");
		printf("    5. Set the RAM region to read/write\n\r");
		printf("    6. Read the RAM content at offset 0\n\r");
		printf("    7. Write the RAM context at offset 0\n\r");
		printf("    8. Quit the external program\n\r");
		printf("\n\r");
		printf("  Choice: ");

		ucChoice = DBG_GetChar();
		DBG_PutChar(ucChoice);
		printf("\n\r");

		switch (ucChoice) {
		case '1':
			_UpdateMPU(MPU_PIOC_REGION_REGION,
					MPU_PIOC_PERIPHERALS_REGION_START_ADDRESS |
					MPU_REGION_VALID |
					MPU_PIOC_REGION_REGION,
					MPU_AP_UNPRIVILEGED_READONLY |
					MPU_REGION_EXECUTE_NEVER |
					MPU_CalMPURegionSize(MPU_PIOC_PERIPHERALS_REGION_END_ADDRESS - MPU_PIOC_PERIPHERALS_REGION_START_ADDRESS) |
						MPU_REGION_ENABLE);
			break;

		case '2':
			_UpdateMPU(MPU_PIOC_REGION_REGION,
					MPU_PIOC_PERIPHERALS_REGION_START_ADDRESS |
					MPU_REGION_VALID |
					MPU_PIOC_REGION_REGION,
					MPU_AP_FULL_ACCESS |
					MPU_REGION_EXECUTE_NEVER |
					MPU_CalMPURegionSize(MPU_PIOC_PERIPHERALS_REGION_END_ADDRESS -
						MPU_PIOC_PERIPHERALS_REGION_START_ADDRESS) |
					MPU_REGION_ENABLE);
			break;

		case '3':
		/* Set back to unprivileged mode*/

			LED_Toggle(LED_YELLOW0);
			__set_CONTROL(USER_MODE);
			break;

		case '4':
			_UpdateMPU(MPU_PRIVILEGE_RAM_REGION,
					MPU_SRAM_PRIVILEGE_START_ADDRESS |
					MPU_REGION_VALID |
					MPU_PRIVILEGE_RAM_REGION,
					MPU_AP_UNPRIVILEGED_READONLY |
					MPU_REGION_CACHEABLE |
					MPU_REGION_BUFFERABLE |
					MPU_TEX_B001|
					MPU_CalMPURegionSize(MPU_SRAM_PRIVILEGE_END_ADDRESS -
					MPU_SRAM_PRIVILEGE_START_ADDRESS) |
					MPU_REGION_ENABLE);
			break;

		case '5':
			_UpdateMPU(MPU_PRIVILEGE_RAM_REGION,
					MPU_SRAM_PRIVILEGE_START_ADDRESS |
					MPU_REGION_VALID |
					MPU_PRIVILEGE_RAM_REGION,
					MPU_AP_FULL_ACCESS |
					MPU_REGION_CACHEABLE |
					MPU_REGION_BUFFERABLE |
					MPU_TEX_B001|
					MPU_CalMPURegionSize(MPU_SRAM_PRIVILEGE_END_ADDRESS -
					MPU_SRAM_PRIVILEGE_START_ADDRESS) |
					MPU_REGION_ENABLE);

			break;

		case '6':
			printf("-I- RAM address has content %x \n\r",(unsigned)(pdw[0]));
			break;

		case '7':
			printf("-I- Write offset 0 of RAM region with content 0x55AA55AA\n\r");
			pdw[0] = 0x55AA55AA;
			break;

		case '8':
			printf("-I- MPU TEST FINISH ...\n\r");
			break;

		default:
			printf("-I- This option is not valid\n\r");
			break;
		}
	}
	/* Setback to privilege mode, before entering the main routine,
	   it is supervisor mode*/
	__ASM volatile(" svc 0x00 ");
	while (!dwRaisePriDone);
	dwRaisePriDone = 0;

	__set_CONTROL(PRIVILEGE_MODE);

	return 0;
}