#include "stm32f0xx.h" #define PINOUT_LED_1 3 #define PINOUT_LED_2 5 #define PINOUT_LED_3 4 #define PINOUT_LED_4 6 const unsigned short leds[] = {PINOUT_LED_1, PINOUT_LED_2, PINOUT_LED_3, PINOUT_LED_4}; /* * This function configures the I/O-ports that are used by the I/O-shield. It * uses register RCC_AHBENR to enable the clocks for the ports that are used, * register GPIOx_MODER to configure pins as input, analog or output and * GPIOx_PUPDR to configure pull-up and pull-down resistors. */ void shieldConfig() { // enable clock for I/O port D RCC->AHBENR |= RCC_AHBENR_GPIOBEN; GPIOB->MODER &= ~((0b11 << (PINOUT_LED_1 * 2)) |\ (0b11 << (PINOUT_LED_2 * 2)) |\ (0b11 << (PINOUT_LED_3 * 2)) |\ (0b11 << (PINOUT_LED_4 * 2))); GPIOB->MODER |= (0b01 << (PINOUT_LED_1 * 2)) |\ (0b01 << (PINOUT_LED_2 * 2)) |\ (0b01 << (PINOUT_LED_3 * 2)) |\ (0b01 << (PINOUT_LED_4 * 2)); } /* * This function drives led of the I/O-shield. should be the number * of the LED to drive (0, 1, 2 or 3) and should be an integer with value * 0 or 1 which indicates if the LED should be turned on (1) or off (0). */ void ledWrite(int num, int on) { GPIOB->ODR &= ~(1 << leds[num]); GPIOB->ODR |= (on << leds[num]); } /* * This function returns the status of the pushbutton of the I/O-shield. * Return value 1 indicates that the button is currently pressed and return * value 0 indicates that the button is currently not pressed. */ int buttonRead() { return 0; } void delay() { int i; for (i = 0; i < 50000; i++) { asm("nop"); } } int main() { shieldConfig(); // RCC->AHBENR |= RCC_AHBENR_GPIOAEN; // GPIOA->MODER &= ~(1 << (PINOUT_LED_1 * 2 + 1)); // GPIOA->MODER |= (1 << (PINOUT_LED_1 * 2)); // GPIOA_MODER &= ~(0 << (PINOUT_LED_1 * 2 + 1)); while (1) { for(int i = 0; i < 2 * 4; i++) { ledWrite(i % 4, i >= 4); delay(); } } }