feat: Refactor clock configuration, update HSE startup timeout, and enhance UART heartbeat message
This commit is contained in:
@ -100,7 +100,7 @@
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSE_STARTUP_TIMEOUT)
|
||||
#define HSE_STARTUP_TIMEOUT 1000U /*!< Time out for HSE start up, in ms */
|
||||
#define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
|
||||
@ -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;
|
||||
|
||||
8
flash_openocd.sh
Executable file
8
flash_openocd.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
openocd \
|
||||
-f interface/cmsis-dap.cfg \
|
||||
-f target/stm32f4x.cfg \
|
||||
-c "adapter speed 4000" \
|
||||
-c "transport select swd" \
|
||||
-c "program build/stmf411re_test.elf verify reset exit"
|
||||
3
flash_probe_rs.sh
Executable file
3
flash_probe_rs.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
probe-rs download --chip STM32F411RE build/stmf411re_test.elf --verify
|
||||
@ -17,18 +17,19 @@ Mcu.Name=STM32F411R(C-E)Tx
|
||||
Mcu.Package=LQFP64
|
||||
Mcu.Pin0=PC14-OSC32_IN
|
||||
Mcu.Pin1=PC15-OSC32_OUT
|
||||
Mcu.Pin10=PB3
|
||||
Mcu.Pin11=PB6
|
||||
Mcu.Pin12=VP_SYS_VS_Systick
|
||||
Mcu.Pin10=PA14
|
||||
Mcu.Pin11=PB3
|
||||
Mcu.Pin12=PB6
|
||||
Mcu.Pin13=VP_SYS_VS_Systick
|
||||
Mcu.Pin2=PH0 - OSC_IN
|
||||
Mcu.Pin3=PH1 - OSC_OUT
|
||||
Mcu.Pin4=PA2
|
||||
Mcu.Pin5=PA3
|
||||
Mcu.Pin6=PA9
|
||||
Mcu.Pin7=PA10
|
||||
Mcu.Pin8=PA13
|
||||
Mcu.Pin9=PA14
|
||||
Mcu.PinsNb=13
|
||||
Mcu.Pin6=PA8
|
||||
Mcu.Pin7=PA9
|
||||
Mcu.Pin8=PA10
|
||||
Mcu.Pin9=PA13
|
||||
Mcu.PinsNb=14
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32F411RETx
|
||||
@ -67,6 +68,8 @@ PA3.GPIO_Label=USART_RX
|
||||
PA3.Locked=true
|
||||
PA3.Mode=Asynchronous
|
||||
PA3.Signal=USART2_RX
|
||||
PA8.Mode=Clock-out-1
|
||||
PA8.Signal=RCC_MCO_1
|
||||
PA9.Mode=Asynchronous
|
||||
PA9.Signal=USART1_TX
|
||||
PB3.GPIOParameters=GPIO_Label
|
||||
@ -120,41 +123,42 @@ ProjectManager.UAScriptAfterPath=
|
||||
ProjectManager.UAScriptBeforePath=
|
||||
ProjectManager.UnderRoot=false
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USART1_UART_Init-USART1-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true
|
||||
RCC.48MHZClocksFreq_Value=32000000
|
||||
RCC.AHBFreq_Value=32000000
|
||||
RCC.APB1CLKDivider=RCC_HCLK_DIV2
|
||||
RCC.APB1Freq_Value=16000000
|
||||
RCC.APB1TimFreq_Value=32000000
|
||||
RCC.APB2Freq_Value=32000000
|
||||
RCC.APB2TimFreq_Value=32000000
|
||||
RCC.CortexFreq_Value=32000000
|
||||
RCC.EthernetFreq_Value=32000000
|
||||
RCC.FCLKCortexFreq_Value=32000000
|
||||
RCC.48MHZClocksFreq_Value=48000000
|
||||
RCC.AHBFreq_Value=48000000
|
||||
RCC.APB1Freq_Value=48000000
|
||||
RCC.APB1TimFreq_Value=48000000
|
||||
RCC.APB2Freq_Value=48000000
|
||||
RCC.APB2TimFreq_Value=48000000
|
||||
RCC.CortexFreq_Value=48000000
|
||||
RCC.EthernetFreq_Value=48000000
|
||||
RCC.FCLKCortexFreq_Value=48000000
|
||||
RCC.FLatency-AdvancedSettings=FLASH_LATENCY_1
|
||||
RCC.FamilyName=M
|
||||
RCC.HCLKFreq_Value=32000000
|
||||
RCC.HSE_Timout=1000
|
||||
RCC.HCLKFreq_Value=48000000
|
||||
RCC.HSE_VALUE=8000000
|
||||
RCC.HSI_VALUE=16000000
|
||||
RCC.I2SClocksFreq_Value=48000000
|
||||
RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FLatency-AdvancedSettings,FamilyName,HCLKFreq_Value,HSE_Timout,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLM,PLLN,PLLP,PLLQCLKFreq_Value,PLLSourceVirtual,PWR_Regulator_Voltage_Scale,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOInputMFreq_Value,VCOOutputFreq_Value,VcooutputI2S
|
||||
RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FLatency-AdvancedSettings,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLM,PLLP,PLLQCLKFreq_Value,PLLSourceVirtual,PWR_Regulator_Voltage_Scale,RCC_MCO1Source,RCC_MCODiv1,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOInputMFreq_Value,VCOOutputFreq_Value,VcooutputI2S
|
||||
RCC.LSE_VALUE=32768
|
||||
RCC.LSI_VALUE=32000
|
||||
RCC.MCO2PinFreq_Value=32000000
|
||||
RCC.PLLCLKFreq_Value=32000000
|
||||
RCC.MCO1PinFreq_Value=24000000
|
||||
RCC.MCO2PinFreq_Value=48000000
|
||||
RCC.PLLCLKFreq_Value=48000000
|
||||
RCC.PLLM=8
|
||||
RCC.PLLN=128
|
||||
RCC.PLLP=RCC_PLLP_DIV4
|
||||
RCC.PLLQCLKFreq_Value=32000000
|
||||
RCC.PLLQCLKFreq_Value=48000000
|
||||
RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
|
||||
RCC.PWR_Regulator_Voltage_Scale=PWR_REGULATOR_VOLTAGE_SCALE3
|
||||
RCC.PWR_Regulator_Voltage_Scale=PWR_REGULATOR_VOLTAGE_SCALE2
|
||||
RCC.RCC_MCO1Source=RCC_MCO1SOURCE_PLLCLK
|
||||
RCC.RCC_MCODiv1=RCC_MCODIV_2
|
||||
RCC.RTCFreq_Value=32000
|
||||
RCC.RTCHSEDivFreq_Value=4000000
|
||||
RCC.SYSCLKFreq_VALUE=32000000
|
||||
RCC.SYSCLKFreq_VALUE=48000000
|
||||
RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
|
||||
RCC.VCOI2SOutputFreq_Value=96000000
|
||||
RCC.VCOInputFreq_Value=1000000
|
||||
RCC.VCOInputMFreq_Value=500000
|
||||
RCC.VCOOutputFreq_Value=128000000
|
||||
RCC.VCOOutputFreq_Value=192000000
|
||||
RCC.VcooutputI2S=48000000
|
||||
USART1.IPParameters=VirtualMode
|
||||
USART1.VirtualMode=VM_ASYNC
|
||||
|
||||
Reference in New Issue
Block a user