Table of Contents

7 - Úvod do Nucleo STM32F446RE

* pro vyučující: 07

Procvičovaná témata

Úkoly na cvičení

Vývoj v prostředí mbed.org

Ve webovém vývojovém prostředí https://developer.mbed.org/platforms/ST-Nucleo-F446RE/ vytvořte aplikaci pro blikání LED a vyčitání stavu tlačítka.

#include "mbed.h"
 
DigitalOut myled(LED1);
 
int main() {
   float period = 0.3; // 300 ms
   while (1) {
      myled = !myled;
      wait(period);
   }
}

#include "mbed.h"
 
DigitalOut myled(LED1);
DigitalIn mybutton(USER_BUTTON); 
 
int main() {
   while (1) {
      if (mybutton == 0) {
         myled = 1;
      } else {
         myled = 0;
      }
   }
}

Křížová (cross) kompilace

Realizujte výše uvedené úlohy křížovou kompilací s využitím následujících bloků.

make

make burn

#include "stm32f4xx_hal.h"
 
/* method to delay by busy loop */
void ms_delay(int ms)
{
   while (ms-- > 0) {
      volatile int x=5971;
      while (x-- > 0)
         __asm("nop"); //no operation
   }
}
 
/* main function */
int main(void)
{         
  /* Enable GPIOA Clock (to be able to program the GPIO configuration registers) */
  /* RCC - real-time clock control, AHB1 - advanced high-performance bus 1, ENR - enable register */
  RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOAEN);
 
  /* GPIO_INIT pin PA5 - output, fast, pull-up */
  GPIOA->MODER   |= ((uint32_t) 0x00000001 << 10); 	//set port A pin 5 output; MODER - mode setup register
  GPIOA->OSPEEDR |= ((uint32_t) 0x00000002 << 10);		//set port A pin 5 output speed fast; OSPEEDR - output speed setup register
  GPIOA->PUPDR   |= ((uint32_t) 0x00000001 << 10); 	//set port A pin 5 pull-up; PUPDR - pull-up pull-down setup register   
 
  /* blinking led example */   
  while (1)
  {  
  	/* toggle LED - PA5; ODR - output data register */
	GPIOA->ODR ^= ((uint32_t) 0x00000001 << 5);
        /* wait in busy loop */
        ms_delay(50); 	
  }
}

#include "stm32f4xx_hal.h"
 
/* main function */
int main(void)
{         
  /* Enable GPIOA Clock (to be able to program the GPIO configuration registers) */
  /* RCC - real-time clock control, AHB1 - advanced high-performance bus 1, ENR - enable register */
  RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOAEN);
 
  /* GPIO_INIT pin PA5 - output, fast, pull-up */
  GPIOA->MODER   |= ((uint32_t) 0x00000001 << 10); 	//set port A pin 5 output; MODER - mode setup register
  GPIOA->OSPEEDR |= ((uint32_t) 0x00000002 << 10);		//set port A pin 5 output speed fast; OSPEEDR - output speed setup register
  GPIOA->PUPDR   |= ((uint32_t) 0x00000001 << 10); 	//set port A pin 5 pull-up; PUPDR - pull-up pull-down setup register   
 
  /* Enable GPIOC Clock (to be able to program the GPIO configuration registers) */
  RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOCEN);
 
  /* GPIO_INIT pin PC13 - input, pull-up */
  GPIOC->MODER  &= ~((uint32_t) 0x00000003 << 26);	//set port C pin 13 input; MODER - mode setup register
  GPIOA->PUPDR  |= ((uint32_t) 0x00000001 << 26); 	//set port C pin 13 pull-up; PUPDR - pull-up pull-down setup register   
 
  uint32_t btn = 0;
 
  /* Btn to led control */   
  while (1)
  {  
  	/* read the button - PC13; IDR - input data register  */	
  	btn = (GPIOC->IDR) & ((uint32_t) 0x00000001 << 13);	//masking bit 13
 
  	if (btn){
  		/* turn on LED - PA5; ODR - output data register */
	  	GPIOA->ODR |= ((uint32_t) 0x00000001 << 5);
  	} else {
  		/* turn off LED - PA5; ODR - output data register */
  		GPIOA->ODR &= ~((uint32_t) 0x00000001 << 5);
  	} 	
  }
}

Integrované vývojové prostředí

Další alterantivou vývoje pro Nucleo STM32F446RE je využití dostupného vývojového prostředí System Workbench, které je součástí OpenSTM32 vývojových nástrojů. V zásadě vývoj odpovídá křížové kompilaci, jen je nutné si ještě nakonfigurovat vývojové prostředí, které je modifikovanou verzí IDE Eclipse.

Další úkoly na cvičení

V další části cvičení pokračujte implementací domácího úkolu hw08.

Procvičování binárních výrazů