2020-06-24 06:04 AM
Hi, i'm trying to use the LSE clock with the RTC but it doesn't start until i make a state reset or run the code under debug mode.
I have read all other posts of LSE problems in the forum and found a lot of info, almost everything related with hardware or PCB layout, well, i have to admit that my pcb layout is not the best and the hardware parts either.
Hardware:
Schematic:
PCB layout:
The parts i’m using are:
Microcontroller: STM32L431VCT6
Crystal: https://www.digikey.com/products/en?keywords=631-1204-ND
Capacitors: 12pF as indicate the crystal datasheet.
Software:
The program do the next:
Step 3 and 4 repeat periodical
RCC config:
Clocks config:
RTC config:
Initialization:
int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_I2C1_Init();
MX_TIM15_Init();
MX_ADC1_Init();
MX_DMA_Init();
MX_TIM16_Init();
MX_USART1_UART_Init();
MX_TIM6_Init();
MX_DAC1_Init();
MX_USART2_UART_Init();
MX_RTC_Init();
/* USER CODE BEGIN 2 */
my_main();
/* USER CODE END 2 */
Enter STOP 2 mode function:
void D_aDormir(void)
{
//Desactivo los perifericos
HAL_I2C_DeInit(&hi2c1);
HAL_ADC_DeInit(&hadc1);
HAL_DAC_DeInit(&hdac1);
HAL_UART_DeInit(&huart2);
HAL_UART_DeInit(&huart1);
HAL_TIM_Base_DeInit(&htim6);
HAL_TIM_PWM_DeInit(&htim15);
HAL_TIM_Base_DeInit(&htim15);
HAL_TIM_PWM_DeInit(&htim16);
HAL_TIM_Base_DeInit(&htim16);
__HAL_RCC_I2C1_CLK_DISABLE();
__HAL_RCC_TIM6_CLK_DISABLE();
__HAL_RCC_TIM15_CLK_DISABLE();
__HAL_RCC_TIM16_CLK_DISABLE();
//Poner todos los pines posibles como entrada analogica
GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.Pin = GPIO_PIN_All;
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
GPIO_InitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_DeInit(GPIOA, GPIO_InitStructure.Pin);
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
HAL_GPIO_DeInit(GPIOB, GPIO_InitStructure.Pin);
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
HAL_GPIO_DeInit(GPIOD, GPIO_InitStructure.Pin);
HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
HAL_GPIO_DeInit(GPIOH, GPIO_InitStructure.Pin);
HAL_GPIO_Init(GPIOH, &GPIO_InitStructure);
GPIO_InitStructure.Pin &= (~SMBUSALERT_Pin);
HAL_GPIO_DeInit(GPIOC, GPIO_InitStructure.Pin);
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_All;
GPIO_InitStructure.Pin &= (~MODE_OFF_Pin);
HAL_GPIO_DeInit(GPIOE, GPIO_InitStructure.Pin);
HAL_GPIO_Init(GPIOE, &GPIO_InitStructure);
// Disable GPIOs clock
__HAL_RCC_GPIOA_CLK_DISABLE();
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOD_CLK_DISABLE();
HAL_DBGMCU_DisableDBGSleepMode();
HAL_DBGMCU_DisableDBGStopMode();
HAL_DBGMCU_DisableDBGStandbyMode();
//Desactivar el clock de los puertos posibles
//Desactivar systick
HAL_SuspendTick();
NVIC_ClearPendingIRQ(EXTI15_10_IRQn);
NVIC_ClearPendingIRQ(EXTI9_5_IRQn);
if(HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 30, RTC_WAKEUPCLOCK_CK_SPRE_16BITS) != HAL_OK)
{
Error_Handler();
}
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
}
Wake up function:
void D_despertar(void)
{
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_I2C1_Init();
MX_TIM15_Init();
MX_ADC1_Init();
MX_DMA_Init();
MX_TIM16_Init();
MX_TIM6_Init();
MX_DAC1_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
//Activar systick
HAL_ResumeTick();
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
/* Señal de encendido */
buzzer_flag = true;
}
The program works well, but the problem is that the LSE don't start (the program get stuck) until a reset pulse or running the code under debugging. And if i power off and power on the board, the LSE get stuck again.
I tried almost everything, changed the LSE startup timeout, the drive capability, tried with different parallel resistors to the crystal, cleaning and drying the board.
I haven't tried changing the capacitors because i don't have any, but i can get some to try.
The problem happen in all the boards
So my questions are:
Why it’s only working after a reset and not on a power up?
It’s a software o hardware problem?
I have to change the crystal layout?
I have to change the crystal/caps parts?
Regards,
Tomás
2020-06-24 06:09 AM
I had a similar issue with some boards and the problem was in the capacitors. Try removing them completely on one board and see what happens. If that works try some known good caps - probably of a lower value say 9pF
2020-06-24 09:15 AM
Thanks for the reply!
I removed the capacitors but unfortunately it didn't work either
2020-06-24 01:41 PM
The Load capacitance given by DS does not mean you put two capacitors of that capacitance next to the crystal. Read AN2867.
Without using Cube, after having read the relevant portions of RCC chapter in RM, write a minimal program writing directly to registers, which only starts the LSE oscillator, without any timeout, and indicates when it succeeds (e.g. lighting up a LED).
Experiment with drive strength.
JW
2020-06-24 08:28 PM
C24/C25 are almost certainly too big.
Look at AN2867 for how to calculate what the capacitors should be.
They also list some recommended parts. Note that C0 is way less than what you have.