====== Labs ====== ==== 1. Getting started ==== - Download and install [[https://www.st.com/en/development-tools/stm32cubeide.html|STM32CubeIDE]] - Fill the [[https://docs.google.com/forms/d/e/1FAIpQLSf4dqEGd_PHnOraj1LvI-odU4sW33VFn28-S6Vg1KtlU7EpUA/viewform|questionnaire]] ==== 2. C crash course ==== - File created during the session (zipped): {{ :courses:be2m37mam:tutorials:main.zip |}} ==== 3. STM32F4 minimal example - blinky LED ==== - Create new project under STM32CubeIDE: File -> New -> STM32 Project -> write name of project, select Empty -> OK - Put content of this file into created (almost empty) main.c: {{ :courses:be2m37mam:tutorials:blink.zip |}} - Follow instructions to fulfill [[courses:be2m37mam:tasks:task01|T01 - Light snake]] ==== 4. Systick, interrupt and SWV ==== - Open project in the STM32CubeIDE {{ :courses:be2m37mam:tutorials:tutorial-04.zip |}} ==== 5. External interupts ==== #define setbit(reg, bit) ((reg) |= (1U << (bit))) #define clearbit(reg, bit) ((reg) &= (~(1U << (bit)))) #define togglebit(reg, bit) ((reg) ^= (1U << (bit))) #define getbit(reg, bit) ((reg & (1U << bit)) >> bit) void EXTI15_10_IRQHandler() { // change PR (pending interrupt) to 1, if is 0 setbit(EXTI->PR, 13); // change of system LED togglebit(GPIOA->ODR, 5); } void buttonConfig(void) { setbit(RCC->AHB1ENR, 2); // RCC->AHB1ENR |= 0x05; -- two GPIO's at once // activate pull-up setbit(GPIOC->PUPDR, 26); // System configuration controller clock enable, page 121 setbit(RCC->APB2ENR, 14); // mask setbit(EXTI->IMR, 13); // IRQ on falling / rising setbit(EXTI->FTSR, 13); // GPIOC 13 will be source of IRQ setbit(SYSCFG->EXTICR[3], 5); // enable IRQ NVIC_EnableIRQ(EXTI15_10_IRQn); // 40 ~ EXTI15_10_IRQn // the same ! setbit(NVIC->ISER[40/32], 40%32); } void ledConfig() { // minimal config setbit(RCC->AHB1ENR, 0); setbit(GPIOA->MODER, 10); } int main(void) { ledConfig(); buttonConfig(); while (1) { // boring stuff here } }