Skip to content

NUCLEO-64 STM32-L152RE: Constantly blinking an LED and toggling another LED on on-board button press.

Notifications You must be signed in to change notification settings

mixtapeo/STM32-LED

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

Introduction

The aim of this project is to understand the general workflow of working with the STMCubeIDE and configuring board, debug, and miscellaneous settings crucial to any project.
Inspiration for the project is credited to Digikey. However, the code they provide is outdated, and the steps are slightly different due to the use of different boards.
FreeRTOS will be used for task scheduling.

Steps

  1. Connect your STM32-L152RE board, install STMCubeIDE, and set up the environment.

  2. Open the auto-configurator, and select the following:

    • a. "GPIO_OUTPUT" on two pins (these will power the LEDs).
    • b. Search for "EXTI" in the search bar and enable this on the available port.
      • i. Navigate through the GPIO menu and enable the interrupt.
      • ii. This allows the blue button's external interrupt on the board to toggle the LED on press.

    image

  3. Navigate to "Middleware" and enable FreeRTOS:

    • a. Add up to two tasks:
      • i. One task should have normal priority.
      • ii. The other task should have below-normal priority to avoid clashing with system tasks.
    • b. Add a semaphore for the button press:
      • i. FreeRTOS will arrange for the button press to be communicated to the code at an appropriate time if other tasks (e.g., system tasks) are using the resource.
      • Note: This step can be skipped by using a toggle variable in the code, but using a semaphore is cleaner and more efficient.
  4. Modify the system clock to ensure accuracy:

    • Navigate to SYS and scroll down to change the system clock to "TIM6".
  5. Adjust the NVIC to enable the button interrupt.

  6. Implement the code:

    /* USER CODE END Header_blink1start */
    void blink1start(void *argument)
    {
      /* USER CODE BEGIN 5 */
      /* Infinite loop */
    
    	for(;;)
    	  {
    	    HAL_GPIO_TogglePin(LED_1_GPIO_Port, LED_1_Pin);
    	    osDelay(1000);
    	  }
      /* USER CODE END 5 */
    }
    
    /* USER CODE BEGIN Header_blink2start */
    /**
    * @brief Function implementing the blink2 thread.
    * @param argument: Not used
    * @retval None
    */
    /* USER CODE END Header_blink2start */
    void blink2start(void *argument)
    {
      /* USER CODE BEGIN blink2start */
      /* Infinite loop */
    	for(;;){
    			if(osOK == osSemaphoreAcquire (buttonPressedHandle, 500))
    			{
    				HAL_GPIO_TogglePin(LED_2_GPIO_Port, LED_2_Pin);
    			}
    		}
      /* USER CODE END blink2start */
    }
  7. Finally, start debug on the top menu, and press resume (on the top menu again), the system should be working as desired.

Challenges

  1. The system timer being stuck on the base clock after an interrupt caused the STM program to freeze.
  2. For the longest time, I mistakenly pressed the reset (black) button, thinking it was the interrupt button.
  3. Initially, I assigned both tasks very low priority, which worked but wasn't optimal. Task scheduling priority considerations were discovered later.

This should ensure readability and proper structure in your Markdown document. Let me know if you'd like to further refine any section!

About

NUCLEO-64 STM32-L152RE: Constantly blinking an LED and toggling another LED on on-board button press.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published