2020-02-16 09:01 PM
Hello,
Please lets me known if I had missed any thing here.
Thank you,
Aaron
#include "stm32l4xx_hal_conf.h"
#include "stm32l4r5xx.h"
#include "main.h"
#include <string.h>
/*----------------------------------------------------------------*/
#define TRUE 1
#define FALSE 0
/*----------------------------------------------------------------*/
void UART3_Init(void);
void Error_handler(void);
/*----------------------------------------------------------------*/
UART_HandleTypeDef huart3;
/*----------------------------------------------------------------*/
int main(void)
{
RCC_OscInitTypeDef osc_init;
RCC_ClkInitTypeDef clk_init;
uint8_t msg[17];
HAL_Init();
UART3_Init();
/* Create argument structure for OSCCONFIG */
memset(&osc_init,0,sizeof(osc_init));
osc_init.OscillatorType = RCC_OSCILLATORTYPE_HSE;
osc_init.HSEState = RCC_HSE_BYPASS;
if (HAL_RCC_OscConfig(&osc_init) != HAL_OK) //<-- HSERDY wasn't flag, fail the argument
{
Error_handler(); //<-- program was fail and trapped here
}
/* Create argument structure for CLOCKCONFIG */
memset(&clk_init,0,sizeof(clk_init));
clk_init.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
clk_init.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;
clk_init.AHBCLKDivider = RCC_SYSCLK_DIV2;
clk_init.APB1CLKDivider = RCC_HCLK_DIV2;
clk_init.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&clk_init,FLASH_ACR_LATENCY_0WS) != HAL_OK)
{
Error_handler();
}
__HAL_RCC_HSI_DISABLE();
/*Debug using printf and USART3*/
memset(msg,0,sizeof(msg));
sprintf(msg,"SYSCLK: %lu \r\n",HAL_RCC_GetSysClockFreq());
HAL_UART_Transmit(&huart3, msg, strlen(msg), HAL_MAX_DELAY);
memset(msg,0,sizeof(msg));
sprintf(msg,"HCLK: %lu \r\n",HAL_RCC_GetHCLKFreq());
HAL_UART_Transmit(&huart3, msg, strlen(msg), HAL_MAX_DELAY);
memset(msg,0,sizeof(msg));
sprintf(msg,"PCLK1: %lu \r\n",HAL_RCC_GetPCLK1Freq());
HAL_UART_Transmit(&huart3, msg, strlen(msg), HAL_MAX_DELAY);
memset(msg,0,sizeof(msg));
sprintf(msg,"PCLK2: %lu \r\n",HAL_RCC_GetPCLK2Freq());
HAL_UART_Transmit(&huart3, msg, strlen(msg), HAL_MAX_DELAY);
while(1)
{
}
return 0;
}
/*----------------------------------------------------------------*/
void UART3_Init(void)
{
huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart3.Init.Mode = UART_MODE_TX_RX;
if ( HAL_UART_Init(&huart3)!=HAL_OK)
{
Error_handler();
}
}
/*----------------------------------------------------------------*/
void Error_handler(void)
{
while(1);
}