Greetings,
I'm trying to add a PIT Timer Interrupt to the TCPIP2.0.0 example code. The derivative is S32K358, and I'm using S32K3x8-EVB for testing the code.
I have the following setup:
In main.c:
#include "device.h"
#include "Pit_Ip.h"
#include "Clock_Ip.h"
#include "IntCtrl_Ip.h"
#include "Siul2_Port_Ip.h"
#include "Siul2_Dio_Ip.h"
/* The actual TCP/IP test */
extern void start_example(void);
int c1 = 0;
/* Global flag updated in interrupt */
volatile uint8 toggleLed = 0U;
void TimerInterupt1(void)
{
toggleLed = 1U;
}
/* main function */
int main(void)
{
device_init();
start_example();
return 0;
}
In device.c: ( I have migrated most of the MCAL modules to Drivers, and therefore I have removed some modules). I have also removed OsIf in order to check whether it affects the functionality of the TCPIP stack, but the TCPIP examples seem to function well.
#include "S32K358.h"
//#include "Platform.h"
#include "device.h"
#include "Mcal.h"
#include "Mcu.h"
//#include "Port.h"
#include "Siul2_Port_Ip.h"
//#include "OsIf.h"
#include "Eth_43_GMAC.h"
//#include "Dio.h"
#include "Siul2_Dio_Ip.h"
#ifndef USING_OS_FREERTOS
//#include "Gpt.h"
#endif
#include "Pit_Ip.h"
#include "IntCtrl_Ip.h"
#include "apps/led_control/led.h"
void device_init(void)
{
/* Set RMII configuration for EMAC in DCM module */
IP_DCM_GPR->DCMRWF1 = (IP_DCM_GPR->DCMRWF1 & ~DCM_GPR_DCMRWF1_MAC_CONF_SEL_MASK) | DCM_GPR_DCMRWF1_MAC_CONF_SEL(2U);
// /* Initialize Os Interface */
// OsIf_Init(NULL_PTR);
/* Initialize all pins using the Port driver */
//Port_Init(NULL_PTR);
Siul2_Port_Ip_PortStatusType Status_Init_Port = SIUL2_PORT_ERROR;
Status_Init_Port = Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS_PortContainer_0_BOARD_InitPeripherals, g_pin_mux_InitConfigArr_PortContainer_0_BOARD_InitPeripherals);
if(Status_Init_Port != SIUL2_PORT_SUCCESS)
{
while(1); /* Error during initialization. */
}
/* Setup Clocks */
/* Initialize Mcu module */
Mcu_Init(NULL_PTR);
/* Initialize Mcu clock */
Mcu_InitClock(McuClockSettingConfig_0);
while (Mcu_GetPllStatus() != MCU_PLL_LOCKED){};
/* Use PLL clock */
Mcu_DistributePllClock();
Mcu_SetMode(McuModeSettingConf_0);
// /* Initialize Platform driver */
// Platform_Init(NULL_PTR);
/* set PIT 0 interrupt */
IntCtrl_Ip_Init(&IntCtrlConfig_0);
IntCtrl_Ip_EnableIrq(PIT0_IRQn);
/* Initialize PIT instance 0 - Channel 0 */
Pit_Ip_Init(PIT_INST_0, &PIT_0_ChannelConfig_PB_BOARD_InitPeripherals);
/* Initialize channel 0 */
Pit_Ip_InitChannel(PIT_INST_0, PIT_0_CH_0);
/* Enable channel interrupt PIT_0 - CH_0 */
Pit_Ip_EnableChannelInterrupt(PIT_INST_0, CH_0);
/* Start channel CH_0 */
Pit_Ip_StartChannel(PIT_INST_0, CH_0, PIT_PERIOD_0);
/* Initialize channel 0 */
Pit_Ip_InitChannel(PIT_INST_0, PIT_0_CH_1);
/* Enable channel interrupt PIT_0 - CH_0 */
Pit_Ip_EnableChannelInterrupt(PIT_INST_0, CH_1);
/* Start channel CH_0 */
Pit_Ip_StartChannel(PIT_INST_0, CH_1, PIT_PERIOD_1);
#ifndef USING_OS_FREERTOS
// /* Initialize PIT driver and start the timer */
// Gpt_Init(&Gpt_Config_BOARD_InitPeripherals);
// /* Start the Gpt timer */
// Gpt_StartTimer(GptConf_GptChannelConfiguration_GptChannelConfiguration_0, 40000000U);
// /* Enable the Gpt notification*/
// Gpt_EnableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_0);
// OsIf_SetTimerFrequency(160000000U, OSIF_USE_SYSTEM_TIMER);
#endif /* USING_OS_FREERTOS */
/* Initialize and enable the GMAC module */
Eth_43_GMAC_Init(NULL_PTR);
}
#include "BasicTypes.h"
#ifndef DEVICE_H
#define DEVICE_H
// 40000000 is one second
// 4000000 is 100 ms
// 400000 is 10 ms
#define PIT_PERIOD_0 2000000 //100ms
#define PIT_PERIOD_1 400000 // 10 ms
#define PIT_PERIOD_2 4000 //100 us
#define PIT_INST_0 0
#define PIT_INST_1 1
#define PIT_INST_2 2
#define CH_0 0
#define CH_1 1
#define CH_2 2
void device_init(void);
#endif
In test.c's while loop I have the following setup:
/* Toggle the gpio pin to blink the LED when the Pit notification is called */
if (1U == toggleLed)
{
//Siul2_Dio_Ip_TogglePins(LED_PORT, (1UL << LED_PIN));
led0_red();
toggleLed = 0U;
}
void led0_red(void){
// Dio_WriteChannel(DioConf_DioChannel_LED0_RED, STD_HIGH);
// Dio_WriteChannel(DioConf_DioChannel_LED0_GREEN, STD_LOW);
// Dio_WriteChannel(DioConf_DioChannel_LED0_BLUE, STD_LOW);
Siul2_Dio_Ip_WritePin(LED0_RED_PORT, LED0_RED_PIN, STD_HIGH);
Siul2_Dio_Ip_WritePin(LED0_GREEN_PORT, LED0_GREEN_PIN, STD_LOW);
Siul2_Dio_Ip_WritePin(LED0_BLUE_PORT, LED0_BLUE_PIN, STD_LOW);
}
The configuration in PINtool is as follows:
The configuration in the peripheral tool:
I have also set breakpoints insider the TimerInterupt1(); function, which is supposed to be called every 50 ms, but the execution never reaches the breakpoint.
Is there anything that I'm missing?
I compared with the available Pit_Gpt_Ip_example as well, but couldn't find why the modifications that I made to TCPIP example isn't working with respect to the timer interrupts, while the rest of the functionality of the TCPIP example works perfectly.
Hi @ajosep12
If possible, could you please share your project? I would like to conduct a detailed analysis of the configurations to ensure that all requirements are met. Additionally, I would like to test it on my side to verify if I can reproduce the behavior you are describing.
I also recommend commenting out any functions that are not related to the PIT functionality. This will help isolate the issue and simplify troubleshooting.
BR, VaneB