feat: Refactor clock configuration, update HSE startup timeout, and enhance UART heartbeat message
This commit is contained in:
@ -21,6 +21,7 @@
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include <stdio.h>
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
@ -58,7 +59,7 @@ static void MX_USART2_UART_Init(void);
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
static const char heartbeat_msg[] = "PB6 heartbeat\r\n";
|
||||
static char heartbeat_buf[64];
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
@ -101,9 +102,16 @@ int main(void)
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1) {
|
||||
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6);
|
||||
/* Heartbeat: emit status over UART1 and blink the PB6 LED */
|
||||
HAL_UART_Transmit(&huart1, (uint8_t *)heartbeat_msg,
|
||||
sizeof(heartbeat_msg) - 1, HAL_MAX_DELAY);
|
||||
/* Heartbeat: emit tick timestamp over UART1 and blink the PB6 LED */
|
||||
int msg_len = snprintf(heartbeat_buf, sizeof(heartbeat_buf),
|
||||
"PB6 heartbeat %lu\r\n", (unsigned long)HAL_GetTick());
|
||||
if (msg_len > 0) {
|
||||
if (msg_len >= (int)sizeof(heartbeat_buf)) {
|
||||
msg_len = (int)sizeof(heartbeat_buf) - 1;
|
||||
}
|
||||
HAL_UART_Transmit(&huart1, (uint8_t *)heartbeat_buf, (uint16_t)msg_len,
|
||||
HAL_MAX_DELAY);
|
||||
}
|
||||
HAL_Delay(1000);
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
@ -124,7 +132,7 @@ void SystemClock_Config(void)
|
||||
/** Configure the main internal regulator output voltage
|
||||
*/
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
@ -134,7 +142,7 @@ void SystemClock_Config(void)
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||
RCC_OscInitStruct.PLL.PLLN = 128;
|
||||
RCC_OscInitStruct.PLL.PLLN = 192;
|
||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||
RCC_OscInitStruct.PLL.PLLQ = 4;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
@ -148,13 +156,14 @@ void SystemClock_Config(void)
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_PLLCLK, RCC_MCODIV_2);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,6 +253,14 @@ static void MX_GPIO_Init(void)
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin : PA8 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_8;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PB6 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_6;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
|
||||
Reference in New Issue
Block a user