Professional Documents
Culture Documents
CONTENT 1/3
1. GPIO lab
2. EXTI lab
3. SLEEP lab
4. STOP lab
5. STANDBY lab
6. DMA Poll lab
7. DMA Interrupt lab
8. RTC Alarm lab
9. UART Poll lab
10. UART Interrupt lab
11. UART DMA lab
STM32F42xx Technical Training
20/10/2015
CONTENT 2/3
12. SPI Poll lab
13. SPI Interrupt lab
14. SPI DMA lab
15. TIM Interrupt lab
16. TIM PWM out lab
17. TIM DMA lab
18. TIM Counter lab
19. DAC wave generation lab
20. ADC Poll lab
21. ADC Interrupt lab
22. ADC DMA lab
STM32F42xx Technical Training
20/10/2015
CONTENT 3/3
23. WWDG lab
24. IWDG lab
25. FMC SDRAM BSP lab
26. LCD BSP Print text lab
27. I2C BSP EEPROM lab
28. SPI BSP GYROSCOPE lab
20/10/2015
GPIO Lab 1
20/10/2015
Objective
Learn how to setup pin and GPIO port in CubeMX
How to Generate Code in CubeMX and use HAL functions
Goal
Configure GPIO pin in CubeMX and Generate Code
Add in to project HAL_Delay function and HAL_GPIO_Toggle function
Verify the correct functionality on toggling LED
is not possible
Clock Configuration
TAB>Clock Configuration
We can easily
setup STM32
clocks
RM0090 Chapter 6
Reset and clock
control
Page 151
10
Internal
oscillators
11
External clock
sources
12
13
14
Clock sources
Internal oscillators
LSI
HSI
LSE
External 32,768Hz
crystal or external
signal in bypass
mode
15
Internal oscillators
LSI
HSI
External crystal
4-26MHz or
external signal 1-50Mhz
in bypass mode
16
Internal oscillators
LSI
HSI
Disabled clocks
How to enable?
4. High speed external
clocks
17
Internal oscillators
LSI
HSI
Disabled clocks
How to enable?
4. High speed external
clocks
18
19
20
Multiplexer select
clock source for
system
Clock source
for PLL
PLL multiplies
frequency
21
HSI as system
source
System frequency
16MHz
AHB prescaler
divide by 1
Core frequency
is now 16MHz
22
System frequency
8MHz
HSE crystal
or external
signal
AHB prescaler
divide by 1
Core frequency
is now 8MHz
23
HSI crystal
System frequency
180MHz
Core frequency
is now 180MHz
PLL out P divider
by 2
24
System frequency
180MHz
PLL in M divider
by 8
PLL multiplier N
by 360
Core frequency
is now 180MHz
PLL out P divider
by 2
25
Core clocks
26
Systick divider
Core clocks
Systick clock
27
External memory
controller clock
Core clocks
28
APB1 prescaler
APB1 peripherals
clock
Core clocks
APB1 timers clock
APB1 timers multiplier
29
APB2 prescaler
APB2 peripherals
clock
Core clocks
30
Clock Configuration
overview 22
Data sheet
Figure 4
31
Clock Configuration
overview 23
AHB, Core, memory
clock
32
Clock Configuration
overview 23
Core clock
External memory
clock
DMA clock
AHB clock
33
MCO output?
USB FS tree?
34
1. Disabled
MCO
MCO1 output
TAB>Pinout
RCC>MCO1 checkbox
TAB>Clock Configuration
Now the MCO1 output can be set
2. MCO1 enable
4. Set MCO1
35
1. RTC disabled
RTC
TAB>Pinout
RCC>RTC set RTC feature
TAB>Clock Configuration
Now the RTC can be set
2. RTC set
3. Set RTC
36
1. USB disabled
TAB>Pinout
RCC>USB_OTG_FS
set feature
TAB>Clock Configuration
2. USB enable
37
GPIO Configuration
TAB>Configuration>System>GPIO
38
GPIO(Pin) Configuration
Select Push Pull mode
No pull-up and pull-down
Output speed to HIGH
Is important for faster
peripheries like SPI, USART
Button OK
39
LOW
LOW
HIGH
HIGH
LOW
HIGH
HIGH
40
41
42
43
EXTI lab 2
20/10/2015
Objective
Learn how to setup input pin with EXTI in CubeMX
How to Generate Code in CubeMX and use HAL functions
Goal
Configure GPIO and EXTI pin in CubeMX and Generate Code
Add into project Callback function and function which turn on led
Verify the correct functionality by pressing button which turns on LED
45
46
47
48
GPIO Configuration
TAB>Configuration>System>GPIO
49
GPIO(Pin) Configuration
Select External Interrupt Mode with Rising edge trigger detection
No pull-up or pull-down
PG14 can be let in default
settings
Button OK
50
NVIC Configuration
We need to enable interrupts for EXTI
TAB>Configuration>System>NVIC
51
NVIC Configuration
Enable interrupt for
EXTI Line0
Button OK
52
53
54
Generated by
CubeMX
HAL_EXTI0_IRQHandler
EXTI0_IRQHandler
55
MX_GPIO_Init
inside main.c
HAL_EXTI0_IRQHandler
EXTI0_IRQHandler
56
inside
stm32f4xx_it.c
HAL_EXTI0_IRQHandler
EXTI0_IRQHandler
57
HAL_EXTI0_IRQHandler
EXTI0_IRQHandler
58
HAL_EXTI0_IRQHandler
EXTI0_IRQHandler
59
3. create
edge
1. init NVIC
Peripheral Initializations
including peripheral interrupt NVIC
initializations
2. init GPIO
Configure the GPIO to generate interrupt on
rising or falling edge
5. HAL EXTI
interrupt handler
HAL_EXTI0_IRQHandler
6. HAL EXTI
callback
4. EXTI interrupt
handler
EXTI0_IRQHandler
60
61
20/10/2015
Objective
We use the EXTI setup from lab 1
Learn how to setup SLEEP in HAL
Create simple project with SLEEP mode with wake up on pin press
Goal
Use project from EXTI lab
Learn how to setup the SLEEP in HAL, which events can wake up you
Verify the correct functionality by measuring consumption
63
SLEEP Mode
GPIOs
Core
CM4
RTC/backup reg.
RAM
IWDG
DMA
GP timers
Clock
HSI
SPI
USB
HSE
LSI
LSE
DAC
ADC
FLASH
USART
I2C
Reset
Power
regulator
Core is stopped
Peripherals are running
65
4. create
edge
1. init NVIC
Peripheral Initializations
including peripheral interrupt NVIC
initializations
2. init GPIO
Configure the GPIO to generate interrupt on
rising or falling edge
5. EXTI interrupt
handler
3. Use WFI
Enter into SLEEP mode(WFI)
HAL_EXTI0_IRQHandler
6. HAL EXTI
interrupt handler
7. HAL EXTI
callback
EXTI0_IRQHandler
To be able to reprogram
the STM32 which is in
LP mode, use
connection during
reset option
66
67
Is this better?
68
20/10/2015
Objective
We use the EXTI setup from lab 1
Learn how to setup STOP in HAL
Create simple project with STOP mode with wake up on pin press
Goal
Use project from EXTI lab
Learn how to setup the STOP in HAL, which events can wake up you
Verify the correct functionality by measuring consumption
70
STOP Mode
Core is stopped
GPIOs
Core
CM4
RTC/backup reg.
IWDG
GP timers
FLASH
RAM
DMA
DAC
ADC
Clock
HSE
HSI
SPI
USB
USART
I2C
72
4. create
edge
1. init NVIC
Peripheral Initializations
including peripheral interrupt NVIC
initializations
2. init GPIO
Configure the GPIO to generate interrupt on
rising or falling edge
Clock reconfigure
7. HAL EXTI
callback
5. EXTI interrupt
handler
3. Use WFI
HAL_EXTI0_IRQHandler
8. Reconfigure
clock after
wakeup
6. HAL EXTI
interrupt handler
EXTI0_IRQHandler
To be able to reprogram
the STM32 which is in
LP mode, use
connection during
reset option
73
74
Or different function
/* USER CODE BEGIN 3 */
/* Infinite loop */
while (1)
{
HAL_Delay(1000);
HAL_PWREx_EnterUnderDriveSTOPMode(PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON,PWR_STOPENTRY_WFI);
SystemClock_Config();
}
/* USER CODE END 3 */
75
20/10/2015
Objective
For this lab create empty CubeMX project
Learn how to setup STANDBY in HAL
Create simple project with STANDBY mode with wake up on pin press
Goal
Learn how to setup the STANDBY in HAL, which events can wake up you
Verify the correct functionality by measuring consumption
77
STANDBY Mode
GPIOs
Core
CM4
RTC/backup reg.
FLASH
RAM
IWDG
DMA
GP timers
Clock
HSE
SPI
HSI
USB
LSI
LSE
DAC
USART
I2C
Reset
ADC
Power
regulator
Reset
RTC OUT
WKUP 1,2,3
2. Standby
Enable Wake-up pin
Reset
3. Use WFI
5. Wake up
STM with reset
4. create
edge
79
To be able to reprogram
the STM32 which is in
LP mode, use
connection during
reset option
80
81
82
20/10/2015
Objective
Learn how to setup DMA transfer in CubeMX
Create simple DMA memory to memory transfer from RAM to RAM
Goal
Use CubeMX and Generate Code with DMA
Learn how to setup the DMA in HAL
Verify the correct functionality by comparing transferred buffers
84
6
CORTEX-M4
168MHz
w/ FPU & MPU
Ethernet
10/100
High Speed
USB2.0
Dual Port
DMA1
Dual Port
DMA2
Master 5
Master 4
Master 2
Master 3
FIFO/DMA
FIFO/DMA
FIFO/8 Streams
FIFO/8 Streams
85
Dual Port
AHB1-APB2
S-Bus
I-Bus
Master 1
AHB1
Dual Port
AHB1-APB1
AHB2
SRAM1
112KB
SRAM2
16KB
FSMC
I-Code
D-Code
ART
Accelerator
D-Bus
CCM
data RAM
64KB
FLASH
1Mbytes
86
87
DMA configuration
TAB>Configuration
System>DMA
TAB>DMA2
Button ADD
1. TAB >
Configuration
3. TAB>DMA 2
4. Add DMA
channel
2. System DMA
88
DMA configuration
Select MEMTOMEM
DMA request
1. MEMTOMEM
Normal mode
Increment source and
destination address
FIFO setup
Byte data width
Burst size
Button OK
3. Increment
addresses
2. Normal
mode
4. FIFO setup
6. OK
89
90
1. init DMA
Peripheral
Initializations
Start Process
(HAL_DMA_Start)
2. Start DMA
91
Return values
Most of CubeMX functions have return values, which indicate, if operation was successful,
timeout occurs of function end with error
Is recommended handle this return values to be sure that program working as expected
HAL_OK
HAL_ERROR
HAL_BUSY
92
Return values
Most of CubeMX functions have return values, which indicate, if operation was successful,
timeout occurs of function end with error
Is recommended handle this return values to be sure that program working as expected
HAL_OK
HAL_ERROR
HAL_BUSY
93
Return values
Most of CubeMX functions have return values, which indicate, if operation was successful,
timeout occurs of function end with error
Is recommended handle this return values to be sure that program working as expected
HAL_OK
HAL_ERROR
HAL_BUSY
94
95
/* USER
uint8_t
uint8_t
/* USER
CODE BEGIN 0 */
Buffer_Src[]={0,1,2,3,4,5,6,7,8,9};
Buffer_Dest[10];
CODE END 0 */
96
97
20/10/2015
Objective
Learn how to setup DMA transfer with interrupt in CubeMX
Create simple DMA memory to memory transfer from RAM to RAM
Goal
Use CubeMX and Generate Code with DMA
Learn how to setup the DMA in HAL
Verify the correct functionality by comparing transferred buffers
99
100
101
DMA configuration
TAB>Configuration
System>DMA
TAB>DMA2
Button ADD
1. TAB >
Configuration
3. TAB>DMA 2
4. Add DMA
channel
2. System DMA
102
DMA configuration
Select MEMTOMEM
DMA request
1. MEMTOMEM
Normal mode
Increment source and
destination address
FIFO setup
Byte data width
Burst size
Button OK
3. Increment
addresses
2. Normal
mode
4. FIFO setup
6. OK
103
DMA configuration
1. TAB >
Configuration
3. Enable DMA2
interrupts
4. OK
104
105
106
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_DMA_IRQHandler
DMA2_Stream0_IRQHandler
107
Generated by CubeMX
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_DMA_IRQHandler
DMA2_Stream0_IRQHandler
108
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_DMA_IRQHandler
DMA2_Stream0_IRQHandler
Defined by user
109
Generated in main.c
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_DMA_IRQHandler
DMA2_Stream0_IRQHandler
110
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_DMA_IRQHandler
DMA2_Stream0_IRQHandler
We recommend to use it
in main.c
111
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_DMA_IRQHandler
DMA2_Stream0_IRQHandler
112
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_DMA_IRQHandler
DMA2_Stream0_IRQHandler
Generated in
stm32f4xx_it.c
113
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_DMA_IRQHandler
DMA2_Stream0_IRQHandler
Defined in
stm32f4xx_hal_dma.c
114
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_DMA_IRQHandler
DMA2_Stream0_IRQHandler
115
DMA Initializations
including peripheral interrupt NVIC
initializations
Start process with interrupt generation at end
of process
HAL_DMA_Start_IT
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_DMA_IRQHandler
DMA2_Stream0_IRQHandler
116
Process interrupt
information
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_DMA_IRQHandler
DMA2_Stream0_IRQHandler
117
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_DMA_IRQHandler
DMA2_Stream0_IRQHandler
118
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_DMA_IRQHandler
DMA2_Stream0_IRQHandler
119
DMA Initializations
including peripheral interrupt NVIC
initializations
Start process with interrupt generation at end
of process
HAL_DMA_Start_IT
HAL_OK
HAL_ERROR
2. DMA transfer
start
HAL_BUSY
5. DMA transfer
was correct
5. Error in DMA
transfer
HAL_DMA_IRQHandler
4. HAL DMA
management
DMA2_Stream0_IRQHandler
3. DMA transfer
complete or error
120
/* USER
uint8_t
uint8_t
/* USER
CODE BEGIN 0 */
Buffer_Src[]={0,1,2,3,4,5,6,7,8,9};
Buffer_Dest[10];
CODE END 0 */
121
122
123
DMA Start
Before we start the DMA with interrupt we need to set the callback into DMA structure
Then is possible use the HAL_DMA_Start_IT to begin DMA transfer
/* USER CODE BEGIN 2 */
hdma_memtomem_dma2_stream0.XferCpltCallback=&XferCpltCallback;
HAL_DMA_Start_IT(&hdma_memtomem_dma2_stream0,(uint32_t)Buffer_Src,(uint32_t)Buffer_Dest,10);
/* USER CODE END 2 */
20/10/2015
Objective
Learn how to setup RTC with interrupt in CubeMX
Create simple RTC project with periodic alarm interrupt
Goal
Use CubeMX and Generate Code with RTC
Learn how to setup the RTC in HAL
Verify the correct functionality by periodic RTC alarm interrupts
125
126
127
RTC Configuration
TAB>Configuration
2. RTC
3. Check configuration
128
129
TAB>NVIC Setup
Enable Alarm interrupt
Button OK
3. Button OK
130
We create the RTC interrupt handler and we reconfigure the Alarm A time
HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm,
uint32_t Format)
HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t
Format)
131
RTC enable
/* Initialize all configured peripherals */
HAL_PWR_EnableBkUpAccess();//enable PWR backup domain access (RTC,BKReg)
__HAL_RCC_RTC_ENABLE();//Enable RTC. not created by cube because the RTC can run.
MX_GPIO_Init();
MX_RTC_Init();
132
RTC enable
/* USER CODE BEGIN 4 */
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc){
RTC_AlarmTypeDef sAlarm;
HAL_RTC_GetAlarm(hrtc,&sAlarm,RTC_ALARM_A,FORMAT_BIN);
if(sAlarm.AlarmTime.Seconds>58){
sAlarm.AlarmTime.Seconds=0;
}else{
sAlarm.AlarmTime.Seconds=sAlarm.AlarmTime.Seconds+1;
}
while(HAL_RTC_SetAlarm_IT(hrtc, &sAlarm, FORMAT_BIN)!=HAL_OK){}
HAL_GPIO_TogglePin(GPIOG,GPIO_PIN_14);
}
/* USER CODE END 4 */
133
134
Advanced task
The counting stops after 1minute
Modify the project to create alarm every 1s for infinite time
/**Enable the Alarm A
*/
sAlarm.AlarmTime.Hours = 0;
sAlarm.AlarmTime.Minutes = 0;
sAlarm.AlarmTime.Seconds = 1;
sAlarm.AlarmTime.SubSeconds = 0;
sAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM;
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_HOURS|RTC_ALARMMASK_MINUTES;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmDateWeekDay = 1;
sAlarm.Alarm = RTC_ALARM_A;
HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, FORMAT_BCD);
We only need to modify the Alarm mask to ignore Days, Hours and Minutes
20/10/2015
Objective
Learn how to setup UART in CubeMX
How to Generate Code in CubeMX and use HAL functions
Work in pairs, one will create transmitter and second receiver
Goal
Configure UART in CubeMX and Generate Code
Learn how to send and receive data over UART without interrupts
Verify the correct functionality
136
Pin selection
We are looking for free pins where is possible to create wire loopback connection
137
Pin selection
We are looking for free pins
where is possible to create
wire loopback connection
Image from
STM32F429-Discovery
user manual
138
Pin selection
We are looking for free pins where is possible to create wire loopback connection
Image from
STM32F429
datasheet
139
Hardware preparation
We connect selected pins together by jumper, this help us to create loopback on UART
Hardware
connection
RX <-TX
TX>RX
140
141
142
143
144
145
146
MX_USART1_UART_Init();
HAL_UART_Init(&huart1);
HAL_UART_MspInit callback
147
1. We need init
UART1
MX_USART1_UART_Init();
HAL_UART_Init(&huart1);
HAL_UART_MspInit callback
148
1. We need init
UART1
MX_USART1_UART_Init();
HAL_UART_Init(&huart1);
HAL_UART_MspInit callback
149
MX_USART1_UART_Init();
1. We need init
UART1
2. Call UART1 init
function
HAL_UART_Init(&huart1);
HAL_UART_MspInit callback
150
151
MX_USART1_UART_Init();
1. We need init
UART1
2. Call UART1 init
function
HAL_UART_Init(&huart1);
HAL_UART_MspInit callback
MX_USART1_UART_Init();
1. We need init
UART1
2. Call UART1 init
function
3. Store UART1 configuration
into structure
HAL_UART_Init(&huart1);
HAL_UART_MspInit callback
152
MX_USART1_UART_Init();
1. We need init
UART1
2. Call UART1 init
function
3. Store UART1 configuration
into structure
HAL_UART_Init(&huart1);
HAL_UART_MspInit callback
Function wrote
parameters from structure
into UART1 registers
153
154
MX_USART1_UART_Init();
HAL_UART_Init(&huart1);
1. We need init
UART1
2. Call UART1 init
function
3. Store UART1 configuration
into structure
4. Write to UART1 registers
HAL_UART_MspInit callback
155
MX_USART1_UART_Init();
HAL_UART_Init(&huart1);
1. We need init
UART1
2. Call UART1 init
function
3. Store UART1 configuration
into structure
4. Write to UART1 registers
HAL_UART_MspInit callback
156
MX_USART1_UART_Init();
HAL_UART_Init(&huart1);
1. We need init
UART1
2. Call UART1 init
function
3. Store UART1 configuration
into structure
4. Write to UART1 registers
HAL_UART_MspInit callback
MX_USART1_UART_Init();
HAL_UART_Init(&huart1);
1. We need init
UART1
2. Call UART1 init
function
3. Store UART1 configuration
into structure
4. Write to UART1 registers
HAL_UART_MspInit callback
157
MX_USART1_UART_Init();
HAL_UART_Init(&huart1);
1. We need init
UART1
2. Call UART1 init
function
3. Store UART1 configuration
into structure
4. Write to UART1 registers
HAL_UART_MspInit callback
158
Generated by
CubeMX
Peripheral Initializations
Polling process
HAL_UART_Transmit
HAL_TIMEOUT
HAL_OK
HAL_ERROR
Function blocks
Polling with timeout
HAL_BUSY
159
Peripheral Initializations
Polling process
HAL_UART_Transmit
HAL_TIMEOUT
HAL_OK
HAL_ERROR
Function blocks
Polling with timeout
HAL_BUSY
160
Generated by
CubeMX
Peripheral Initializations
Polling process
HAL_UART_Receive
HAL_TIMEOUT
HAL_OK
HAL_ERROR
Function blocks
Polling with timeout
HAL_BUSY
161
Peripheral Initializations
Polling process
HAL_UART_Receive
HAL_TIMEOUT
HAL_OK
HAL_ERROR
Function blocks
Polling with timeout
HAL_BUSY
162
163
Transmit solution
Create data structure for data
164
Receive solution
Create data structure for data
165
20/10/2015
10
Objective
Learn how to setup UART with interrupts in CubeMX
How to Generate Code in CubeMX and use HAL functions
Create simple loopback example with interrupts
Goal
Configure UART in CubeMX and Generate Code
Learn how to send and receive data over UART with interrupts
Verify the correct functionality
167
10
Pin selection
It will be same as previous lab we use again PA9 and PA10
168
10
Hardware preparation
We connect selected pins together by jumper, this help us to create loopback on UART
Hardware
loopback
169
10
170
10
171
10
172
10
173
10
174
10
175
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_UART_IRQHandler
USART1_IRQHandler
10
176
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_UART_IRQHandler
USART1_IRQHandler
10
177
Generated by CubeMX
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_UART_IRQHandler
USART1_IRQHandler
10
178
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_UART_IRQHandler
USART1_IRQHandler
Defined by user
10
179
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_UART_IRQHandler
USART1_IRQHandler
10
180
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_UART_IRQHandler
USART1_IRQHandler
We recommend to use it
in main.c
10
181
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_UART_IRQHandler
USART1_IRQHandler
10
182
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_UART_IRQHandler
USART1_IRQHandler
Generated in
stm32f4xx_it.c
10
183
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_UART_IRQHandler
USART1_IRQHandler
Defined in
stm32f4xx_hal_uart.c
10
184
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_UART_IRQHandler
USART1_IRQHandler
10
185
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_UART_IRQHandler
USART1_IRQHandler
10
186
HAL_OK
HAL_ERROR
HAL_BUSY
Process interrupt
information
HAL_UART_IRQHandler
USART1_IRQHandler
10
187
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_UART_IRQHandler
USART1_IRQHandler
10
188
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_UART_IRQHandler
USART1_IRQHandler
10
189
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_UART_IRQHandler
USART1_IRQHandler
10
190
Peripheral Initializations
including peripheral interrupt NVIC
initializations
Start process with interrupt generation at end
of process
HAL_UART_Transmit_IT
HAL_OK
HAL_ERROR
2. UART1 send
buffer
HAL_BUSY
5. Buffer sent
5. Transmit error
HAL_UART_IRQHandler
4. Send more
data or manage
error
USART1_IRQHandler
3. UART1 Tx
register empty
10
191
10
Buffer definition
/* USER
uint8_t
uint8_t
/* USER
CODE BEGIN 0 */
tx_buff[]={0,1,2,3,4,5,6,7,8,9};
rx_buff[10];
CODE END 0 */
192
10
193
10
!!!!!!!! F4 cube 1.3.0 error in TX and RX. If we use loopback mode with
interrupt will not work correctly
/* USER CODE BEGIN 4 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
__NOP();//test if we reach this position
}
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
__NOP();//test if we reach this position
}
/* USER CODE END 4 */
194
20/10/2015
11
Objective
Learn how to setup UART with DMA in CubeMX
How to Generate Code in CubeMX and use HAL functions
Create simple loopback example with DMA
Goal
Configure UART in CubeMX and Generate Code
Learn how to send and receive data over UART with DMA
Verify the correct functionality
196
11
Pin selection
It will be same as previous lab we use again PA9 and PA10
197
11
Hardware preparation
We connect selected pins together by jumper, this help us to create loopback on UART
Hardware
loopback
198
11
199
11
200
11
201
11
202
11
203
11
204
11
205
11
206
11
207
HAL_OK
HAL_ERROR
HAL_ERROR
HAL_DMA_IRQHandler
DMA_Stream_IRQ
Handler
11
208
Generated by CubeMX
HAL_OK
HAL_ERROR
HAL_ERROR
HAL_DMA_IRQHandler
DMA_Stream_IRQ
Handler
11
209
HAL_OK
HAL_ERROR
HAL_ERROR
HAL_DMA_IRQHandler
DMA_Stream_IRQ
Handler
Defined by user
process Error callback
HAL_UART_ErrorCallback
11
210
HAL_OK
HAL_ERROR
HAL_ERROR
HAL_DMA_IRQHandler
DMA_Stream_IRQ
Handler
11
211
HAL_OK
HAL_ERROR
HAL_ERROR
HAL_DMA_IRQHandler
DMA_Stream_IRQ
Handler
We recommend to use it
in main.c
11
212
HAL_OK
HAL_ERROR
HAL_ERROR
HAL_DMA_IRQHandler
DMA_Stream_IRQ
Handler
Generated in
stm32f4xx_it.c
process Error callback
HAL_UART_ErrorCallback
11
213
HAL_OK
HAL_ERROR
HAL_ERROR
HAL_DMA_IRQHandler
DMA_Stream_IRQ
Handler
Defined in
stm32f4xx_hal_dma.c and
then linked to
stm32f4xx_hal_uart.c
11
214
HAL_OK
HAL_ERROR
HAL_ERROR
HAL_DMA_IRQHandler
DMA_Stream_IRQ
Handler
11
215
HAL_OK
HAL_ERROR
HAL_ERROR
HAL_DMA_IRQHandler
DMA_Stream_IRQ
Handler
11
216
HAL_OK
HAL_ERROR
Process interrupt
information from DMA and
UART
HAL_ERROR
HAL_DMA_IRQHandler
DMA_Stream_IRQ
Handler
11
217
HAL_OK
HAL_ERROR
HAL_ERROR
HAL_DMA_IRQHandler
DMA_Stream_IRQ
Handler
11
218
HAL_OK
HAL_ERROR
HAL_ERROR
HAL_DMA_IRQHandler
DMA_Stream_IRQ
Handler
11
219
Peripheral Initializations
including DMA stream initializations
HAL_OK
HAL_ERROR
2. UART1
receive buffer
HAL_ERROR
HAL_DMA_IRQHandler
5. Buffer
received
5. Receive error
4. Process
interrupt
DMA_Stream_IRQ
Handler
3. DMA buffer
full
11
220
11
Buffer definition
/* USER
uint8_t
uint8_t
/* USER
CODE BEGIN 0 */
tx_buff[]={0,1,2,3,4,5,6,7,8,9};
rx_buff[10];
CODE END 0 */
221
11
222
20/10/2015
12
Objective
Learn how to setup SPI in CubeMX
How to Generate Code in CubeMX and use HAL functions
Goal
Configure SPI in CubeMX and Generate Code
Learn how to send and receive data over SPI without interrupts
Verify the correct functionality
224
12
Pin selection
We are looking for free pins where is possible to create wire loopback connection
225
12
226
12
Hardware preparation
Connect PA6 and PA7 together with jumper
Hardware
loopback
227
12
228
12
229
12
230
12
231
12
Peripheral Initializations
Polling process
HAL_SPI_TransmitReceive
HAL_TIMEOUT
HAL_OK
HAL_ERROR
Function blocks
Polling with timeout
HAL_BUSY
232
12
233
12
/* USER
uint8_t
uint8_t
/* USER
CODE BEGIN PV */
tx_buffer[]={0,1,2,3,4,5,6,7,8,9};
rx_buffer[10];
CODE END PV */
234
20/10/2015
13
Objective
Learn how to setup SPI with interrupts in CubeMX
How to Generate Code in CubeMX and use HAL functions
Create simple loopback example with interrupts
Goal
Configure SPI in CubeMX and Generate Code
Learn how to send and receive data over SPI with interrupts
Verify the correct functionality
236
13
237
13
Hardware preparation
Connect PA6 and PA7 together with jumper
Hardware
loopback
238
13
239
13
240
13
CubeMX SPI configuration
TAB>NVIC Settings
Enable SPI interrupt
Button OK
241
13
242
13
243
HAL_OK
HAL_ERROR
HAL_BUSY
HAL_SPI_IRQHandler
SPI1_IRQHandler
13
244
13
Buffer definition
/* USER
uint8_t
uint8_t
/* USER
CODE BEGIN 0 */
tx_buff[]={0,1,2,3,4,5,6,7,8,9};
rx_buff[10];
CODE END 0 */
245
13
246
20/10/2015
14
Objective
Learn how to setup SPI with DMA in CubeMX
How to Generate Code in CubeMX and use HAL functions
Create simple loopback example with DMA
Goal
Configure SPI in CubeMX and Generate Code
Learn how to send and receive data over SPI with DMA
Verify the correct functionality
248
14
249
14
Hardware preparation
Connect PA6 and PA7 together with jumper
Hardware
loopback
250
14
251
14
252
14
253
14
254
14
255
14
256
HAL_OK
HAL_ERROR
HAL_ERROR
HAL_DMA_IRQHandler
DMA2_Stream0_IRQ
Handler
14
257
14
Buffer definition
/* USER
uint8_t
uint8_t
/* USER
CODE BEGIN 0 */
tx_buff[]={0,1,2,3,4,5,6,7,8,9};
rx_buff[10];
CODE END 0 */
258
14
259
20/10/2015
15
Objective
Learn how to setup TIM with Interrupt in CubeMX
How to Generate Code in CubeMX and use HAL functions
Indicate TIM interrupt with LED toggle
Goal
Configure TIM in CubeMX and Generate Code
Learn how start timer and handle interrupt
Verify the correct functionality
261
15
262
15
CubeMX TIM configuration
Tab>Configuration>Control>TIM1
Check the settings
263
15
CubeMX TIM configuration
Tab>Parameter Settings
Prescaler to 18000
Counter period to 10000
Together with 180MHz TIMER1
clock we get period 1Hz
264
15
CubeMX TIM configuration
Tab>NVIC Settings
Enable TIM1 Update interrupt
Button OK
265
15
266
15
267
HAL_OK
HAL_ERROR
process callback
HAL_TIM_PeriodElapsedCallback
HAL_BUSY
HAL_TIM_IRQHandler
TIM1_UP_TIM10_IRQHandler
15
TIM callback
void TIM1_UP_TIM10_IRQHandler(void)
268
15
Solution
TIM start
269
20/10/2015
16
Objective
Learn how to setup TIM with PWM out in CubeMX
How to Generate Code in CubeMX and use HAL functions
Indicate TIM PWM on LED
Goal
Configure TIM in CubeMX and Generate Code
Learn how start timer and set PWM out
Verify the correct functionality with LED
271
16
272
16
273
16
274
16
Peripheral
Initializations
Start Process
HAL_TIM_PWM_Start
275
16
276
16
Solution
TIM PWM start
277
20/10/2015
17
Objective
Learn how to setup TIM with DMA in CubeMX
How to Generate Code in CubeMX and use HAL functions
Indicate TIM DMA transfer with LED toggle
Goal
Configure TIM in CubeMX and Generate Code
Learn how start timer and setup DMA
Verify the correct functionality with DMA transfer into GPIO register
279
17
280
17
281
17
282
17
283
17
284
17
HAL_OK
HAL_ERROR
HAL_ERROR
HAL_OK
HAL_ERROR
HAL_ERROR
285
17
286
17
287
20/10/2015
18
Objective
Learn how to setup TIM as counter in CubeMX
How to Generate Code in CubeMX and use HAL functions
Indicate TIM count 5 button press with LED toggle
Goal
Configure TIM as counter in CubeMX and Generate Code
Learn how start timer and handle interrupt
Verify the correct functionality with LED toggle after 5 button press
289
18
290
18
291
18
292
18
293
18
294
18
295
18
296
HAL_OK
HAL_ERROR
process callback
HAL_TIM_PeriodElapsedCallback
HAL_BUSY
HAL_TIM_IRQHandler
TIM1_UP_TIM10_IRQHandler
18
TIM callback
void TIM1_UP_TIM10_IRQHandler(void)
297
18
Solution
TIM start
298
20/10/2015
19
Objective
Learn how to setup DAC as wave generator in CubeMX
How to Generate Code in CubeMX and use HAL functions
Goal
Configure DAC as wave generator in CubeMX and Generate Code
Learn how start it in project
300
19
301
19
302
19
303
19
Peripheral
Initializations
Start Process
HAL_DAC_Start
Set value
HAL_DAC_SetValue
304
19
305
19
Solution
DAC setup and start
/* USER CODE BEGIN 2 */
HAL_DAC_Start(&hdac,DAC_CHANNEL_2);
/* USER CODE END 2 */
306
20/10/2015
20
Objective
Use the DAC part from previous lab
Learn how to setup ADC in CubeMX
How to Generate Code in CubeMX and use HAL functions
Goal
Configure ADC in poll in CubeMX and Generate Code
Learn how to start ADC and measure the DAC
Verify the measured wave in STMStudio
(http://www.st.com/web/en/catalog/tools/PF251373 require JAVA)
308
20
309
20
Hardware connection
Connect DAC out2 PA5 and ADC1 IN13 PC3 together
310
20
311
20
312
20
Start Process
HAL_DAC_Start
Peripheral
Initializations
Start Process
HAL_ADC_Start
313
20
314
DAC functions
HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment,
uint32_t Data)
20
Solution
Variables
/* USER CODE BEGIN PV */
uint32_t value_adc;
uint32_t value_dac=0;
/* USER CODE END PV */
315
20
Solution
Main loop with DAC set and ADC set
/* USER CODE BEGIN 3 */
/* Infinite loop */
while (1)
{
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1,10);
value_adc=HAL_ADC_GetValue(&hadc1);
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_2, DAC_ALIGN_12B_R, value_dac);
value_dac++;
if(value_dac>4095){
value_dac=0;
}
HAL_Delay(1);
}
/* USER CODE END 3 */
316
20
317
20
STM studio settings
Set value_adc address
my 0x2000005C
Set 16bit unsigned val
Right click on this line
Select Send To
VarViewer1
318
20
319
20
STM studio settings
Now press
green play button
And you will see
content of
value_adc
320
20/10/2015
21
Objective
Use the DAC part from previous lab
Learn how to setup ADC with interrupt in CubeMX
How to Generate Code in CubeMX and use HAL functions
Goal
Configure ADC in interrupt in CubeMX and Generate Code
Learn how to start ADC and measure the DAC
Verify the measured wave in STMStudio
(http://www.st.com/web/en/catalog/tools/PF251373 require JAVA)
322
21
323
21
324
21
CubeMX ADC configuration
TAB>NVIC settings
Enable ADC1 interrupt
Button OK
325
21
CubeMX NVIC configuration
Because we want use the
Systick for delay in interrupt
The ADC interrupt priority must
be changed
TAB>Configuration>System>NVIC
Change ADC1
preemption priority
to 1
326
21
327
21
HAL_OK
HAL_ERROR
process callback
HAL_ADC_ConvCpltCallback
HAL_BUSY
HAL_ADC_IRQHandler
ADC_IRQHandler
328
21
329
DAC functions
HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment,
uint32_t Data)
21
Solution
Variables
/* USER CODE BEGIN PV */
uint32_t value_adc;
uint32_t value_dac=0;
/* USER CODE END PV */
330
21
Solution
ADC complete callback routine
/* USER CODE BEGIN 4 */
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
value_adc=HAL_ADC_GetValue(&hadc1);
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_2, DAC_ALIGN_12B_R, value_dac);
value_dac++;
if(value_dac>4095){
value_dac=0;
}
HAL_Delay(1);
HAL_ADC_Start_IT(&hadc1);
}
/* USER CODE END 4 */
331
21
STM studio settings
Check functionality
again with
STMstudio
332
20/10/2015
22
Objective
Use the DAC part from previous lab
Learn how to setup ADC with DMA in CubeMX
How to Generate Code in CubeMX and use HAL functions
Goal
Configure ADC in DMA in CubeMX and Generate Code
Learn how to start ADC and measure the DAC
Verify the measured wave in STMStudio
(http://www.st.com/web/en/catalog/tools/PF251373 require JAVA)
334
22
335
22
336
22
CubeMX ADC configuration
TAB>DMA Settings
Button ADD
DMA request ADC1
Peripheral to memory direction
Circular mode
Memory increment
Half word data width
Button OK
337
22
338
22
339
HAL_OK
HAL_ERROR
process callback
HAL_ADC_ConvCpltCallback
HAL_BUSY
HAL_DMA_IRQHandler
DMA1_StreamX_IRQHandler
22
340
DAC functions
HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment,
uint32_t Data)
22
Solution
Variables
/* USER CODE BEGIN PV */
uint32_t value_adc;
uint32_t value_dac=0;
/* USER CODE END PV */
341
22
Solution
ADC main routine
/* USER CODE BEGIN 3 */
/* Infinite loop */
while (1)
{
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_2, DAC_ALIGN_12B_R, value_dac);
value_dac++;
if(value_dac>4095){
value_dac=0;
}
HAL_Delay(5);
HAL_ADC_Start(&hadc1);
HAL_Delay(5);
}
/* USER CODE END 3 */
342
22
STM studio settings
Check functionality
again with
STMstudio
343
WWDG lab 23
20/10/2015
23
Use WWDG
Objective
Learn how to setup WWDG in CubeMX
How to Generate Code in CubeMX and use HAL functions
Create simple application to test WWDG
Goal
Configure WDGin in CubeMX and Generate Code
Learn how to start WWDG
WWDG indication via LED
345
23
Use WWDG
346
23
Use WWDG
347
23
Use WWDG
348
23
CubeMX WWDG configuration
TAB>Configuration>System>
>WWDG>Parameter Settings
Set prescaller to 8
WWDG window to 80
And free running counter to 127
Button OK
Use WWDG
349
23
Now we set the project details for generation
Menu > Project > Project Settings
Set the project name
Project location
Type of toolchain
Use WWDG
350
23
How calculate the window
Use WWDG
APB1freq=45MHz, prescaller 8
We refresh the
WWDG to 127
In our case 80
Fixed 63
351
23
Use WWDG
Solution
WWDG Start
352
IWDG lab 24
20/10/2015
24
Use IWDG
Objective
Learn how to setup WWDG in CubeMX
How to Generate Code in CubeMX and use HAL functions
Create simple application to test WWDG
Goal
Configure WDGin in CubeMX and Generate Code
Learn how to start WWDG
WWDG indication via LED
354
24
Use IWDG
355
24
Use IWDG
356
24
CubeMX ADC configuration
TAB>Configuration>System>
>IWDG>Parameter Settings
Set prescaller to 4
Max value to 50
Button OK
Use IWDG
357
24
Now we set the project details for generation
Menu > Project > Project Settings
Set the project name
Project location
Type of toolchain
Use IWDG
358
24
Use IWDG
t iwdg =
1
f LSI
1
) * 4 * 50 = 6.25ms
3
32 *10
359
24
Use IWDG
Solution
IWDG Start
360
24
Hardware IWDG
Remove IWDG start from project
Use IWDG
361
24
Hardware IWDG
Start ST-Link utility
Menu>Target>Option bytes
or CTRL+B
Uncheck the WDG_WS
Button APPLY
Now the IWDG is automatically started after reset
Use IWDG
362
20/10/2015
25
Objective
Learn how import BSP into project
Which part need to by configured in GUI
Try to write data into SDRAM and read it
Goal
Successfully import BSP into your project
Learn which part you need to import
How to setup the project
364
25
365
25
366
25
stm32f4xx_discovery_sdram.c
stm32f4xx_discovery_io.c
Components
ili9341.c
lis3dsh.c
stmpe811.c
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_sdram.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
367
25
stm32f4xx_discovery_sdram.c
stm32f4xx_discovery_io.c
Components
ili9341.c
lis3dsh.c
stmpe811.c
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_sdram.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
368
25
1. include
stm32f4xx_discovery_sdram.h
Our project
BSP package
Discovery drivers
stm32f4xx_discovery.c
stm32f4xx_discovery_sdram.c
2. include
stm32f4xx_discovery.h
Components
ili9341.c
lis3dsh.c
stm32f4xx_discovery_io.c
stmpe811.c
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_sdram.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
369
25
3. include stm32f4xx_hal.h
Discovery drivers
stm32f4xx_discovery.c
stm32f4xx_discovery_sdram.c
Components
ili9341.c
lis3dsh.c
stmpe811.c
stm32f4xx_discovery_io.c
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_sdram.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
370
25
stm32f4xx_discovery_sdram.c
Components
ili9341.c
lis3dsh.c
stmpe811.c
stm32f4xx_discovery_io.c
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_sdram.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
371
25
6. HAL_SDRAM_Init
is function from
stm32f4xx_discovery_sdram.c
Discovery drivers
stm32f4xx_discovery_sdram.c
stm32f4xx_discovery_io.c
Components
ili9341.c
lis3dsh.c
stmpe811.c
8. stm32f4xx_II_fmc.c use
functions from
stm32f4xx_hal_sdram.c
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_sdram.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
372
25
User Code
stm32f4xx_it.c
BSP Drivers
Stm32f4xx_discovery.c
Stm32ffxx_discovery_sdram.c
Include files
user_code.h
stm32f4xx_it.h
Stm32f4xx_discovery.h
Stm32ffxx_discovery_sdram.h
stm32f4xx_hal.h
HAL Drivers
stm32f4xx_hal_ppp.c
stm32f4xx_hal_ppp_ex.c
stm32f4xx_hal_conf.h
stm32f4xx_hal.c
stm32f4xx_hal_ppp.h
stm32f4xx_hal_ppp_ex.h
stm32f4xx_hal_def.h
373
25
374
25
375
25
376
25
377
25
378
25
379
25
SDRAM test
/* USER CODE BEGIN PV */
volatile uint32_t value;
/* USER CODE END PV */
380
20/10/2015
26
Objective
Learn how import BSP LCD into project
Because the LCD use the SDRAM we use project from lab 25
Which part need to by configured in GUI
Try to write text on LCD
Goal
Successfully import BSP LCD into your project
Learn which part you need to import
How to setup the project
382
26
stm32f4xx_discovery_lcd.c
stm32f4xx_discovery_sdram.c
Utilities
Components
ili9341.c
lis3dsh.c
stmpe811.c
Fonts
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_hal_sdram.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_ltdc.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
383
26
1. include
stm32f4xx_discovery_lcd.h
Our project
BSP package
Discovery drivers
stm32f4xx_discovery.c
stm32f4xx_discovery_lcd.c
Components
ili9341.c
lis3dsh.c
stmpe811.c
stm32f4xx_discovery_sdram.c
2. stm32f4xx_discovery_lcd.h
Utilities
use the discovery BSP and
SDRAM
Fonts
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_hal_sdram.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_ltdc.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
384
26
stm32f4xx_discovery_lcd.c
Components
ili9341.c
lis3dsh.c
stmpe811.c
stm32f4xx_discovery_sdram.c
Utilities
4. stm32f4xx_discovery_lcd.h
use LCTD controller from HAL
Fonts
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_hal_sdram.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_ltdc.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
385
26
stm32f4xx_discovery_lcd.c
stm32f4xx_discovery_sdram.c
Utilities
Components
ili9341.c
lis3dsh.c
2. stm32f4xx_discovery_lcd.h
use fonts from utility folder
stmpe811.c
Fonts
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_hal_sdram.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_ltdc.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
386
26
387
26
388
26
389
26
390
26
391
26
392
26
393
20/10/2015
27
Objective
Learn how import BSP EEPROM into project
We use the project from lab 26
Which part need to by configured in GUI
Try to write text into EEPROM and read it
Read text from EEPROM and display it on LCD
Goal
Successfully import BSP EEPROM drivers into your project
Learn which part you need to import
How to setup the project
395
27
stm32f4xx_discovery_eeprom.c
stm32f4xx_discovery_lcd.c
stm32f4xx_discovery_sdram.c
stm32f4xx_discovery.c
Utilities
Components
ili9341.c
lis3dsh.c
stmpe811.c
Fonts
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_hal_sdram.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_ltdc.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
396
27
397
Our project
BSP package
Discovery drivers
stm32f4xx_discovery_io.c
stm32f4xx_discovery_eeprom.c
stm32f4xx_discovery_lcd.c
stm32f4xx_discovery_sdram.c
stm32f4xx_discovery.c
Utilities
Components
ili9341.c
lis3dsh.c
stmpe811.c
Fonts
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_hal_sdram.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_ltdc.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
27
stm32f4xx_discovery_eeprom.c
stm32f4xx_discovery_lcd.c
stm32f4xx_discovery_sdram.c
stm32f4xx_discovery.c
ili9341.c
3. stm32f4xx_discovery_io.c call
Components
functions from
stm32f4xx_discovery.c
lis3dsh.c
stmpe811.c
pin init and write/read functions
Utilities
Fonts
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_hal_sdram.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_ltdc.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
398
27
stm32f4xx_discovery_eeprom.c
stm32f4xx_discovery_lcd.c
stm32f4xx_discovery_sdram.c
stm32f4xx_discovery.c
Components
ili9341.c
4. stm32f4xx_discovery.c
Use stm32f4xx_hal_i2c to
lis3dsh.c
stmpe811.c
commutate with eeprom memory
Utilities
Fonts
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_hal_sdram.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_ltdc.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
399
27
400
27
401
27
402
27
403
27
Define variables
/* USER CODE BEGIN PV */
uint8_t text_to_write[]="test text";//write to eeprom
uint8_t text_to_read[200];//read from eeprom
uint32_t address=0;//address in eeprom
uint16_t read_num=1;//number of bytes which we want to read from
eeprom
/* USER CODE END PV */
404
27
405
27
406
20/10/2015
28
Objective
Learn how import BSP GYROSCOPE into project
We use the project from lab 26
Which part need to by configured in GUI
Read data from GYROSCOPE and display it on LCD
Goal
Successfully import BSP GYROSCOPE drivers into your project
Learn which part you need to import
How to setup the project
408
28
stm32f4xx_discovery_gyroscope.c
stm32f4xx_discovery_lcd.c
stm32f4xx_discovery_sdram.c
stm32f4xx_discovery.c
Utilities
Components
ili9341.c
lis3dsh.c
stmpe811.c
Fonts
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_hal_sdram.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_ltdc.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
409
28
410
Our project
BSP package
Discovery drivers
stm32f4xx_discovery_io.c
stm32f4xx_discovery_gyroscope.c
stm32f4xx_discovery_lcd.c
stm32f4xx_discovery_sdram.c
stm32f4xx_discovery.c
Utilities
Components
ili9341.c
lis3dsh.c
stmpe811.c
Fonts
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_hal_sdram.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_ltdc.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
28
stm32f4xx_discovery_gyroscope.c
stm32f4xx_discovery_lcd.c
stm32f4xx_discovery_sdram.c
stm32f4xx_discovery.c
ili9341.c
3. stm32f4xx_discovery_io.c call
Components
functions from
stm32f4xx_discovery.c
lis3dsh.c
stmpe811.c
pin init and read functions
Utilities
Fonts
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_hal_sdram.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_ltdc.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
411
28
stm32f4xx_discovery_gyroscope.c
stm32f4xx_discovery_lcd.c
stm32f4xx_discovery_sdram.c
stm32f4xx_discovery.c
Components
ili9341.c
lis3dsh.c
4. stm32f4xx_discovery.c
Use stm32f4xx_hal_spi to
stmpe811.c
commutate with gyroscope
Utilities
Fonts
HAL API
stm32f4xx_hal_spi.c
stm32f4xx_hal_sdram.c
stm32f4xx_II_fmc.c
stm32f4xx_hal_ltdc.c
stm32f4xx_hal.c
stm32f4xx_hal_i2c.c
412
28
413
28
414
28
Define variables
/* USER CODE BEGIN PV */
float valxyz[3];//gyroscope values
uint8_t buffer[200];//text buffer
/* USER CODE END PV */
415
28
416
28
417
20/10/2015
CubeMX install
CubeMX tool
http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1533/PF259242?s_searchtype=
partnumber
Optionally you can download the Cube packages for STM32 device if you
dont want to download them throe CubeMX
STM32CubeL0
STM32CubeL1
STM32CubeF0
STM32CubeF2
STM32CubeF3
STM32CubeF4
419
CubeMX install
420
CubeMX install
The comparison of the CubeMX repository settings and structure in this folder
421
CubeMX install
For the code generation the CubeMX use the package from the Repository
folder
The CubeMX can generate the code for some GUI
Keil
IAR
Atollic
For driver installation you will need the Admin rights on your PC
422
Appendix B Documents
20/10/2015
CubeMX documentation
424
STM32F4 documentation
STM32F429 Datasheet
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00071990.pdf
425
STM32F429i-Discovery
documentation
STM32F429i-Discovery page
http://www.st.com/web/en/catalog/tools/FM116/SC959/SS1532/LN1848/PF259090?s_searchtyp
e=keyword
426
TODO
Example list todo
1. GPIO - done
2. EXTI - done
3. SLEEP - done
4. STOP - done
5. STANDBY -done
6. DMA M2M - done
7. DMA IT - done
8. RTC - done
9. USART - done
10. USART IT - done
11. USART DMA - done
427
TODO
Example list todo
12. SPI Poll - done
13. SPI IT - done
14. SPI DMA - done
15. TIM IT - done
16. TIM PWM out - done
17. TIM DMA - done
18. TIM Counter done
19. DAC wave generation done
20. ADC poll done
21. ADC IT - done
22. ADC DMA - done
428
TODO
429
www.st.com/stm32
STM32F42xx Technical Training
20/10/2015