Sunteți pe pagina 1din 39

https://os.mbed.

com/platforms/ST-Nucleo-F767ZI/

Tutorial STM32F767
Example programs

OS 5  mbed-os-example-blinky
This is a very simple guide, reviewing the steps required to get Blinky working on an
Mbed OS platform.
Last updated: 22 Nov 2019
OS 5  mbed-os-tcp-server-example
A small example of TCP server over ethernet for mbed-os.
 ethernet , MBED-OS , TCP
Last updated: 26 Jun 2017
OS 2  Nucleo_blink_led
Blinky LED test for ST Nucleo boards
 blink , led , Nucleo , STM , stm32
Last updated: 13 Sep 2017
OS 2  Nucleo_printf
Display a message on PC using UART.
 Nucleo , printf , STM , stm32 , UART
Last updated: 07 Jun 2017
OS 2  Nucleo_pwm
Output a pwm signal.
 Nucleo , pwm , STM , stm32
Last updated: 07 Jun 2017
OS 2  Nucleo_read_analog_value
Read an analog value using ADC.
 AnalogIn , Nucleo , STM , stm32
Last updated: 07 Jun 2017
OS 2  Nucleo_read_button
Read the user button state on the Nucleo board.
 BUTTON , DigitalIn , Nucleo , STM , stm32
Last updated: 07 Jun 2017
OS 2  Nucleo_read_button_interrupt
Read the user button using external interrupt.
 BUTTON , InterruptIn , Nucleo , STM , stm32
Last updated: 07 Jun 2017
OS 2  Nucleo_analog_loop
Analog loop example using ADC and DAC.
 Analog , dac
Last updated: 07 Jun 2017
OS 2  Nucleo_display_time
Display the date and time using RTC.
 Date , Nucleo , RTC , STM , stm32 , time
Last updated: 07 Jun 2017
OS 2  Nucleo_i2c_master
Read external LM75 temperature sensor using I2C master.
 I2C , LM75 , Nucleo , STM , stm32 , temperature sensor
Last updated: 07 Jun 2017
OS 2  Nucleo_pwm2
Output pwm signal with duty-cycle changed when pressing a button.
 BUTTON , Nucleo , pwm , STM , stm32
Last updated: 07 Jun 2017
OS 2  Nucleo_read_ios
Read several IOs of a port at the same time.
 Nucleo , PortIn , STM , stm32
Last updated: 07 Jun 2017
OS 5  Nucleo_rtos_basic
RTOS basic example.
 Nucleo , rtos
Last updated: 23 Nov 2017
OS 2  Nucleo_sawtooth
Basic example to use the DAC. Output a sawtooth signal.
 dac , Nucleo , sawtooth
Last updated: 08 Jun 2017
OS 2  Nucleo_sinewave_output
Output a sinewave using DAC.
 dac , Nucleo , sinewave , STM , stm32
Last updated: 08 Jun 2017
OS 2  Nucleo_spi_master
Send data with SPI.
 Nucleo , SPI , STM , stm32
Last updated: 07 Jun 2017
OS 2  Nucleo_ticker
Basic example of how to blink a led using the Ticker object.
 led , Nucleo , Ticker
Last updated: 07 Jun 2017
OS 2  Nucleo_toggle_ios
Toggle several IOs of a port at the same time.
 Nucleo , PortOut , STM , stm32 , Toggle
Last updated: 07 Jun 2017
OS 2  Nucleo_blink_color_led
Example program that uses the color LED of the mbed application shield with ST
Nucleo board
 color , F103RB , led , mbed , Nucleo , shield , ST
Last updated: 17 Aug 2016
OS 5  mbed-os-example-blinky
Fork of https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-
blinky/
Last updated: 22 Jun 2017
OS 5  Nucleo_usbhost
USBHost example : USBHostMSD, HID mouse and keyboard , support hub.
Last updated: 28 Apr 2017
OS 2  Nucleo_read_hyperterminal
Read hyper-terminal
 Hyper-terminal
Last updated: 21 Jun 2017
OS 2  STM32_USBDevice_Mouse
USBDevice Mouse example.
 Mouse , USB , USB device , USB HID
Last updated: 03 Aug 2017
OS 2  STM32_USBHost_Mouse
USBHost Mouse example.
 Mouse , USB , USB Host
Last updated: 03 Aug 2017
OS 2  STM32_USBDevice_Serial
USBDevice Serial com port example.
 Serial , USB , USB CDC serial , USB device
Last updated: 03 Aug 2017
OS 2  STM32_Button_Debounce
Button with debounce example.
 BUTTON , debounce , Timeout
Last updated: 06 Oct 2017
OS 2  STM32_Button_Interrupt
Button with interrupt example.
 basics , BUTTON , interrupt , stm32
Last updated: 07 Jul 2017
OS 2  STM32_Print_PC
Print on PC example.
 basics , print , printf , stm32
Last updated: 08 Jul 2017
OS 2  STM32_read_analog
ADC read value example.
Last updated: 27 Sep 2017
OS 5  example-Ethernet-mbed-Cloud-connect
Superseded by https://os.mbed.com/teams/ST/code/pelion-example-common/
 cloud , ethernet , stm32
Last updated: 15 Oct 2018
OS 2  Nucleo_pwm3
Output a PWM signal on any IO using Timeout.
 Nucleo , pwm , STM , stm32 , Timeout
Last updated: 07 Jun 2017
OS 5  pelion-example-common
Mbed OS Device Management example for various ST boards.
 device management , Pelion , ST , ST Discovery , ST Nucleo
Last updated: 27 Mar 2019
Supported shields

This table summarizes the different shields (non ST X-NUCLEO boards) tested on
Nucleo-64, Nucleo-144, B96B and Discovery platforms (only ones having an Arduino
Uno connector).

This list is not exhaustive! A shield not present or not mentioned "Tested" does not
mean that it will not work!

Nucleo-
Discovery
64/Nucleo-
Shield name Shield type F469NI/F769NI/F746NG
144/B96B
board status
boards status

mbed Application Display, Tested Tested


Shield Sensors

Freetronics 16x2 Display Tested


LCD

Seeed 2.8" TFT Display Tested


Touch V2

Seeed SDCard Storage Tested (1)


V4b

W5200 Ethernet Connectivity Tested (1)

Seeed Wifi Connectivity Tested (2)

Seeed Bluetooth Connectivity Tested (2)

Seeed NFC V2 Connectivity Tested (1)

Seeed XBee V2 Connectivity Tested (2)

Seeed GPRS V2 Connectivity Tested (2)

Ciseco SRF Connectivity Tested (2)


Sparkfun GPS Sensors Tested (2)

Freescale Multi- Sensors Tested (3)


Sensor

CN0357-Toxic- Sensors Tested


gas-measurement

CN0216-Weigh- Sensors Tested


Scale

Seeed Motor V2 Drivers Tested

Seeed Bot Drivers Tested

Seeed EL Drivers Tested

Seeed Relay V2 Actuators Tested

Seeed Energy Power supply Tested (4)

Seeed Charger V2 Power supply Tested (4)

Seeed Grove V2 Hook-up Tested

Shields support notes

 (1)
 This shield requires SPI pins remapping because it uses a non-standard 6 pin SPI
connector. Please refer to the shield page on mbed for more information.
 (2)
 To use this shield with Nucleo-64 boards you will need to remove/open SB13 and
SB14 and solder/close SB62 and SB63 solder bridges. This will enable the STM32
microcontroller to communicate with the shield using the default serial connection present
on D0/D1 pins. As a drawback, the serial communication (used by printf for example) and going
via the ST-Link and USB will be disconnected. Alternatively you could use other serial-
enabled pins, which have to be connected to the CN3-TX/RX connector. Please refer to the the
Nucleo pinout image for serial pins options and to the user manual (USART communication
chapter).
 (3)
 This shield uses I2C on A4/A5 pins and requires bridging of A4<->D14 and A5<->D15.
 (4)
 This shield requires that the board is configured to boot on external power. On the
Nucleo-64, this configuration is done using thez PWR jumper and has to be switched
to E5V position.
Filters

 Mbed Enabled
o Baseline (27)

 Mbed OS support
o Mbed OS 2 (24)
o Mbed OS 5.4 (5)
o Mbed OS 5.5 (7)
o Mbed OS 5.6 (2)
o Mbed OS 5.7 (2)
o Mbed OS 5.8 (2)
o Mbed OS 5.9 (1)
o Mbed OS 5.10 (3)
o Mbed OS 5.11 (1)
o Mbed OS 5.12 (2)
o Mbed OS 5.13 (2)
o Mbed OS 5.14 (2)
o Mbed OS 5.15 (2)

 Actuators
o Audio (14) 
o Motor (25) 
o Relay (9) 
o Servomotor (8) 
o Solenoid (1) 
o Other (2)

 Communication
o 802.15.4 (2) 
o Bluetooth & BLE (7) 
o CAN (1) 
o Cellular (10) 
o Ethernet (10) 
o Infrared (3) 
o LoRa (6) 
o RFID (4) 
o Sigfox (1) 
o Sub-1 GHz (1) 
o WiFi (14) 
o Other (11)

 Display
o Graphic LCD (31) 
o LED Controller (36) 
o Text LCD (9) 
o Touchscreen (11) 
o Other (23)

 Expansion Boards
o Arduino Shield (46) 
o Board Specific (21) 
o General Purpose (4) 
o Grove (38) 
o Mbed Interface (5) 

 Inputs
o Button (15) 
o Joystick (8) 
o Potentiometer (10) 

 IoT and Web Services (12)

 Sensors
o Biometrics (10) 
o Capacitive Touch (19) 
o Compass (10) 
o Environmental (22) 
o Flex/Force (4) 
o Gas (4) 
o GPS (10) 
o Imaging (13) 
o Light (23) 
o Motion (55)
o Sound (8) 
o Temperature (44)
o Other (43)

 Storage
o EEPROM (4) 
o Flash (2) 
o Other Storage (1) 
o RAM (4) 
o SD Card (7) 
o USB Mass Storage (2) 

 Other (54)

 Component vendor
o AnalogDevices (9)
o Avnet (1)
o Bosch Sensortec (1)
o CSR (1)
o L-Tek (2)
o Maxim Integrated (30)
o Minewtech (2)
o NXP Semiconductors (23)
o PixArt (13)
o Rohm Co., Ltd. (10)
o SeeedStudio (7)
o Semtech (5)
o Sigma Delta Technologies (7)
o STMicroelectronics (29)
o u-blox AG (1)
o WIZnet (7)
https://medium.com/@rlamarrr/introduction-to-stm32cube-blinking-an-led-61469168f9e4

Under the File menu, select Create New STM32 project /


Start New STM32 Project.

Target Selection
The target selector is a very handy utility for selecting MCUs and
boards based on specific features.

From the Target Selector window that appears, select the


appropriate target MCU, which in my case is an STM32F767ZI
(STM32F767ZIT6) MCU.
After selection, Proceed by clicking on the Next button.

If you don’t have the package for the MCU, it requests to download
the appropriate STM32Cube package (in my case STM32Cube
F7) into the STM32Cube Repository and installs it.

The Project Setup window appears, enter the project details as


appropriate and proceed by clicking on the Finish button.
Project Setup Window

Approve the STM32CubeMX perspective switch from the dialog


box that appears.
Identifying MCU and Development
Board Pinout

Nucleo-144 boards’ LED pinout


From the Nucleo-144 Manual, we can observe that the
development board’s user LD1 (LED1) is connected to the
MCU’s PB0 (PB_0) pin.

Alternatively,
Pin Schematic

Using the schematic above from MBED, we can observe the label


names for each GPIO pin, The user LED1 is assigned to GPIO pin
labeled PB_0 (PB0) as indicated in the schematic above
(LED1 emphasized in the thick black box).

GPIO Configuration
As earlier stated we’ll be using the STM32CubeMX initialization
code generator to configure the peripherals and software stacks,
This is already embedded into the IDE.
Using the Device Configuration tool we can initialize peripherals,
Allocate pins, configure NVIC, configure Timers, configure
SysTick, configure hardware connectivity mediums (e.g. SPI, I2C,
UART, etc), configure GPIOs, configure ADC and DAC,
middleware initialization (e.g. FreeRTOS, LIBJPEG, LWIP, etc)
and many more.

STM32CubeMX Device Configuration Tool


Now, we want to try to blink an onboard LED, namely the
user LED1, As earlier deduced, this corresponds to the
MCU’s PB0 pin, from the Pinout view click on the PB0 pin and
select the appropriate Pin Mode for this.
Pinout View
Pin PB_0
By default, the pin is initially in the Reset_State, Since we are
performing GPIO output with push and pull (on and off), we select
the GPIO_Output option.
Then navigate to the GPIO menu (Pinout Configuration tab
> Categories > System Core > GPIO).

Here we can assign desired labels and configurations to the pins


we’ve initialized (pins not in Reset_State).
GPIO Configuration

From the GPIO table, click on the pin name field PB0 and use the
above GPIO configuration.

But why? The Embedded Artistry has a detailed explanation on


GPIO settings; Demystifying Microcontroller GPIO Settings.

Note: We set the User Label of the pin to LED1 (this will be used
as the prefix of the variable name to reference its pin and GPIO
port later in our code).

Click on the Device Configuration Tool Code


Generation icon on the top toolbar, and this generates the
required initialization code.

Device Configuration Tool Code Generation

Your project’s file and folder hierarchy should look similar to this:
Generated File and Folder Hierarchy

Adding our Program


With the previously generated component startup files, folders,
headers, and libraries generated by STM32CubeMX, we can
proceed to stack our program on top.
For now, we’ll only focus on the GPIO. The clocks configuration
and other parts of the generated code are topics that’ll be
discussed in later episodes.

From the File Explorer window, we edit the Src/main.c file as


follows:

The generated main function is something like this:


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();/* USER CODE BEGIN Init *//* USER
CODE END Init *//* Configure the system clock
*/SystemClock_Config();/* USER CODE BEGIN SysInit *//* USER CODE
END SysInit *//* Initialize all configured peripherals
*/MX_GPIO_Init();/* USER CODE BEGIN 2 *//* USER CODE END 2 *//*
Infinite loop *//* USER CODE BEGIN WHILE */while (1){/* USER CODE
END WHILE *//* USER CODE BEGIN 3 */}/* USER CODE END 3 */}

Note the comment sections with USER CODE


BEGIN and USER CODE END, as this prevents conflicts
between CubeMX’s generated code and user code.

We’d like to toggle the LED state at a frequency of 2Hz (500ms


interval),

Replace the infinite loop code section with:


/* Infinite loop *//* USER CODE BEGIN WHILE */
// GPIO_PIN_SET => 1
// GPIO_PIN_RESET => 0static unsigned short pin_state = 0;while (1)
{/* USER CODE END WHILE *//* USER CODE BEGIN 3 */pin_state = !
pin_state;// write pin state
// NOTE: You can in turn use
HAL_GPIO_TogglePinHAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin,
pin_state);// synchronous delay for 500 msHAL_Delay(500);}/* USER
CODE END 3 */

Save the file (Ctrl+S).


Program Execution
Ensure you have your development board connected to your
computer.

On the top tool bar, click: Run > Debug > Select STM32 MCU
C/C++ Application > OK.
The Debug Configuration window pops up, under
the Debugger tab, select the desired debug probe, in my
case: ST-LINK (OpenOCD). Click Apply and then OK.

Approve the Debug Context Switch Dialog (if any), this switches
the window to the Debug Context view.

Click on the Debugger Console tab.


Debugger Console

On the debugger console:

 Enter ‘c’ to continue execution of the program until a


breakpoint is reached
You can notice the LED1 peripheral blinking:

Demonstration
Conclusion
You have now reached the end of this introductory article, I hope
this was helpful. Be sure to leave your comments, questions and
edit suggestions.

More Learning Resources


Here are some more free learning resources:

 Embedded Artistry

 STM32 F7 Resources

 Reddit

 STMicroelectronics MOOCs & OLTs (Youtube Playlists)

S-ar putea să vă placă și