cancel
Showing results for 
Search instead for 
Did you mean: 

Getting GPIO pin to toggle in Blinky

BEppe.1
Associate II

I'm trying to get my embedded skills back from many years ago, so I have an STM32L475 L475E board I am working with. I am using Blinky to reference from, but I can't get the output pin to toggle in the thread for the flashing led.

/* Private defines -----------------------------------------------------------*/
/* USER CODE BEGIN Private defines */
 
 
#define I_GPIO_PORT_A								GPIOA
#define I_GPIO_PORT_B								GPIOB
#define I_GPIO_PORT_C								GPIOC
#define I_GPIO_PORT_D								GPIOD
 
 
#define IT_ENCODER_CH1_A						GPIO_PIN_0
#define IT_ENCODER_CH2_A						GPIO_PIN_1
#define I_ENCODER_CH1_B							GPIO_PIN_2
#define I_ENCODER_CH2_B							GPIO_PIN_7
 
#define IT_FRONT_BUMPER							GPIO_PIN_2
#define IT_REAR_BUMPER							GPIO_PIN_3
#define IT_LF_SIDE_OPTIC						GPIO_PIN_4
#define IT_LR_SIDE_OPTIC						GPIO_PIN_5
#define IT_RF_SIDE_OPTIC						GPIO_PIN_8
#define O_DIR_CH1										GPIO_PIN_1
#define O_PWM_CH1										GPIO_PIN_2
#define O_PWM_CH2										GPIO_PIN_5
#define O_DIR_CH2										GPIO_PIN_14
#define IT_RR_SIDE_OPTIC						GPIO_PIN_15
 
 
-----------------------------------------------------------------------------------------------------------
 
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
	/* Timer data for PWM */
//	TM_PWM_TIM_t TIM_Data;
	
  /* GPIO Ports Clock Enable */
//  __HAL_RCC_GPIOC_CLK_ENABLE();
 
 
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
 
 
 
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(I_GPIO_PORT_B, O_PWM_CH1, GPIO_PIN_SET);
 
 
 
//  /*Configure GPIO pin Output Level */
//  HAL_GPIO_WritePin(I_GPIO_PORT_B, O_PWM_CH1, GPIO_PIN_RESET);
 
  /*Configure GPIO pin : O_PWM_CH1 */
  GPIO_InitStruct.Pin = O_PWM_CH1;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(I_GPIO_PORT_B, &GPIO_InitStruct);
 
 
//  /*Configure GPIO pin Output Level */
//  HAL_GPIO_WritePin(I_GPIO_PORT_B, O_PWM_CH1, GPIO_PIN_SET);
 
 
//  /*Configure GPIO pin Output Level */
//  HAL_GPIO_WritePin(I_GPIO_PORT_B, O_PWM_CH1, GPIO_PIN_RESET);
 
 
--------------------------------------------------------------------------------------------
 
Thread:
/*---------------------------------------------------------------------------
  thrLED: blink LED
 *---------------------------------------------------------------------------*/
__NO_RETURN static void thrLED (void *arg) {
  uint32_t active_flag = 0U;
 
  (void)arg;
 
  for (;;) {
    if (osThreadFlagsWait(1U, osFlagsWaitAny, 0U) == 1U) {
      active_flag ^= 1U;
    }
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(I_GPIO_PORT_B, O_PWM_CH1, GPIO_PIN_SET);
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(I_GPIO_PORT_B, O_DIR_CH1, GPIO_PIN_RESET);
 
 
 
 
 
 
 
    if (active_flag == 1U) {
      vioSetSignal(vioLED0, vioLEDoff);         // Switch LED0 off
      vioSetSignal(vioLED1, vioLEDon);          // Switch LED1 on
      osDelay(50U);                            // Delay 100 ms
      vioSetSignal(vioLED0, vioLEDon);          // Switch LED0 on
      vioSetSignal(vioLED1, vioLEDoff);         // Switch LED1 off
      osDelay(50U);                            // Delay 100 ms
    }
    else {
      vioSetSignal(vioLED0, vioLEDon);          // Switch LED0 on
      osDelay(700U);                            // Delay 500 ms
      vioSetSignal(vioLED0, vioLEDoff);         // Switch LED0 off
      osDelay(700U);                            // Delay 500 ms
    }
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(I_GPIO_PORT_B, O_PWM_CH1, GPIO_PIN_RESET);
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(I_GPIO_PORT_B, O_DIR_CH1, GPIO_PIN_SET);
  }
}

Whats my issue please?

5 REPLIES 5
MM..1
Chief III

As first you show incomplete code, second you ignore MX generated structure.

From showed code only one pin maybe work if code dont hang on any place. ?debug?

  /*Configure GPIO pin : O_PWM_CH1 */
  GPIO_InitStruct.Pin = O_PWM_CH1;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(I_GPIO_PORT_B, &GPIO_InitStruct);

Normal steps =

  1. In MX wizard set all pins on MCU image to necessary configs
  2. In left part MX config all peripherals to desired functions
  3. place your code into
/* USER CODE BEGIN ....
 
 
/* USER CODE END ...
  1.  

TDK
Guru

> vioSetSignal(vioLED0, vioLEDoff);

You don't show anywhere what this does.

If you set a breakpoint in the section where it's supposed to toggle the LED, does it get there? If not, that's your problem. If so, there's an issue with how you're toggling the pin.

If you feel a post has answered your question, please click "Accept as Solution".

thanks for the feedback. I did not know that Keil had an MX generator? I cannot/have not seen one. So I don't think this helps. This code is what comes from example programs, so if it's wrong the previous writer did this. I'm just trying to understand why my pins do not toggle. What in the code is incorrect because it looks right to me. Yes I debugged, but if it does not toggle how far can you debug when you don't know if your code is correct?

thanks for the feedback. This is from the Blinky program in the thread to flash LED2 as an example program. I thought that it would be clear when I said "I am using Blinky to reference from"

MX exist in two variants, as IDE plugin and as standalone app. In project config you can select KEIL or IAR ...

And around examples, good is download or use firmware package folder, where is big amount examples ... double click on project file ...

Why thread and RTOS