2020-06-01 01:57 AM
I have a project using a STM32f107VC which I am trying to update and I run into some problem configuring the clock in the updated environment
So I tried to create a simple project using Stm32CubeMX and I still can't configure the clock properly.
I added code to my main application that blinks a led with delay of 1000 ms but the LED actually blinks every 2000ms (checked with a scope)
I generate an Other Toolchains (GPDSC) project in the CubeMX and then import it to Visual GDB 5.4r12
the project information is :
Stm32CubeMX: version 5.3.0
MCU: STM32F107VCTx
Firmware: STM32Cube FW_F1 V1.8.0
This is the clock configuration:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
//MX_USART1_UART_Init();
//MX_USART2_UART_Init();
//MX_USART3_UART_Init();
//MX_LWIP_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_GPIO_WritePin(GPIOE, RED_LED_Pin | GREEN_LED_Pin, GPIO_PIN_RESET);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOE, RED_LED_Pin | GREEN_LED_Pin, GPIO_PIN_SET);
HAL_Delay(1000);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
2020-06-01 05:37 AM
Post your clock initialization code. How are you generating the delay? If timer, post that code as well.
2020-06-02 11:19 PM
Hi, thank you for your response.
Please see the code in the question. I edited it.
2020-06-03 01:05 AM
HAL_Delay(1000);
What is the source the 1ms tic, SYSTICK? How is that set up? Read out the relevant registers' content and check.
JW
2020-06-03 03:11 AM
I didn't understand what registers to check? I exported the cube mx code, this is the default project. I added only the code inside the while true
2020-06-03 05:49 AM
while (1)
{
HAL_GPIO_WritePin(GPIOE, RED_LED_Pin | GREEN_LED_Pin, GPIO_PIN_RESET);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOE, RED_LED_Pin | GREEN_LED_Pin, GPIO_PIN_SET);
HAL_Delay(1000);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
This is going to blink at a period of 2000ms. On for 1s, off for 1s. So one blink per 2s. Is that not what you're seeing?
2020-06-03 11:21 PM
No, what I'm seeing is 2s ON, 2s OFF.
2020-06-03 11:21 PM
No, what I'm seeing is 2s ON, 2s OFF.
2020-06-04 04:00 AM
seems to be a problem in HAL_RCC_GetSysClockFreq()
in file VisualGDB\EmbeddedBSPs\arm-eabi\com.sysprogs.arm.stm32\2020.01\STM32F1xxxx\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c
there is special handling of the case where *PLLMUL=6.5 where the code multiplies by 13 & later divides by 2 using this code:
if (pllmul == aPLLMULFactorTable[(uint32_t)(RCC_CFGR_PLLMULL6_5) >> RCC_CFGR_PLLMULL_Pos])
{
pllclk = pllclk / 2;
}
the problem is that this is NOT done if the PLL source is RCC_PLLSOURCE_HSI_DIV2
so the calculated SystemCoreClock is wrong
this is a bug in the visual gdb library, not STM cube!