PRJ2: ESP2-UC workshop 1 Introductie 1
Hoe dit onderdeel in elkaar zit Tooling GPIO Leerdoelen vandaag Hoe dit onderdeel in elkaar zit Tooling GPIO 2
Overzicht semester Periode 3 en 4 EC’s Embedded Systems Project 2: sensoren en actuatoren (ESP2) Project 2 10 Projectopdracht Projectvaardigheden workshop 32-bit Microcontroller workshop Information Technology 2 Electrical Engineering Fundamentals 2 3
Literatuur Han Scholar: ET-V12-ES 4
Aanschaffen: STM32F0DISCOVERY discovery development kit Benodigde Materiaal Aanschaffen: STM32F0DISCOVERY discovery development kit Zie: www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF253215 ARLE = Applied Reseach Lab Engineering 5 5
praktische opdrachten Werkwijze workshops praktische opdrachten 6
Toetsing Productrapport 25 % Product 25 % Productpresentatie √ Printontwerp √ Professional Skills √ Integrale toets 50 % 7
Onderwerpen Installation and verification of the SDE & GPIO Voorjaarsvakantie Ontwikkelweek Architecture of the STM32F051x & USART Standard Peripheral Driver Library Timers/Counters & PWM ADC/DAC I2C DMA 8
ST32F4 Pebble Time Smartwatch http://www.eevblog.com/2015/07/01/eevblog-761-pebble-time-smartwatch-teardown/
Hoe dit onderdeel in elkaar zit Tooling GPIO Vandaag Hoe dit onderdeel in elkaar zit Tooling GPIO 10
Documents STM32F05xxx Reference Manual http://www.st.com/st-web- ui/static/active/en/resource/technical/document/ref erence_manual/DM00031936.pdf STM32F051R8 Datasheet http://www.st.com/web/catalog/mmc/FM141/SC116 9/SS1574/LN7/PF251901 11
MDK-ARM Microcontroller Development Kit Tools MDK-ARM Microcontroller Development Kit Download vanaf: www.keil.com/arm/mdk.asp Installeer 12
Dit start automatisch de ‘Pack Installer’ Tools Dit start automatisch de ‘Pack Installer’ Installeer ten minste Keil::STM32F0xx_DFP 13
Tools Installeer de ST-LINK/V2 drivers vanaf: http://www.st.com/web/catalog/tools/FM146/C L1984/SC724/SS1677/PF251168 14
Example project Download example ZIP file from Scholar Start μVision by double clicking the file blinky.uvprojx Build the project by pressing F7 or The Build Output should look like this: Connect the STM32F0-Discovery board to your PC/laptop. Program the microcontroller by pressing the load button or from the menu Flash -> Download
Example project Troubles during installation or running the blinky project? 1. See Scholar for additional information. 2. Ask your teacher.
Hoe dit onderdeel in elkaar zit Tooling GPIO Vandaag Hoe dit onderdeel in elkaar zit Tooling GPIO 17
General Purpose Input Output GPIO General Purpose Input Output GPIOx-IDR 16-bits simultaneous GPIOx-MODER input, output, alternate function or analog GPIOx-PUPDR Pull-up, Pull-down, disabled GPIOx-ODR 16-bits simultaneous GPIOx-OTYPER Push-pull, open-drain or disabled GPIOx-BSRR Individual Bit Set Reset
GPIO registers
GPIO registers
stm32f0xx.h typedef struct { __IO uint32_t MODER; /* port mode register */ __IO uint16_t OTYPER; /* port output type register */ uint16_t RESERVED0; __IO uint32_t OSPEEDR; /* port output speed register */ __IO uint32_t PUPDR; /* port pull-up/pull-down register */ __IO uint16_t IDR; /* port input data register */ uint16_t RESERVED1; __IO uint16_t ODR; /* port output data register */ uint16_t RESERVED2; __IO uint32_t BSRR; /* port bit set/reset registerBSRR */ __IO uint32_t LCKR; /* port configuration lock register */ __IO uint32_t AFR[2]; /* alternate function low register */ __IO uint16_t BRR; /* bit reset register */ uint16_t RESERVED3; } GPIO_TypeDef;
CMSIS Compliant ! Code – Register access //in stm32f0xx.h #define GPIOC ((GPIO_TypeDef *) GPIOC_BASE) //0x48000800 //in your code: GPIOC->ODR = 0x00000000; -> : “indirect selection operator” CMSIS Compliant !
Code - Set individual bits #define RCC_AHBENR_GPIOCEN ((uint32_t)0x00080000) //set individual bit: RCC->AHBENR |= RCC_AHBENR_GPIOCEN; Register Mask register |= mask; ≡ register = register | mask; Individual set: bitwise or Example: Register 0b00001111000011110000111100001111 Mask 0b00000000000010000000000000000000 ---------------------------------- OR
Code – Clear individual bits #define GPIO_OTYPER_OT_8 ((uint32_t)0x00000100) #define GPIO_OTYPER_OT_9 ((uint32_t)0x00000200) //clear individual bits: GPIOC->OTYPER &= ~(GPIO_OTYPER_OT_8 | GPIO_OTYPER_OT_9); Register Mask GPIO_OTYPER_OT_8 0b00000000000000000000000100000000 GPIO_OTYPER_OT_9 0b00000000000000000000001000000000 ---------------------------------- OR Mask 0b00000000000000000000001100000000 Individual clear: bitwise and with bitwise inverse Register 0b00001111000011110000111100001111 ~Mask 0b11111111111111111111110011111111 ---------------------------------- AND Register 0b00001111000011110000110000001111
Code – Toggle individual bits GPIOC->ODR ^= GPIO_ODR_0; Register Mask Individual toggle: bitwise xor Example: Register 0b00001111000011110000111100001111 Mask 0b00000000000000000000000000000001 ---------------------------------- XOR Register 0b00001111000011110000111100001110
GPIO example #include "stm32f0xx.h" void delay(const int d); int main(void) { RCC->AHBENR |= RCC_AHBENR_GPIOCEN; //GPIOC Periph clock enable GPIOC->MODER |= (GPIO_MODER_MODER8_0 | GPIO_MODER_MODER9_0); //PC8 and PC9 output GPIOC->OTYPER &= ~(GPIO_OTYPER_OT_8 | GPIO_OTYPER_OT_9); //Push pull mode selected GPIOC->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR8 | GPIO_OSPEEDER_OSPEEDR9); //maximum speed GPIOC->PUPDR &= ~(GPIO_PUPDR_PUPDR8 | GPIO_PUPDR_PUPDR9); //no pull-up or pull-down while(1) GPIOC->BSRR = GPIO_BSRR_BS_9; // Set PC9 GPIOC->BSRR = GPIO_BSRR_BR_8; // Set PC8 delay(SystemCoreClock/8); // delay 1 sec. GPIOC->BSRR = GPIO_BSRR_BR_9; // Reset PC9 GPIOC->BSRR = GPIO_BSRR_BS_8; // Reset PC8 }
Assignment 1 Make the blue LED blink with ~ 2 Hz while the green LED blinks with ~10 Hz.
Assignment 2 So far we have seen how to use outputs. In a similar way inputs can be used. Adapt the project blinky.uvprojx so that: when the blue USER Push button is not pressed, the blue LED blinks with a frequency of ~ 1 Hz. when the blue USER Push button is pressed, the blue LED blinks with a frequency of ~ 10 Hz. Tips: The features of the STM32F0DISCOVERY board are described in the User Manual UM1525, which can be found on the STM32F0DISCOVERY website. In paragraph 4.9 is described which I/O pin is connected to the blue USER Push button. Remember to also enable this I/O pin’s peripheral clock!
Assignment 3 Use a breadboard and connect eight LED’s to PC0 to PC7. Implement a LED chaser that changes direction when pressing the blue USER Push button.