Main Content

Change the LED Glow Intensity on STMicroelectronics STM32Fxx Based Boards

This example demonstrates how to brighten and dim an LED by using the Embedded Coder® Support Package for STMicroelectronics® STM32 Processors.

Embedded Coder Support Package for STMicroelectronics STM32 Processors enables you to use PWM Output block to vary the duty cycle of digital output pulse. This PWM output is written to GPIO PB14 which is a user LED.

In this example you will learn how to configure a simple Simulink model to change the intensity of user LED for STMicroelectronics NUCLEO-F429ZI board. You can configure this model for other supported STM32Fxx based boards by browsing to Configuration Parameters > Hardware Implementation > Hardware board and selecting the required board.

Prerequisites

It is recommended that you complete these examples:

Required Hardware

To run this example, you need the following hardware:

  • Supported STMicroelectronics STMicroelectronics NUCLEO-F429ZI board

  • USB type A to Micro-B cable

Model

The following figure shows the example model:

open_system('PWMLED');

Connecting Pin PE9 with PB14

Write the PWM output to GPIO PE9, and connect PE9 to PB14 (LD3-RED) using a breadboard wire, as shown.

Configuring the Model for Code Generation and Download

In this task, you configure the model for the supported STMicroelectronics STMicroelectronics NUCLEO-F429ZI board.

1. Open the model PWMLED. This model has been configured for the STMicroelectronics NUCLEO-F429ZI board.

2. Open the Modeling tab and press CTRL+E to open Configuration Parameters dialog box.

3. Go to Hardware Implementation > Hardware board.

The user LED is driven by GPIO Pin PB14 on the STMicroelectronics NUCLEO-F429ZI board. The user LED might be driven by a different pin on different STM32 processor boards.

4. Open Hardware tab and click Build, Deploy & Start to automatically download the generated bin file, PWMLED.bin, on to the connected STM32F4xx board.

5. Observe that the onboard LED connected at pin PB14 brightens up to the fullest and then dims up to the lowest intensity.

Close Model

close_system('PWMLED', 0);