cancel
Showing results for 
Search instead for 
Did you mean: 

Just found out about CubeMX, was doing it the hard way before this..... I have not found a way in MX to create a complete thread based program.

BEppe.1
Associate II

I cannot find anything in the code generation which allows for me to easily, being the operative word, create threads from the generated code. I have not been able to find any examples either to this nature.

What is the best way to go from a standard "main" loop to a thread based generated program? Are there any examples? Every time I create a thread I get an unhappy compiler. There is a secret somewhere on how to create a true thread based program, isn't there?

8 REPLIES 8
KnarfB
Principal III

In CubeMX, when you configure your project, choose Middleware FreeRTOS and a CMSIS interface (both will do, V2 is newer). Depending on how deep you want to dive, you can create tasks (=threads) etc. in CubeMX or in the code. You find the docs here: https://www.keil.com/pack/doc/CMSIS/RTOS2/html/group__CMSIS__RTOS.html

hth

KnarfB

Sara BEN HADJ YAHYA
ST Employee

Hi @BEppe.1​ ,

Welcome to the community and thanks for your feedback,

You can find plenty of FreeRTOS Examples under Example Selector in CubeMX, some of which are available for CubeMX (Please refer to the attachment). And as @KnarfB​  mentioned, when you configure your project you can find FreeRTOS under Middleware.

Since you just started using CubeMX, I advise you to watch our tutorial videos, you can access to them easily from Help menu/Tutorial videos in CubeMX.

0693W00000HnwNiQAJ.png0693W00000HnwO2QAJ.pngIf you issue is solved, please close this post by clicking the "Select as Best" button. This will help other members of the community find this response more quickly :)

Regards,

Sara.

Thanks that was helpful. Only there are no examples for my board. B-L475E-IOT01A2. I put some code together using different video's, but the "PWM Start" won't start the PWM. Here is the important parts the init and run code. Any suggestions would be appreciated. I have my scope on the correct pin I programmed, I know as I have an Excel sheet with all the pins available from the board matched with the pins used.

Suggestions?

***MAIN ***
 MX_TIM2_Init();
  MX_TIM5_Init();
  /* USER CODE BEGIN 2 */
	HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_2);
 
 
*** TIMER 5 ***
 
static void MX_TIM5_Init(void)
{
 
  /* USER CODE BEGIN TIM5_Init 0 */
 
  /* USER CODE END TIM5_Init 0 */
 
  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  TIM_MasterConfigTypeDef sMasterConfig = {0};
  TIM_OC_InitTypeDef sConfigOC = {0};
 
  /* USER CODE BEGIN TIM5_Init 1 */
 
  /* USER CODE END TIM5_Init 1 */
  htim5.Instance = TIM5;
  htim5.Init.Prescaler = 1023;
  htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim5.Init.Period = 62499;
  htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
  if (HAL_TIM_Base_Init(&htim5) != HAL_OK)
  {
    Error_Handler();
  }
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_TIM_PWM_Init(&htim5) != HAL_OK)
  {
    Error_Handler();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 31250;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN TIM5_Init 2 */
 
  /* USER CODE END TIM5_Init 2 */
  HAL_TIM_MspPostInit(&htim5);
 
}

Hi @BEppe.1​ ,

Could you please specify the CubeMX version and which pin are you using.

If possible please share share your .ioc file.

Regards,

Sara.

BEppe.1
Associate II

Sure. Here is the information requested.

Board = B-L475E-IOT01A1

Firmware Package = STM32Cube FW_L4 V1.17.0

Toolchain IDE = V5.32

 also it is pin1 of CN3 (PA0), forgot to include.

 

Got it.... The signal is not pretty but it's there.

Hi @BEppe.1​ ,

I checked your .ioc file and there is no issue in it, also you are using the right pins. So I believe that there is nothing wrong.

About the signal, it could be due the high frequency and the type of cables you are using, in this case it is perfectly normal to get such result.

If the shape of your signal is not expected could you please share a capture of it ?

Thanks,

Sara.