2014-06-19 02:06 PM
Hi,
I am following the instruction on UM1718 user manual, the section on Tutorial 1 from pinout to project C code generation using an STM32F4MCU). The following listed the codes generated by the code generator. I have added code as instructed by the user manual. However, nothing works. Can anyone help, please?Thanks/* Includes ------------------------------------------------------------------*/#include ''stm32f4xx_hal.h''/* Private variables ---------------------------------------------------------*/TIM_HandleTypeDef htim3;/* USER CODE BEGIN 0 *//* USER CODE END 0 *//* Private function prototypes -----------------------------------------------*/static void SystemClock_Config(void);static void MX_GPIO_Init(void);static void MX_TIM3_Init(void);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(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_TIM3_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* USER CODE BEGIN 3 */ HAL_TIM_Base_Start(&htim3); /* Infinite loop */ while (1) { } /* USER CODE END 3 */}/** System Clock Configuration*/static void SystemClock_Config(void){ RCC_OscInitTypeDef RCC_OscInitStruct; __PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = 6; HAL_RCC_OscConfig(&RCC_OscInitStruct);}/* TIM3 init function */void MX_TIM3_Init(void){ TIM_ClockConfigTypeDef sClockSourceConfig; TIM_MasterConfigTypeDef sMasterConfig; htim3.Instance = TIM3; htim3.Init.Prescaler = 16000; htim3.Init.CounterMode = TIM_COUNTERMODE_UP; htim3.Init.Period = 1000; htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; HAL_TIM_Base_Init(&htim3); sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig); sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig);}/** Configure pins as * Analog * Input * Output * EVENT_OUT * EXTI*/void MX_GPIO_Init(void){ GPIO_InitTypeDef GPIO_InitStruct; /* GPIO Ports Clock Enable */ __GPIOD_CLK_ENABLE(); /*Configure GPIO pin : PD12 */ GPIO_InitStruct.Pin = GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);}/* USER CODE BEGIN 4 */void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){ if (htim->Instance==htim3.Instance) HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);}/* USER CODE END 4 */#ifdef USE_FULL_ASSERT/** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */void assert_failed(uint8_t* file, uint32_t line){ /* User can add his own implementation to report the file name and line number, ex: printf(''Wrong parameters value: file %s on line %d\r\n'', file, line) */}#endif/** * @} */ /** * @}*/ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/2014-06-24 12:23 PM
Hello,
Replace in your code : HAL_TIM_Base_Start(&htim1); with: HAL_TIM_Base_Start_IT(&htim3); (as stated in the user manual) Ensure also the proper configuration of the interrupts: in MX configuration tab, check under NVIC settings, TIM3 global interrupt is enabled and set a priority (ex: 15).