Download presentation
Presentation is loading. Please wait.
1
32-bitni mikrokontroleri i primena - MS1BMP
2017/2018 Nenad Jovičić Marija Janković
2
STM32L476RG – kopamo dublje STM32L476xx – MCU Datasheet
Provera karakteristika pri izboru mikrokontrolera Alternate pin function Additional pin function STM32 Nucleo-64 board – User Manual Solder bridges STM32L4x5 and STM32L4x6 advanced ARM®-based 32-bit MCUs - Reference Manual Sve što ste hteli da znate ali vas mrzi da čitate Ako hoćemo da znamo čime zapravo raspolažemo i šta sve nudi naš mikrokontroler treba da pogledamo par stvari, Datasheet čipa, User Manual ploče koji nam ukratko ukazuje na mogućnosti i pomoću koga možemo da vidimo da li nam neki mikrokontroler odgovara ili ne. I na kraju Reference manual koji detaljno opisuje anatomiju i fiziologiju mikrokontrolera. Otvoriti reference manual i pokazati sekciju o GPIO.
3
STM Cortex-M - GPIO - Portovi
5V tolerantni ulazi Kapacitet po pinu 25mA 18 MHz učestanost toglovanja Konfigurabilna izlazna brzina do 50 MHz Do 16 analognih ulaza Alternativne funkcije (USARTx, TIMx, I2Cx, SPIx,…) Svaki pin može da generiše spoljašnji prekid Jedan pin može da se koristi za buđenje iz STANDBY moda (PA.00) Jedan pin može da bude Tamper Pin (za watchdog) (PC.13) Pinovi grupisani u 5 16-bitnih portova (GPIOA..GPIOE) Mehanizam zaključavanja konfiguracije
4
Analog Input/Output (Reset state)
GPIO Konfiguracije Analog Input Configuration Mode CNF1 CNF0 MOD1 MOD0 To On-chip Peripherals ON/OFF Pull - UP Pull - Down VDD VSS Analog Input/Output (Reset state) 00 Alternate Function Input Input Floating 1 01 ON OFF Input Pull-Up(2) 1 Read Input Data Register VDD or VDD_FT(1) Input Pull-Down(2) TTL Schmitt Trigger Output Push-Pull 10 Input Driver I/O pin Output Open-Drain 1 VDD VSS Output Driver AF Push-Pull 1 11 Write Bit Set/Reset Registers OUTPUT CONTROL Output Data Register VSS AF Open-Drain 1 Push-Pull or Open Drain Read / Write or disabled From On-chip Peripherals Alternate Function Output
5
Ulazna konfiguracija Izlazni bafer je isključen
Schmitt trigger kolo je aktivno Pull-up i pull-down otpornici su aktivni u zavisnosti od sadržaja GPIOx_PUPDR registra Vrednosti na ulazima pinova se očitavaju i upisuju u ulazni registar na svaki takt AHB magistrale Čitanjem ulaznog registra (Input data register) dobijaju se digitalna stanja ulaza
6
Izlazna konfiguracija
Open-Drain mod: “0” u Output Data registru aktivira N-MOS tranzistor, dok “1” u Output Data registru ostavlja pin u stanju visoke impedanse (P-MOS transistor se nikada ne aktivira). Push-pull mod: “0” u Output Data registru aktivira N-MOS, dok “1” u Output Data registru aktivira P-MOStor. Schmitt Trigger kolo je uključeno Interni pull-up i pull-down otpornici su isključeni Stanje koje je na pinu se sempluje i upisuje u Input Data registar na svaki APB2 klok Čitanjem Input Data registra očitava se stanje pina kada je konfigurisan u Open-Drain ili Push-pull modu ako je pomenut debounsing treba objasniti i sta je schmitt trigger, tj. kako nam je on obezbedio da lepo detektujemo pritisak ili puštanje tastera.
7
Konfiguracija alternativne funkcije
Izlazni dajver je u Open Drain ili Push-Pull konfiguraciji Schmitt Trigger ulaz je aktiviran Pull-up i pull-down otpornici su deaktivirani Podatak na pinu se sempluje u ulazni registar na svaku ivicu APB2 takta Ako je izlaz u open drain modu očitavanje ulaznog registra daje stanje na pinu
8
Konfiguracija analognog ulaza
Izlazni bafer je isključen (otkačen) Schmitt Trigger kolo je isključeno zbog smanjenja potrošnje. Pull-up i pull-down otpornici su isključeni Očitavanje ulaznog registra uvek daje “0”
9
GPIO registri Četiri 32-bitna konfiguraciona registra (GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, GPIOx_PUPDR) Dva 32-bitna data registra (GPIOx_IDR, GPIOx_ODR) Jedan 32-bitni set/reset registar (GPIOx_BSRR) Jedan 16-bitni reset registar (GPIOx_BRR) Jedan 32-bitni locking registar (GPIOx_LCKR) Dva 32-bitna alternate function selekciona registra (GPIOx_AFRH, GPIOx_AFRL)
10
Port mode register (GPIOx_MODER) (x=A..I)
11
Port output type register (GPIOx_OTYPER) (x=A..I)
Port pull-up/pull-down register (GPIOx_PUPDR) (x=A..I)
12
Port speed register (GPIOx_OSPEEDR) (x=A..I)
13
Port input data register (GPIOx_IDR) (x=A..I)
Port output data register (GPIOx_ODR) (x=A..I)
14
Port bit set/reset register (GPIOx_BSRR) (x=A..G)
The purpose of the GPIOx_BSRR and GPIOx_BRR registers is to allow atomic read/modify accesses to any of the GPIOx_ODR registers. In this way, there is no risk of an IRQ occurring between the read and the modify access. Each I/O port bit is freely programmable, however the I/O port registers have to be accessed as 32-bit words, half-words or bytes.
15
Port bit reset register (GPIOx_BRR) (x=A..G)
mbed-os/dirvers/DigitalOut.h [gpio_write] -> mbed-os/targets/TARGET_STM/gpio_object.h [static function gpio_write] -> obj->reg_set ili obj->reg_reset
16
Port configuration lock register (GPIOx_LCKR) (x=A..G)
17
STM32L4x5 and STM32L4x6 advanced ARM®-based 32-bit MCUs
18
STM32CubeL4 komponente Sa adrese tnt.etf.rs/~ms1bmp/stm32cubel4.zip
(za F103RB tnt.etf.rs/~ms1bmp/stm32cubef1.zip) skinuti .zip fajl i raspakovati ga u folder E:/MS1BMP
19
STM32CubeL4 komponente STM32Cube includes STM32CubeMX, a graphical software configuration tool that allows the generation of C initialization code using graphical wizards. STM32Cube embedded software libraries, including: The HAL hardware abstraction layer, enabling portability between different STM32 devices via standardized API calls The Low-Layer (LL) APIs, a light-weight, optimized, expert oriented set of APIs designed for both performance and runtime efficiency A collection of Middleware components, like RTOS, USB library, file system, TCP/IP stack, Touch sensing library or Graphic Library (depending on the MCU series)
20
STM32CubeL4 arhitektura
21
Struktura foldera
22
Primeri – GPIO IOToggle
23
Projekat GPIO_IOToggle
Efikasnije pretraživanje i orjentacija se mogu postići dodavanjem shortcut-ova za pojedine naredbe: Edit->Configuration->Shortcut Keys-> Go to Definition Navigate Backwards Navigate Forwards Comment Uncomment ovo je super pitanje, traziti im da se snadju i pogledaju. Tu treba i reći da im za prolazak kroz fajlove i definicije znacajno olaksavaju zivot shortcut-ovi. Edit-Configuration-Shortcut Keys Onda oni mogu sami da postave za Edit:Advanced:Go to Definition of the current word, za Edit: Navigate Backwards, Edit: Navigate Forwards, za Comment, Uncomment i tako dalje. Neko vreme da se igraju i da gledaju kako radi, onda da builduju i da fleshuju plocicu i da mozda udju u debug, da gledaju vrednosti registara. Autos,Watch1 i tako dalje. Gde se nalazi definicija funkcije HAL_GPIO_TogglePin ()? Kojim registrima se pristupa? HAL_Delay() funkcija imlementira čekanje. Na koji način?
24
STM CUBE CMSIS Struktura projekta
Osnovni konfiguracioni heder fajl za odabranu familiju mikrokontrolera. U zavisnosti od USE_HAL_DRIVER obezbeđuje korišćenje HAL API-ja, ili zahteva direktan pristup registrima periferija u kodu. Startup fajl – definiše ga proizvođač kompajlera SystemInit() startup_stm32l476xx.s main.c BSP – board support package stm32l4xx.h stm32l4xx_nucleo.h main.h USE_HAL_DRIVER stm32l4xx_nucleo.c stm32l476xx.h Cortex-M4 prekidi i izuzeci stm32l4xx_hal.h stm32l4xx_it.c system_stm32l4xx.h system_stm32l4xx.c stm32l4xx_it.h core_cm4.h core_cm4.c Peripheral header file Ovaj fajl prilagodjava korisnik stm32l4xx_hal_conf.h startup_stm32l476xx.s: - Set the initial SP ;* Set the initial PC == Reset_Handler ;* Set the vector table entries with the exceptions ISR address ;* Branches to __main in the C library (which eventually ;* calls main()). main.c has #include main.h main.h has #include stm32l4xx_hal.h and #include stm32l4xx_nucleo.h stm32l4xx_hal.h - This file contains all the functions prototypes for the HAL module driver. HAL_Init() function is called at the beginning of program after reset and before * the clock configuration. The common HAL driver contains a set of generic and common APIs that can be used by the PPP peripheral drivers and the user to start using the HAL. [..] The HAL contains two APIs' categories: (+) Common HAL APIs (+) Services HAL APIs stm32l4xx_hal.h includes stm32l4_hal_conf.h which is the HAL configuration file. stm32l4xx_hal_conf.h This is the list of modules to be used in the HAL driver, ones defined include adequate stm32l4xx_hal_PPP.h and .c files. One of PPP files is cortex which sets up NVIC, SysTick and MPU stm32l4xx_nucleo.h defines specific nucleo peripherals: This file contains definitions for: * LEDs and push-button available on STM32L4XX-Nucleo Kit * from STMicroelectronics * LCD, joystick and microSD available on Adafruit 1.8" TFT LCD * shield (reference ID 802) stm32l4_xx.h - The file is the unique include file that the application programmer * is using in the C source code, usually in main.c. This file contains: * Configuration section that allows to select: * The STM32L4xx device used in the target application * To use or not the peripheral’s drivers in application code(i.e. * code will be based on direct access to peripheral’s registers * rather than drivers API), this option is controlled by * "#define USE_HAL_DRIVER" stm32l476xx.h * This file contains: * Data structures and the address mapping for all peripherals * Peripheral's registers declarations and bits definition * Macros to access peripheral’s registers hardware system_stm32l4xx.c This file provides two functions and one global variable to be called from * user application: * SystemInit(): This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32l4xx.s" file. * * SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * After each device reset the MSI (4 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32l4xx.s" file, to * configure the system clock before to branch to main program. stm32l4xx_hal_cortex.h stm32l4xx_hal_PPP.h stm32l4xx_hal_PPP.c Low-level & API funkcije koje čine biblioteku periferijskih drajvera. PPP = {pwr, gpio, rcc, tim, uart, spi, …} stm32l4xx_hal_cortex.c stm32l4xx_hal_gpio.c NVIC, SysTick and MPU drivers
25
Fajlovi koje menja korisnik
Osnovni konfiguracioni heder fajl za odabranu familiju mikrokontrolera. U zavisnosti od USE_HAL_DRIVER obezbeđuje korišćenje HAL API-ja, ili zahteva direktan pristup registrima periferija u kodu. Startup fajl – definiše ga proizvođač kompajlera SystemInit() main.c startup_stm32l476xx.s main.c BSP – board support package stm32l4xx.h stm32l4xx_nucleo.h main.h stm32l4xx_it.c stm32l4xx_nucleo.c stm32l476xx.h Cortex-M4 prekidi i izuzeci stm32l4xx_hal.h stm32l4xx_it.c system_stm32l4xx.h system_stm32l4xx.c stm32l4xx_it.h stm32l4xx_it.h stm32l4xx_hal_conf.h core_cm4.h core_cm4.c Peripheral header file Ovaj fajl prilagodjava korisnik stm32l4xx_hal_conf.h startup_stm32l476xx.s: - Set the initial SP ;* Set the initial PC == Reset_Handler ;* Set the vector table entries with the exceptions ISR address ;* Branches to __main in the C library (which eventually ;* calls main()). main.c has #include main.h main.h has #include stm32l4xx_hal.h and #include stm32l4xx_nucleo.h stm32l4xx_hal.h - This file contains all the functions prototypes for the HAL module driver. HAL_Init() function is called at the beginning of program after reset and before * the clock configuration. The common HAL driver contains a set of generic and common APIs that can be used by the PPP peripheral drivers and the user to start using the HAL. [..] The HAL contains two APIs' categories: (+) Common HAL APIs (+) Services HAL APIs stm32l4xx_hal.h includes stm32l4_hal_conf.h which is the HAL configuration file. stm32l4xx_hal_conf.h This is the list of modules to be used in the HAL driver, ones defined include adequate stm32l4xx_hal_PPP.h and .c files. One of PPP files is cortex which sets up NVIC, SysTick and MPU stm32l4xx_nucleo.h defines specific nucleo peripherals: This file contains definitions for: * LEDs and push-button available on STM32L4XX-Nucleo Kit * from STMicroelectronics * LCD, joystick and microSD available on Adafruit 1.8" TFT LCD * shield (reference ID 802) stm32l4_xx.h - The file is the unique include file that the application programmer * is using in the C source code, usually in main.c. This file contains: * Configuration section that allows to select: * The STM32L4xx device used in the target application * To use or not the peripheral’s drivers in application code(i.e. * code will be based on direct access to peripheral’s registers * rather than drivers API), this option is controlled by * "#define USE_HAL_DRIVER" stm32l476xx.h * This file contains: * Data structures and the address mapping for all peripherals * Peripheral's registers declarations and bits definition * Macros to access peripheral’s registers hardware system_stm32l4xx.c This file provides two functions and one global variable to be called from * user application: * SystemInit(): This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32l4xx.s" file. * * SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * After each device reset the MSI (4 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32l4xx.s" file, to * configure the system clock before to branch to main program. stm32l4xx_hal_cortex.h stm32l4xx_hal_PPP.h stm32l4xx_hal_PPP.c Low-level & API funkcije koje čine biblioteku periferijskih drajvera. PPP = {pwr, gpio, rcc, tim, uart, spi, …} stm32l4xx_hal_cortex.c stm32l4xx_hal_gpio.c NVIC, SysTick and MPU drivers
26
CMSIS - fajlovi Fajlovi koje definiše isključivo ARM:
core_cm4.c - Core Peripheral Access Layer Source File Ovaj fajl sadži implementaciju CMSIS intrinsic funkcija koje su za razliku od intrinsic funkcija u oviru C kompajlera nezavisne od vrste kompajlera. stm32l4xx_hal_cortex sadrži dummy f-je koji pozivaju one definisane u core_cm4.c fajlu – NVIC, MPU, SysTick core_cm4.h - Core Peripheral Access Layer Header File Ovaj fajl sadrži definicije registara periferija jezgra i funkcije za pristup tim registrima, kao i deklaraciju intrinsic funkcija CMSIS layer Device Peripheral Access Layer čine sledeći fajlovi: system_stm32l4xx.c - Device Peripheral Access Layer Source File Ovaj fajl sadži definiciju funkcije SystemInit koja vrši inicijalizaciju dela mikrokontrolera zaduženog za generisanje klok signala i koja se poziva u okviru startup koda system_stm32l4xx.h - Device Peripheral Access Layer Header File Ovaj fajl sadži deklaraciju funkcije SystemInit stm32l4xx.h Device Peripheral Access Layer Header File Ovaj fajl sadrži definiciju registara periferija mikrokontrolera kao i definiciju bitova u okviru svakog definisanog registra, bazne adrese registara i numeraciju vektora prekida primer SysTick_Config funkcija postoji i u core_cm4.c i u stm32l4xx_hal_cortex.c fajlu, iz hal_cortex je dummy koja samo poziva postojecu funkciju iz core_cmx fajla
27
HAL - fajlovi stm32l4xx_hal_conf.h Device Peripheral Access Layer Configuration Header File Ovaj fajl kontroliše korišćenje periferijskih biblioteka koje definiše isključivo proizvođač mikrokontrolera. stm32l4xx_hal_cortex.c stm32l4xx_hal_cortex.h Ovi fajlovi definišu specifičnosti kontrole prekida, sistemskog takta i reset-a. Formu propisuje ARM, ali ga neznatno redefiniše svaki proizvođač. stm32l4xx_hal_PPP.x Ovi fajlovi predstavljaju drajvere za odgovarajuće periferije i razlikuju se od proizvođača do proizvođača. Specifičnosti različitih razvojnih okruženja se definišu sledećim fajlom: startup_stm32l476xx.s - STM32L476xx Devices vector table for MDK-ARM toolchain. Ovaj fajl sadrži vektor tabelu i Reset_Handler ISR u kojoj se vrši setovanje SP, inicijalizacija dela mikrokontrolera zaduženog za generisanje klok signala i pozicioniranje PC na labelu __iar_program_start gde se nalazi kod za inicijalizaciju promenljivih, nakon čega se poziva main funkcija Napomena: Ovaj fajl se po pravilu razlikuje od okruženja do okruženja!
28
Fajlovi koje menja korisnik
stm32l4xx_hal_conf.h main_X.c stm32l4xx_It.c stm32l4xx_It.h
29
Opcije projekta Konretan mikrokontroler se definiše preko globalnog simbola što utiče na deklaracije u glavnom heder fajlu
30
Opcije projekta Korišćenje periferijskih biblioteka se kontroliše globalnim simbolom koji povezuje konfiguracione heder fajlove.
31
Periferijske biblioteke
U konfiguracionom fajlu se uključuju biblioteke vendor-specific periferija koje obezbeđuje proizvođač mikrokontrolera. U tim hederima se nalaze deklaracije registara, ali i prototipovi specifičnih funkcija za pristup konkretnoj periferiji. stm32Cubexxxxxxxx/Drivers/STM32L4xx_HAL_Driver/Src – c fajlovi koji treba da se inkluduju u projekat Korišćenje funkcija zahteva uključivanje i odgovarajućih source fajlova u projekat!
32
Tipičan main() Ovo je praktično inicijalizacija Cortex Periferija
33
Tipičan main() Definiše korisnik
34
Inicijalizacija periferija I
Pre konfigurisanja bilo koje periferije potrebno je dovesti joj takt korišćenjem odgovarajuće funkcije iz RCC drajvera: __HAL_RCC_PPP_CLK_ENABLE()
35
Inicijalizacija periferija II
Inicijalizacija periferija se uvek izvodi korišćenjem struktura karakterističnih za te periferije: PPP_InitStucture.memberX = valX; PPP_InitStructure.memberY = valY; HAL_PPP_Init(PPPx, &PPP_InitStructure);
36
Kako se togluje LED2 Podatak će biti 0x0020
Na dresu 0x dodaje offset za ODR koji iznosi 0x14 i dobija se adresa 0x
37
LED Toggle - BSRR Napisati funkciju GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) koja vrši izmenu stanja izlaza pina upisujući u BSR registar GPIO porta BSR i BR registar GPIO porta Testirati
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.