This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GH6PM: Tiva C DES (Data Encryption Standard)

Part Number: TM4C123GH6PM

Hello,

I would like to know if the TM4C123GH6PM micro-controller supports DES (Data Encryption Standard) I've been trying to get the DES to work but my code keeps hanging when I wait for the CCM0 peripheral to be ready. In other words the CCM0 is never ready. Also when I run this line of code "SysCtlPeripheralPresent(SYSCTL_PERIPH_CCM0)" it always returns false, does this mean the micro-controller cant do DES?

Any help would be greatly appreciated. I have attached my code to this post.

Thanks

//DES

//BIOS Header Files
#include <xdc/std.h>			//Required - For BIOS Types
#include <ti/sysbios/BIOS.h>	//Required - To call BIOS_start()
#include <xdc/runtime/Log.h>	//Log_info() call
#include <xdc/cfg/global.h>		//Header for defined objects/handles

//TivaWare Header Files
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
#include <math.h>

#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/timer.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.c"
#include "driverlib/gpio.c"
#include "driverlib/uart.c"
#include "driverlib/uart.h"
#include "driverlib/adc.c"
#include "driverlib/adc.h"
#include "driverlib/des.c"
#include "driverlib/des.h"

#include "inc/hw_ints.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_gpio.h"

#include "utils/uartstdio.c"
#include "utils/uartstdio.h"
#include "utils/softuart.c"
#include "utils/softuart.h"

//Functions
void DES_Init(void);
void UART_Init(void);
void encrypt(void);
void decrypt(void);
void runDES(void);

//Global
uint32_t DESPlainText[16] = {0xe2bec16b, 0x969f402e, 0x117e3de9, 0x2a179373,
								   0x578a2dae, 0x9cac031e, 0xac6fb79e, 0x518eaf45,
								   0x461cc830, 0x11e45ca3, 0x19c1fbe5, 0xef520a1a,
								   0x45249ff6, 0x179b4fdf, 0x7b412bad, 0x10376ce6};

uint32_t DESKey[2] = {0xc7f51c87, 0x8076211f};
uint32_t DESIV[2] = {0x6d8ecac4, 0x3b27c885};

//main
void main(void){
   DES_Init();
   UART_Init();
   //runDES();
   BIOS_start();
}

//Initialize DES
void DES_Init(){
	//Set CPU Clock to 40MHz. 400MHz PLL/2 = 200 DIV 5 = 40MHz
	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

	//Enable CCM0 Module for DES
	SysCtlPeripheralDisable(SYSCTL_PERIPH_CCM0);
	SysCtlPeripheralReset(SYSCTL_PERIPH_CCM0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_CCM0);

	//Wait for the CCM module to be ready.
	while(!SysCtlPeripheralReady(SYSCTL_PERIPH_CCM0)){}//wont get past this point

	//Reset the DES module before use.
	DESReset(DES_BASE);

	//Configure the DES module.
	DESConfigSet(DES_BASE, DES_CFG_DIR_ENCRYPT | DES_CFG_MODE_CBC | DES_CFG_SINGLE);

	//Set the key.
	DESKeySet(DES_BASE, DESKey);

	//Write the initial value registers.
	DESIVSet(DES_BASE, DESIV);
}

//Initialize UART
void UART_Init(){
	//Enable Peripheral for USB COM
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	//Set pin type for PB0 and PB1 as UART
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0|GPIO_PIN_1);

	//Configure PA0 as U0RX(Receive) and PA1 as U0TX(Transmit)
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);

	//Enable the appropriate module
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

	//Use internal 16MHz clock for UART
	UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

	//Set UART as console output
	UARTStdioConfig(0, 9600, 16000000);
}

//Run DES
void runDES(void){
	uint32_t DESCipherText[16];
	
	//Run DES
	DESDataProcess(DES_BASE, DESPlainText, DESCipherText, 64);

	//Test Print to TerraTerm
	int test = 6;
	UARTprintf("%d", test);
	
	//Print encrypted
	UARTprintf("Encrypted: %d", DESCipherText[0]);

	//check to see if peripheral exists
	UARTprintf ("DES module present = %d\n", SysCtlPeripheralPresent(SYSCTL_PERIPH_CCM0));

	//encrypt message
	//encrypt();

	//decrypt message
	//decrypt();

	//Delay
	SysCtlDelay(3350000);
}