Tool/software:
Hello,
my system clock is 120MHz. For implementation of a TRNG with an acceptable entropy I want to try to run one timer with PIOSC. This is the code used:
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"
#include "inc/hw_types.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_uart.h"
#include "inc/hw_timer.h"
#include "inc/hw_hibernate.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/hibernate.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
void Timer0IntHandler(void);
uint32_t g_ui32SysClock = 0;
void main(void)
{
// Systemclock auf 120 MHz
g_ui32SysClock = SysCtlClockFreqSet(SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480, 120000000);
SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);
while (!SysCtlPeripheralReady(SYSCTL_PERIPH_HIBERNATE)) {}
HibernateEnableExpClk(g_ui32SysClock);
HWREG(HIB_CC) = HIBERNATE_OUT_SYSCLK;
// Set ALTCLK to PIOSC.
SysCtlAltClkConfig(SYSCTL_ALTCLK_PIOSC);
// GPIO für CCP-Ausgänge (optional für Oszilloskop)
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);
while (!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOM))
;
// GPIOPinConfigure(GPIO_PM6_T5CCP0);
// GPIOPinTypeTimer(GPIO_PORTM_BASE, GPIO_PIN_6);
GPIOPinTypeGPIOOutput(GPIO_PORTM_BASE, GPIO_PIN_6);
GPIOPinWrite(GPIO_PORTM_BASE, GPIO_PIN_6, 0);
// Initialize Timer 0
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
while (!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0))
;
// TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);
TimerConfigure(TIMER0_BASE, TIMER_CFG_A_PERIODIC);
TimerClockSourceSet(TIMER0_BASE, TIMER_CLOCK_PIOSC);
TimerPrescaleSet(TIMER0_BASE, TIMER_A, 255);
TimerLoadSet(TIMER0_BASE, TIMER_A, 624);
TimerIntRegister(TIMER0_BASE, TIMER_A, Timer0IntHandler);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
IntEnable(INT_TIMER0A);
IntMasterEnable();
TimerEnable(TIMER0_BASE, TIMER_A);
while(1)
{
__WFI();
}
}
void Timer0IntHandler(void)
{
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
uint8_t ui8Pin = GPIOPinRead(GPIO_PORTM_BASE, GPIO_PIN_6);
GPIOPinWrite(GPIO_PORTM_BASE, GPIO_PIN_6, ui8Pin ^ GPIO_PIN_6);
}
I tried different things: running as a periodic counter or in PWM mode (as i want to see the frequency on an oszilloscope for debugging). I am using the 16bit-counter TIMER0A, as I was reading in the forum, that the 32bit-mode is not working at all with a different clock source. I even tried to set ALTCLK to PIOSC and activated Hibernation just to try out if this helps. But whatever I try - the timer is running at 120MHz (GPTMCC = 0x01 !!!).
Is there a way to get this timer running with the 16MHz clock of PIOSC?
Regards
Klaus
