Skip to content

0xrocky/stm32f4-discovery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stm32f4-discovery

Experiments with the STM32F407VGT6 MCU.

1. Blinky

Program that, in rotation, turns on and off all the following LEDs on the STM32F4 MCU:

  • user LD3: orange LED is a user LED connected to the I/O PD13 of the STM32F407VGT6
  • user LD4: green LED is a user LED connected to the I/O PD12 of the STM32F407VGT6
  • user LD5: red LED is a user LED connected to the I/O PD14 of the STM32F407VGT6
  • user LD6: blue LED is a user LED connected to the I/O PD15 of the STM32F407VGT6

2. Interrupt

Three exercises for managing an interrupt on EXTI0 (blue button)

The following examples show how to use interrupts to toggle a LED every time we press the user-programmable blue button, which is connected to the PA0 pin:

  1. bare-metal programming
  2. using the ST HAL
  3. using CubeMX

Exercise on nested interrupts (EXTI0 & EXTI1)

Interrupt management with a timer

Prepare a platform with three interrupt sources (I1, I2, I3) each connected to a LED. Write the corresponding interrupt response handlers such that:

  • upon detection of an interrupt signal Ix, 1<= x <= 3, a timer is started
  • if within a predetermined time period T no other interrupt signal is received the LDx is switched on
  • if other interrupts are detected within the predetermined term, all the LEDs corresponding to the interrupts detected will be switched on simultaneously at the end of T

3. printf() with UART/USART

Friends who have studied C should know the standard library functions printf() and scanf(), the former for printing information to the console, and the latter for reading characters from the keyboard to the program. If printf() is called in the program of the microcontroller, where will it be displayed? The answer is unknowable, because the microcontroller does not have a console, but we can use its peripherals to implement printf(), such as LCD or serial port (the serial port is then connected to the computer to display the print information). The serial port is basically the majority of microcontrollers, and the LCD is not necessarily, so we usually use the serial port to print content. So as long as it is a serial port microcontroller, is it possible to print the information by calling printf()?

4. DMA

Two exercises for managing the DMA, in polling and in interrupt.

5. Timer in Input Capture Mode

Application which:

  • set up a GP timer and configure CHx to be input captured on every rising edge of the RCC External Clock Source
  • read (via DMA) the CCRx register and save it to variable T1 on the first edge, on second edge read CCR1 and save it to T2. And now, the input signal's period is T2 – T1, and therefore, the frequency is easily calculated from 1/period
  • configure USART in Async mode and print the calculated frequency to the serial port terminal

6. ADC and Temperature Sensor

Program that acquires data from the built-in temperature sensor using interrupts and:

  • if the detected temperature exceeds 28° C activates the red LED
  • if the temperature drops below 18° C the blue LED lights up
  • for intermediate temperatures the green LED stays on The program also calculates the time taken by the interrupt response routine generated by the ADC circuit.