Professional Documents
Culture Documents
Getting Started - STM MCU - Examples
Getting Started - STM MCU - Examples
Getting Started
with Examples
1
General-Purpose Input/Outputs (GPIOs)
General Flow with
Matlab/Simulink & Waijung Blocksets
Program
Creating a Adding
Model Loading
Simulink Waijung
Verifications &
Model Blocksets
Execution
Simulink Experimental
Verification Verification
2
General-Purpose Input/Outputs (GPIOs)
General Flow with
Matlab/Simulink & Waijung Blocksets
Program
Creating a Adding
Model Loading
Simulink Waijung
Verifications &
Model Blocksets
Execution
Simulink Experimental
Verification Verification
3
Launch the Matlab Tool
One way: Select Start > All Program > matlab 2015a
4
Creating a Simulink Model
Step 1
Step 2
5
Target Setup Block with Waijung Blocks
Add Target
Setup Block
6
Setup Blocks
Target MCU: STM32F4
7
8
Check
9
Example 1: GPIO
10
Setup for GPIOs
11
Initial Status of
a Digital Input Block
12
Port(A,B,C,D,E,H)
• Only ports and pins that
are available on the
selected target MCU are
shown/enabled
13
Check
14
15
Initial Status of a Digital
Output Block
16
Port(A,B,C,D,E,H)
• Only ports and pins that are available on the
selected target MCU are shown/enabled.
Pin(1,2,3,…)
• Only ports and pins that are available on the
selected target MCU are shown/enabled.
17
Connect
18
Save your
design
Check
19
Connect STM32F407VG to Computer
Power
20
Build, Load, & Test the Design
Build
Model
21
Successive Operations (Compiling & Loading)
22
Experimental Test
23
Example 2: Counter
24
Adding & Setup: Counter Limited Block
25
Setup Counter
Limited
26
Adding Compare To Constant Block
27
Setup Compare
To Constant
28
29
Check
30
Adding Digital Output Block
31
Check
32
Connection
33
Save Simulink model
34
Build
Model
35
Confirm file
36
Connect STM32F407VG to Computer
Power
37
38
4 LEDs one by
one bright !!!
39
Example 3: UART Communication
40
Adding
UART Setup
41
Setup UART Setup Block
Setup
UART Setup
42
UART Module 1|2|3|4|5|6
Select UART module for the configuration.
Baud rate communication speed
Ex: 9600, 115200 or 1000000
Pin configuration (remap) for transmit (Tx)
Via this pin, UART Tx signal will be transmitted to other device.
Pin configuration for Receive pin (Rx)
Via this pin, UART Rx signal will be received from other device.
43
Adding and Setup: UART Rx Block
Adding
UART Rx
44
Setup
UART Rx
45
UART Module 1|2|3|4|5|6
Select Transfer mode Ex: Blocking, Non-Blocking
Packet selection
Binary | Binary Vector | Ascii | String Buffer | Raw Buffer
Ascii format pattern for scanf Example: "Value=%d”
Terminator
LF | CR | CRLF
46
Adding & Setup: Enabled Subsystem Block
47
Setup Enabled
Subsystem
48
Delete
Out1
Check
49
Adding & Setup: Digital Output Block
50
Double Click
Digital Output
51
Port(A,B,C,…)
• Only ports and pins that are available on the selected
target MCU are shown/enabled.
Pin(1,2,3,…)
• Only ports and pins that are available on the selected
target MCU are shown/enabled.
52
Adding & Setup: Compare To Constant Block
53
Setup : Compare To Constant
54
55
Connection
In1, Compare To Constant, Digital Output
56
Connection
UART Rx to Enable Subsystem
57
Save Simulink Model
Check
file
58
Connect STM32F407VG, UART to Computer
Tx:C10
Rx:C11 Tx:C11
Rx:C10
59
Build Model and Test Design
Build Model
60
61
Right Click
Select Properties
Check Port
62
63
Open Matlab Command Windows
64
Type
s=serial(‘com7’)
Port information
65
Match Port’s
BaudRate to
UART’s(115200)
See
UART’s Setup
66
Open Port
67
Send data to STM32F4 with the format
(value=%d\r). For example, if we send ‘1’
then you can see PD12 LED light bright.
68
69