16MHz external crystal not working on the S32K314HMS custom board Hi, I am facing an issue with an external crystal of 16MHz not working with S32K314HMS custom board. I am using a build created from S32 Design Studio for S32 Platform Version: 3.6.9 Build id: 260624. I am using raw code to test the board function, as shown below in main.c: #include
/* Corrected Raw Hardware Register Addresses for S32K314 */
#define SIUL2_MSCR_PTB5 (*(volatile uint32_t*)(0x40290294U))
#define MC_CGM_CLKOUT_CNTRL (*(volatile uint32_t*)(0x402D4000U))
/* --- CORRECTED FXOSC REAL ADDRESSES --- */
#define FXOSC_CTRL_REG (*(volatile uint32_t*)(0x40288000U)) /* Corrected from 402D4000 */
#define FXOSC_STAT_REG (*(volatile uint32_t*)(0x40288004U)) /* Corrected from 402D4004 */
volatile uint32_t rawTimeoutCounter = 0;
volatile uint32_t crystalStableResult = 0;
int main(void)
{
/* 1. RAW PIN SETUP: Configure PTB5 as a High-Drive Output mapped to CLKOUT */
SIUL2_MSCR_PTB5 = (5U << 0) | (1U << 21) | (1U << 19);
/* 2. RAW CLOCK ROUTING: Route the Raw FXOSC clock directly to the CLKOUT hardware block */
MC_CGM_CLKOUT_CNTRL = (1U << 24) | (0U << 16); /* Source = FXOSC_CLK, Divider = 1, Enable = 1 */
/* 3. RAW HARDWARE KICKSTART: Power on the External Crystal (FXOSC) analog circuitry */
FXOSC_CTRL_REG |= 0x01U;
/* 4. NON-BLOCKING SOFTWARE POLL
We read the raw hardware status register. If a crystal is physically
oscillating, the status register will flip a hardware bit or report a non-zero value. */
for (rawTimeoutCounter = 0; rawTimeoutCounter < 800000U; rawTimeoutCounter++)
{
/* Check if the FXOSC status register reports it is locked and stable (Bit 31) */
if ((FXOSC_STAT_REG & 0x80000000U) != 0U)
{
crystalStableResult = 1; /* HW SUCCESS: Crystal is alive and shaking! */
break;
}
}
/* 5. PASS / FAIL EVALUATION PADS */
if (crystalStableResult == 1)
{
/* --- CRYSTAL HARDWARE PASSED --- */
for (;;)
{
__asm("NOP"); /* Put a breakpoint here for success */
}
}
else
{
/* --- CRYSTAL HARDWARE FAILED --- */
for (;;)
{
__asm("NOP"); /* Put a breakpoint here for a safe failure catch */
}
}
return 0;
} I am attaching the board schematic for your reference. board_schematic.pngboard_schematic.pngboard_schematic.pngboard_schematic.pngboard_schematic.png Also attaching the .mex configuration for your reference. Re: 16MHz external crystal not working on the S32K314HMS custom board Hello @sksingh4476 ,
a 16 MHz crystal is within the supported FXOSC crystal frequency range for the S32K3 family, so the crystal frequency itself should not be the issue. However, from the raw code snippet it is not clear whether the complete FXOSC configuration is being applied. In particular, please check the FXOSC gain/transconductance setting (GM_SEL). In crystal mode, GM_SEL = 0000b should not be used, because this corresponds to zero transconductance and the oscillator may not start or become stable.
Regarding the mex file: The generated clock initialization code must be called by the application. If the test code bypasses the generated RTD initialization and writes only a few registers manually, then all mandatory FXOSC settings, including GM_SEL, must also be configured manually.
I would recommend first creating any standard S32DS/RTD example project and configuring the FXOSC through the Clock Configuration tool. Please verify whether the external crystal starts correctly with the generated RTD clock initialization code. This is a better baseline than starting directly with a minimal raw-register test, because the generated configuration should include all required FXOSC settings, including the oscillator mode and gain configuration.
If the standard example works, you can then compare the generated FXOSC register values with your minimal code and gradually reduce the code to the smallest required sequence. If the standard example does not work either, then the next step should be to check the hardware side, especially the crystal parameters, ESR, load capacitors including PCB stray capacitance, layout around EXTAL/XTAL, and the gain margin calculation. The datasheet specifies the oscillator build-up condition using gmXOSC > 5 * gm_crit, so the selected crystal and external components should be verified against this requirement.
Best regards,
Pavel Re: 16MHz external crystal not working on the S32K314HMS custom board Hi PavelL, Thanks a lot for the quick response. I tried to find any example code from RTD but did not find one for the S32K314 MCU. I tried calling the clock initialization function in my main function, but the crystal oscillator is still not working. #include "Clock_Ip.h"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "Siul2_Port_Ip.h"
#define LED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define WELCOME_MSG_1 "hello world uart dma\r\n"
int counter, accumulator = 0, limit_value = 1000000;
void Led_Task( void *pvParameters )
{
(void)pvParameters;
for( ;; )
{
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
int main(void) {
Clock_Ip_StatusType Status_Init_Clock = CLOCK_IP_ERROR;
Status_Init_Clock = Clock_Ip_Init(Clock_Ip_aClockConfig);
if (Status_Init_Clock != CLOCK_IP_SUCCESS)
{
while(1); /* Error during initialization. */
}
xTaskCreate( Led_Task , ( const char * const ) "Led_Task", configMINIMAL_STACK_SIZE, (void*)0, LED_TASK_PRIORITY, NULL );
vTaskStartScheduler();
for( ;; );
return 0;
}
uint8_t Sys_GetCoreID(void)
{
return 0U; /* Force return Core 0 (Primary ARM Cortex-M7 Core) */
} FXOSC_CTRL, the value of GM_SEL is the default value 1100. Please refer the attached clock configuration image for your reference. clock_config.pngclock_config.pngclock_config.pngclock_config.png Also attached is the clock configuration file clockYaml for your reference. We observed that another open source project can make the crystal work on the same board. Here is the code used in the main.c file. We observed that the clock configuration is almost the same as ours. I have attached the clock configuration for your reference. /* Including necessary configuration files. */
#include "Clock_Ip.h"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "Siul2_Port_Ip.h"
#include "Siul2_Dio_Ip.h"
//including uart+dma+interrupt files
#include "Lpuart_Uart_Ip.h"
#include "Lpuart_Uart_Ip_Irq.h"
#include "string.h"
#include "IntCtrl_Ip.h"
#include "lpuart0.h"
#include "Dma_Ip.h"
#include "Dma_Ip_Irq.h"
#include "CDD_Rm.h"
#define LED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define WELCOME_MSG_1 "hello world uart dma\r\n"
void Led_Task( void *pvParameters )
{
(void)pvParameters;
for( ;; )
{
Lpuart_Uart_Ip_SyncSend(LPUART_UART_IP_INSTANCE_USING_0, (const uint8 *)WELCOME_MSG_1, 20, 0XFFFF);
Siul2_Dio_Ip_TogglePins(USER_LED0_PORT, (1 << USER_LED0_PIN));
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
int main(void)
{
/* Initialize Clock */
Clock_Ip_StatusType Status_Init_Clock = CLOCK_IP_ERROR;
Status_Init_Clock = Clock_Ip_Init(Clock_Ip_aClockConfig);
if (Status_Init_Clock != CLOCK_IP_SUCCESS)
{
while(1); /* Error during initialization. */
}
/* Initialize all pins using the Port driver */
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. */
}
//Init Interrupt Control
IntCtrl_Ip_Init(&IntCtrlConfig_0);
//Init lpuart0
Lpuart_Uart_Ip_Init(LPUART_UART_IP_INSTANCE_USING_0, &Lpuart_Uart_Ip_xHwConfigPB_0);
//DMA init
Dma_Ip_Init(&Dma_Ip_Sa_xDmaInitPB);
/* Initialize Rm driver for using DmaMux*/
Rm_Init(&Rm_Config);
//turn of AsyncReceive of uart dma, this code must behind Rm_Init(&Rm_Config);
Lpuart_Uart_Ip_AsyncReceive(LPUART_UART_IP_INSTANCE_USING_0, Lpuart0_Receive_Buffer, LPUART0_RECV_BUF_LEN);
xTaskCreate( Led_Task , ( const char * const ) "Led_Task", configMINIMAL_STACK_SIZE, (void*)0, LED_TASK_PRIORITY, NULL );
vTaskStartScheduler();
for( ;; );
return 0;
} I am wondering what clock configuration can make this difference. Thanks, Sunil Re: 16MHz external crystal not working on the S32K314HMS custom board Hello @sksingh4476 ,
Thank you for the update and for sharing both configurations.
I noticed an important difference between the two code examples. In the minimal test, only Clock_Ip_Init() is called, while the working project also calls Siul2_Port_Ip_Init() immediately afterwards. If you determine whether FXOSC is operating by observing the CLKOUT signal on an external pin, the corresponding SIUL2 pin must also be configured for the CLKOUT alternate function. Clock_Ip_Init() configures the clock tree, but it does not by itself configure the physical output pin.
Could you please clarify how you currently determine that FXOSC is not working?
Best regards,
Pavel Re: 16MHz external crystal not working on the S32K314HMS custom board Hi PavelL, Thank you for your response. Your observation gave me a direction to try adding Siul_port_dio module to the project. It seems that adding this port and initializing it can make the clock work. But I still don't understand why this makes a difference. We are using an oscilloscope to directly measure the crystal frequency. Also, we observed that the debugger gets stuck while initializing clocks. Thanks, Sunil
記事全体を表示