diff --git a/.metadata/.plugins/org.eclipse.cdt.core/task1.1727452765701.pdom b/.metadata/.plugins/org.eclipse.cdt.core/task1.1727452765701.pdom index b3202ec..eee0593 100644 Binary files a/.metadata/.plugins/org.eclipse.cdt.core/task1.1727452765701.pdom and b/.metadata/.plugins/org.eclipse.cdt.core/task1.1727452765701.pdom differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/37/c0ca9ea2a71b00111e1997f66d7c19f4 b/.metadata/.plugins/org.eclipse.core.resources/.history/37/c0ca9ea2a71b00111e1997f66d7c19f4 new file mode 100644 index 0000000..a4056ed --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/37/c0ca9ea2a71b00111e1997f66d7c19f4 @@ -0,0 +1,202 @@ +/* *************************************************************************************** + * Project: task1 - C:GPIO + * File: task1.c + * + * Language: C + * + * Hardware: STefi Light v1.1 + * Processor: STM32G431KBT6U + * + * Author: Manuel Lederhofer + * Datum: 10.09.2021 + * + * Version: 2.1 + * History: + * 10.09.2021 ML create project + * 09.03.2022 ML port from STM32F042K6T6 to STM32G431KBT6U + * 18.02.2025 TK changed projectname to "C: GPIO) + * + * Status: under development + * + * Description: + * Blinks the red LED of STefi Light, currently. + * This file contains the main routine and the initialization. + * + * Notes: + * - MCU speed at startup is 16 MHz + * + * Todo: + * - Change the example code to match the description and requirements + * of the requested application in the lab exercise guide. + * + ************************************************************************************** */ + +/* ------------------------------------ INCLUDES -------------------------------------- */ +#include "stm32g431xx.h" +#include "STefi-Light.h" + + +/* ------------------------------------ DEFINES --------------------------------------- */ +#define LOOPS_PER_MS 1244 // NOP-loops for delay() +#define WAITTIME 500 +#define FIRST_LED 0 +#define LAST_LED 3 +#define UP 1 +#define DOWN -1 + + +/* ------------------------------------ TYPE DEFINITIONS ------------------------------ */ +/* ------------------------------------ GLOBAL VARIABLES ------------------------------ */ +int state = 0; +/* ------------------------------------ PRIVATE VARIABLES ----------------------------- */ + + +/* ------------------------------------ PROTOTYPES ------------------------------------ */ +static void GPIO_init(void); +static void delay(const uint16_t ms); +static void blink(const unint numLED); + + +/* ------------------------------------ M A I N --------------------------------------- */ +int main(void) +{ + /* --- initialization --- */ + __disable_irq(); // disable interrupts globally + + GPIO_init(); + + __enable_irq(); // enable interrupts globally + + + /* --- one time tasks --- */ + + + /* --- infinite processing loop --- */ + while (1) + { + /* ... add your code to implement the lab assignment ... */ + int direction; + int i = 0; + while(1){ + if(i == FIRST_LED){ + direction = UP; + } + else if(i == LAST_LED){ + direction = DOWN; + } + blink(i); + if(direction == UP){ + i++; + } + else if(direction == DOWN){ + i--; + } + } + + + + switch (state) { + case 0: + GPIOA->ODR &= ~(1 << 0); // LED0 on + GPIOA->ODR &= ~(1 << 1); + GPIOA->ODR &= ~(1 << 2); + GPIOA->ODR &= ~(1 << 3); + + state++; + break; + case 1: + delay(WAITTIME); // wait + state++; + break; + case 2: + GPIOA->ODR |= (1 << 0); // LED0 off + GPIOA->ODR |= (1 << 1); + GPIOA->ODR |= (1 << 2); + GPIOA->ODR |= (1 << 3); + delay(WAITTIME); // wait + state = 0; + break; + default: + break; + } + } + + return 1; +} + + +/* ------------------------------------ GLOBAL FUNCTIONS ------------------------------ */ + + +/* ------------------------------------ PRIVATE FUNCTIONS ----------------------------- */ + +/* ------------------------------------------------------------------------------------ *\ + * method: static void GPIO_init(void) + * + * Initializes GPIOs on STefi Light for pins with peripherals attached. + * + * requires: - nothing - + * parameters: - none - + * returns: - nothing - +\* ------------------------------------------------------------------------------------ */ +static void GPIO_init(void) +{ + /* enable port clocks */ + RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN; // LEDs: A + + + /* --- LEDs --- */ + GPIOA->ODR |= MASK_LED_ALL; + GPIOA->MODER &= ~(3 << 0); + GPIOA->MODER &= ~(3 << 2); + GPIOA->MODER &= ~(3 << 4); + GPIOA->MODER &= ~(3 << 6); + GPIOA->MODER |= (1 << 0); // set LED pin to output + GPIOA->MODER |= (1 << 2); + GPIOA->MODER |= (1 << 4); + GPIOA->MODER |= (1 << 6); +} + + +/* ------------------------------------------------------------------------------------ *\ + * method: static void delay(const uint16_t ms) + * + * Realizes a millisecond delay by very bad busy-wait. + * + * requires: - nothing - + * parameters: ms - delay time in milliseconds + * returns: - nothing - +\* ------------------------------------------------------------------------------------ */ +static void delay(const uint16_t ms) +{ + for (uint16_t i = 0; i < ms; ++i) + { + for (uint16_t j = 0; j < LOOPS_PER_MS; ++j) + { + __asm("NOP"); + } + } +} + +static void blink(const uint numLED) +{ + switch (state) { + case 0: + GPIOA->ODR &= ~(1 << numLED); // LEDX on + state++; + break; + case 1: + delay(WAITTIME); // wait + state++; + break; + case 2: + GPIOA->ODR |= (1 << numLED); // LEDX off + delay(WAITTIME); // wait + state = 0; + break; + default: + break; +} + + +/* ************************************ E O F ***************************************** */ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6/506794a2a31b00111e1997f66d7c19f4 b/.metadata/.plugins/org.eclipse.core.resources/.history/6/506794a2a31b00111e1997f66d7c19f4 new file mode 100644 index 0000000..7e3d2e2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6/506794a2a31b00111e1997f66d7c19f4 @@ -0,0 +1,158 @@ +/* *************************************************************************************** + * Project: task1 - C:GPIO + * File: task1.c + * + * Language: C + * + * Hardware: STefi Light v1.1 + * Processor: STM32G431KBT6U + * + * Author: Manuel Lederhofer + * Datum: 10.09.2021 + * + * Version: 2.1 + * History: + * 10.09.2021 ML create project + * 09.03.2022 ML port from STM32F042K6T6 to STM32G431KBT6U + * 18.02.2025 TK changed projectname to "C: GPIO) + * + * Status: under development + * + * Description: + * Blinks the red LED of STefi Light, currently. + * This file contains the main routine and the initialization. + * + * Notes: + * - MCU speed at startup is 16 MHz + * + * Todo: + * - Change the example code to match the description and requirements + * of the requested application in the lab exercise guide. + * + ************************************************************************************** */ + +/* ------------------------------------ INCLUDES -------------------------------------- */ +#include "stm32g431xx.h" +#include "STefi-Light.h" + + +/* ------------------------------------ DEFINES --------------------------------------- */ +#define LOOPS_PER_MS 1244 // NOP-loops for delay() +#define WAITTIME 500 + + +/* ------------------------------------ TYPE DEFINITIONS ------------------------------ */ +/* ------------------------------------ GLOBAL VARIABLES ------------------------------ */ +int state = 0; +/* ------------------------------------ PRIVATE VARIABLES ----------------------------- */ + + +/* ------------------------------------ PROTOTYPES ------------------------------------ */ +static void GPIO_init(void); +static void delay(const uint16_t ms); + + +/* ------------------------------------ M A I N --------------------------------------- */ +int main(void) +{ + /* --- initialization --- */ + __disable_irq(); // disable interrupts globally + + GPIO_init(); + + __enable_irq(); // enable interrupts globally + + + /* --- one time tasks --- */ + + + /* --- infinite processing loop --- */ + while (1) + { + /* ... add your code to implement the lab assignment ... */ + + switch (state) { + case 0: + GPIOA->ODR &= ~(1 << 0); // LED0 on + GPIOA->ODR &= ~(1 << 1); + GPIOA->ODR &= ~(1 << 2); + GPIOA->ODR &= ~(1 << 3); + + state++; + break; + case 1: + delay(WAITTIME); // wait + state++; + break; + case 2: + GPIOA->ODR |= (1 << 0); // LED0 off + GPIOA->ODR |= (1 << 1); + GPIOA->ODR |= (1 << 2); + GPIOA->ODR |= (1 << 3); + delay(WAITTIME); // wait + state = 0; + break; + default: + break; + } + } + + return 1; +} + + +/* ------------------------------------ GLOBAL FUNCTIONS ------------------------------ */ + + +/* ------------------------------------ PRIVATE FUNCTIONS ----------------------------- */ + +/* ------------------------------------------------------------------------------------ *\ + * method: static void GPIO_init(void) + * + * Initializes GPIOs on STefi Light for pins with peripherals attached. + * + * requires: - nothing - + * parameters: - none - + * returns: - nothing - +\* ------------------------------------------------------------------------------------ */ +static void GPIO_init(void) +{ + /* enable port clocks */ + RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN; // LEDs: A + + + /* --- LEDs --- */ + GPIOA->ODR |= MASK_LED_ALL; + GPIOA->MODER &= ~(3 << 0); + GPIOA->MODER &= ~(3 << 2); + GPIOA->MODER &= ~(3 << 4); + GPIOA->MODER &= ~(3 << 6); + GPIOA->MODER |= (1 << 0); // set LED pin to output + GPIOA->MODER |= (1 << 2); + GPIOA->MODER |= (1 << 4); + GPIOA->MODER |= (1 << 6); +} + + +/* ------------------------------------------------------------------------------------ *\ + * method: static void delay(const uint16_t ms) + * + * Realizes a millisecond delay by very bad busy-wait. + * + * requires: - nothing - + * parameters: ms - delay time in milliseconds + * returns: - nothing - +\* ------------------------------------------------------------------------------------ */ +static void delay(const uint16_t ms) +{ + for (uint16_t i = 0; i < ms; ++i) + { + for (uint16_t j = 0; j < LOOPS_PER_MS; ++j) + { + __asm("NOP"); + } + } +} + + +/* ************************************ E O F ***************************************** */ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/78/10112b68a61b00111e1997f66d7c19f4 b/.metadata/.plugins/org.eclipse.core.resources/.history/78/10112b68a61b00111e1997f66d7c19f4 new file mode 100644 index 0000000..e4c0cde --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/78/10112b68a61b00111e1997f66d7c19f4 @@ -0,0 +1,198 @@ +/* *************************************************************************************** + * Project: task1 - C:GPIO + * File: task1.c + * + * Language: C + * + * Hardware: STefi Light v1.1 + * Processor: STM32G431KBT6U + * + * Author: Manuel Lederhofer + * Datum: 10.09.2021 + * + * Version: 2.1 + * History: + * 10.09.2021 ML create project + * 09.03.2022 ML port from STM32F042K6T6 to STM32G431KBT6U + * 18.02.2025 TK changed projectname to "C: GPIO) + * + * Status: under development + * + * Description: + * Blinks the red LED of STefi Light, currently. + * This file contains the main routine and the initialization. + * + * Notes: + * - MCU speed at startup is 16 MHz + * + * Todo: + * - Change the example code to match the description and requirements + * of the requested application in the lab exercise guide. + * + ************************************************************************************** */ + +/* ------------------------------------ INCLUDES -------------------------------------- */ +#include "stm32g431xx.h" +#include "STefi-Light.h" + + +/* ------------------------------------ DEFINES --------------------------------------- */ +#define LOOPS_PER_MS 1244 // NOP-loops for delay() +#define WAITTIME 500 + + +/* ------------------------------------ TYPE DEFINITIONS ------------------------------ */ +/* ------------------------------------ GLOBAL VARIABLES ------------------------------ */ +int state = 0; +/* ------------------------------------ PRIVATE VARIABLES ----------------------------- */ + + +/* ------------------------------------ PROTOTYPES ------------------------------------ */ +static void GPIO_init(void); +static void delay(const uint16_t ms); +static void blink(const unint numLED); + + +/* ------------------------------------ M A I N --------------------------------------- */ +int main(void) +{ + /* --- initialization --- */ + __disable_irq(); // disable interrupts globally + + GPIO_init(); + + __enable_irq(); // enable interrupts globally + + + /* --- one time tasks --- */ + + + /* --- infinite processing loop --- */ + while (1) + { + /* ... add your code to implement the lab assignment ... */ + int direction; + while(1){ + int i; + if(i == 0){ + direction = 1; + } + else if(i == 4){ + direction = -1; + } + blink(1); + if(direction > 0){ + i++; + } + else if(direction < 0){ + i--; + } + } + + + + switch (state) { + case 0: + GPIOA->ODR &= ~(1 << 0); // LED0 on + GPIOA->ODR &= ~(1 << 1); + GPIOA->ODR &= ~(1 << 2); + GPIOA->ODR &= ~(1 << 3); + + state++; + break; + case 1: + delay(WAITTIME); // wait + state++; + break; + case 2: + GPIOA->ODR |= (1 << 0); // LED0 off + GPIOA->ODR |= (1 << 1); + GPIOA->ODR |= (1 << 2); + GPIOA->ODR |= (1 << 3); + delay(WAITTIME); // wait + state = 0; + break; + default: + break; + } + } + + return 1; +} + + +/* ------------------------------------ GLOBAL FUNCTIONS ------------------------------ */ + + +/* ------------------------------------ PRIVATE FUNCTIONS ----------------------------- */ + +/* ------------------------------------------------------------------------------------ *\ + * method: static void GPIO_init(void) + * + * Initializes GPIOs on STefi Light for pins with peripherals attached. + * + * requires: - nothing - + * parameters: - none - + * returns: - nothing - +\* ------------------------------------------------------------------------------------ */ +static void GPIO_init(void) +{ + /* enable port clocks */ + RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN; // LEDs: A + + + /* --- LEDs --- */ + GPIOA->ODR |= MASK_LED_ALL; + GPIOA->MODER &= ~(3 << 0); + GPIOA->MODER &= ~(3 << 2); + GPIOA->MODER &= ~(3 << 4); + GPIOA->MODER &= ~(3 << 6); + GPIOA->MODER |= (1 << 0); // set LED pin to output + GPIOA->MODER |= (1 << 2); + GPIOA->MODER |= (1 << 4); + GPIOA->MODER |= (1 << 6); +} + + +/* ------------------------------------------------------------------------------------ *\ + * method: static void delay(const uint16_t ms) + * + * Realizes a millisecond delay by very bad busy-wait. + * + * requires: - nothing - + * parameters: ms - delay time in milliseconds + * returns: - nothing - +\* ------------------------------------------------------------------------------------ */ +static void delay(const uint16_t ms) +{ + for (uint16_t i = 0; i < ms; ++i) + { + for (uint16_t j = 0; j < LOOPS_PER_MS; ++j) + { + __asm("NOP"); + } + } +} + +static void blink(const uint numLED) +{ + switch (state) { + case 0: + GPIOA->ODR &= ~(1 << numLED); // LED0 on + state++; + break; + case 1: + delay(WAITTIME); // wait + state++; + break; + case 2: + GPIOA->ODR |= (1 << numLED); // LED0 off + delay(WAITTIME); // wait + state = 0; + break; + default: + break; +} + + +/* ************************************ E O F ***************************************** */ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9a/00f5864da51b00111e1997f66d7c19f4 b/.metadata/.plugins/org.eclipse.core.resources/.history/9a/00f5864da51b00111e1997f66d7c19f4 new file mode 100644 index 0000000..ab469f2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9a/00f5864da51b00111e1997f66d7c19f4 @@ -0,0 +1,179 @@ +/* *************************************************************************************** + * Project: task1 - C:GPIO + * File: task1.c + * + * Language: C + * + * Hardware: STefi Light v1.1 + * Processor: STM32G431KBT6U + * + * Author: Manuel Lederhofer + * Datum: 10.09.2021 + * + * Version: 2.1 + * History: + * 10.09.2021 ML create project + * 09.03.2022 ML port from STM32F042K6T6 to STM32G431KBT6U + * 18.02.2025 TK changed projectname to "C: GPIO) + * + * Status: under development + * + * Description: + * Blinks the red LED of STefi Light, currently. + * This file contains the main routine and the initialization. + * + * Notes: + * - MCU speed at startup is 16 MHz + * + * Todo: + * - Change the example code to match the description and requirements + * of the requested application in the lab exercise guide. + * + ************************************************************************************** */ + +/* ------------------------------------ INCLUDES -------------------------------------- */ +#include "stm32g431xx.h" +#include "STefi-Light.h" + + +/* ------------------------------------ DEFINES --------------------------------------- */ +#define LOOPS_PER_MS 1244 // NOP-loops for delay() +#define WAITTIME 500 + + +/* ------------------------------------ TYPE DEFINITIONS ------------------------------ */ +/* ------------------------------------ GLOBAL VARIABLES ------------------------------ */ +int state = 0; +/* ------------------------------------ PRIVATE VARIABLES ----------------------------- */ + + +/* ------------------------------------ PROTOTYPES ------------------------------------ */ +static void GPIO_init(void); +static void delay(const uint16_t ms); +static void blink(const unint numLED); + + +/* ------------------------------------ M A I N --------------------------------------- */ +int main(void) +{ + /* --- initialization --- */ + __disable_irq(); // disable interrupts globally + + GPIO_init(); + + __enable_irq(); // enable interrupts globally + + + /* --- one time tasks --- */ + + + /* --- infinite processing loop --- */ + while (1) + { + /* ... add your code to implement the lab assignment ... */ + + switch (state) { + case 0: + GPIOA->ODR &= ~(1 << 0); // LED0 on + GPIOA->ODR &= ~(1 << 1); + GPIOA->ODR &= ~(1 << 2); + GPIOA->ODR &= ~(1 << 3); + + state++; + break; + case 1: + delay(WAITTIME); // wait + state++; + break; + case 2: + GPIOA->ODR |= (1 << 0); // LED0 off + GPIOA->ODR |= (1 << 1); + GPIOA->ODR |= (1 << 2); + GPIOA->ODR |= (1 << 3); + delay(WAITTIME); // wait + state = 0; + break; + default: + break; + } + } + + return 1; +} + + +/* ------------------------------------ GLOBAL FUNCTIONS ------------------------------ */ + + +/* ------------------------------------ PRIVATE FUNCTIONS ----------------------------- */ + +/* ------------------------------------------------------------------------------------ *\ + * method: static void GPIO_init(void) + * + * Initializes GPIOs on STefi Light for pins with peripherals attached. + * + * requires: - nothing - + * parameters: - none - + * returns: - nothing - +\* ------------------------------------------------------------------------------------ */ +static void GPIO_init(void) +{ + /* enable port clocks */ + RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN; // LEDs: A + + + /* --- LEDs --- */ + GPIOA->ODR |= MASK_LED_ALL; + GPIOA->MODER &= ~(3 << 0); + GPIOA->MODER &= ~(3 << 2); + GPIOA->MODER &= ~(3 << 4); + GPIOA->MODER &= ~(3 << 6); + GPIOA->MODER |= (1 << 0); // set LED pin to output + GPIOA->MODER |= (1 << 2); + GPIOA->MODER |= (1 << 4); + GPIOA->MODER |= (1 << 6); +} + + +/* ------------------------------------------------------------------------------------ *\ + * method: static void delay(const uint16_t ms) + * + * Realizes a millisecond delay by very bad busy-wait. + * + * requires: - nothing - + * parameters: ms - delay time in milliseconds + * returns: - nothing - +\* ------------------------------------------------------------------------------------ */ +static void delay(const uint16_t ms) +{ + for (uint16_t i = 0; i < ms; ++i) + { + for (uint16_t j = 0; j < LOOPS_PER_MS; ++j) + { + __asm("NOP"); + } + } +} + +static void blink(const uint numLED) +{ + switch (state) { + case 0: + GPIOA->ODR &= ~(1 << numLED); // LED0 on + state++; + break; + case 1: + delay(WAITTIME); // wait + state++; + break; + case 2: + GPIOA->ODR |= (1 << numLED); // LED0 off + delay(WAITTIME); // wait + state = 0; + break; + default: + break; +} + + +/* ************************************ E O F ***************************************** */ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/50da93c8a61b00111e1997f66d7c19f4 b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/50da93c8a61b00111e1997f66d7c19f4 new file mode 100644 index 0000000..8987db6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/50da93c8a61b00111e1997f66d7c19f4 @@ -0,0 +1,202 @@ +/* *************************************************************************************** + * Project: task1 - C:GPIO + * File: task1.c + * + * Language: C + * + * Hardware: STefi Light v1.1 + * Processor: STM32G431KBT6U + * + * Author: Manuel Lederhofer + * Datum: 10.09.2021 + * + * Version: 2.1 + * History: + * 10.09.2021 ML create project + * 09.03.2022 ML port from STM32F042K6T6 to STM32G431KBT6U + * 18.02.2025 TK changed projectname to "C: GPIO) + * + * Status: under development + * + * Description: + * Blinks the red LED of STefi Light, currently. + * This file contains the main routine and the initialization. + * + * Notes: + * - MCU speed at startup is 16 MHz + * + * Todo: + * - Change the example code to match the description and requirements + * of the requested application in the lab exercise guide. + * + ************************************************************************************** */ + +/* ------------------------------------ INCLUDES -------------------------------------- */ +#include "stm32g431xx.h" +#include "STefi-Light.h" + + +/* ------------------------------------ DEFINES --------------------------------------- */ +#define LOOPS_PER_MS 1244 // NOP-loops for delay() +#define WAITTIME 500 +#define FIRST_LED 0 +#define LAST_LED 3 +#define UP 1 +#define DOWN -1 + + +/* ------------------------------------ TYPE DEFINITIONS ------------------------------ */ +/* ------------------------------------ GLOBAL VARIABLES ------------------------------ */ +int state = 0; +/* ------------------------------------ PRIVATE VARIABLES ----------------------------- */ + + +/* ------------------------------------ PROTOTYPES ------------------------------------ */ +static void GPIO_init(void); +static void delay(const uint16_t ms); +static void blink(const unint numLED); + + +/* ------------------------------------ M A I N --------------------------------------- */ +int main(void) +{ + /* --- initialization --- */ + __disable_irq(); // disable interrupts globally + + GPIO_init(); + + __enable_irq(); // enable interrupts globally + + + /* --- one time tasks --- */ + + + /* --- infinite processing loop --- */ + while (1) + { + /* ... add your code to implement the lab assignment ... */ + int direction; + int i = 0; + while(1){ + if(i == FIRST_LED){ + direction = UP; + } + else if(i == LAST_LED){ + direction = DOWN; + } + blink(i); + if(direction == UP){ + i++; + } + else if(direction == DOWN){ + i--; + } + } + + + + switch (state) { + case 0: + GPIOA->ODR &= ~(1 << 0); // LED0 on + GPIOA->ODR &= ~(1 << 1); + GPIOA->ODR &= ~(1 << 2); + GPIOA->ODR &= ~(1 << 3); + + state++; + break; + case 1: + delay(WAITTIME); // wait + state++; + break; + case 2: + GPIOA->ODR |= (1 << 0); // LED0 off + GPIOA->ODR |= (1 << 1); + GPIOA->ODR |= (1 << 2); + GPIOA->ODR |= (1 << 3); + delay(WAITTIME); // wait + state = 0; + break; + default: + break; + } + } + + return 1; +} + + +/* ------------------------------------ GLOBAL FUNCTIONS ------------------------------ */ + + +/* ------------------------------------ PRIVATE FUNCTIONS ----------------------------- */ + +/* ------------------------------------------------------------------------------------ *\ + * method: static void GPIO_init(void) + * + * Initializes GPIOs on STefi Light for pins with peripherals attached. + * + * requires: - nothing - + * parameters: - none - + * returns: - nothing - +\* ------------------------------------------------------------------------------------ */ +static void GPIO_init(void) +{ + /* enable port clocks */ + RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN; // LEDs: A + + + /* --- LEDs --- */ + GPIOA->ODR |= MASK_LED_ALL; + GPIOA->MODER &= ~(3 << 0); + GPIOA->MODER &= ~(3 << 2); + GPIOA->MODER &= ~(3 << 4); + GPIOA->MODER &= ~(3 << 6); + GPIOA->MODER |= (1 << 0); // set LED pin to output + GPIOA->MODER |= (1 << 2); + GPIOA->MODER |= (1 << 4); + GPIOA->MODER |= (1 << 6); +} + + +/* ------------------------------------------------------------------------------------ *\ + * method: static void delay(const uint16_t ms) + * + * Realizes a millisecond delay by very bad busy-wait. + * + * requires: - nothing - + * parameters: ms - delay time in milliseconds + * returns: - nothing - +\* ------------------------------------------------------------------------------------ */ +static void delay(const uint16_t ms) +{ + for (uint16_t i = 0; i < ms; ++i) + { + for (uint16_t j = 0; j < LOOPS_PER_MS; ++j) + { + __asm("NOP"); + } + } +} + +static void blink(const uint numLED) +{ + switch (state) { + case 0: + GPIOA->ODR &= ~(1 << numLED); // LED0 on + state++; + break; + case 1: + delay(WAITTIME); // wait + state++; + break; + case 2: + GPIOA->ODR |= (1 << numLED); // LED0 off + delay(WAITTIME); // wait + state = 0; + break; + default: + break; +} + + +/* ************************************ E O F ***************************************** */ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e5/302d8a9fa61b00111e1997f66d7c19f4 b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/302d8a9fa61b00111e1997f66d7c19f4 new file mode 100644 index 0000000..acf8dc8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/302d8a9fa61b00111e1997f66d7c19f4 @@ -0,0 +1,200 @@ +/* *************************************************************************************** + * Project: task1 - C:GPIO + * File: task1.c + * + * Language: C + * + * Hardware: STefi Light v1.1 + * Processor: STM32G431KBT6U + * + * Author: Manuel Lederhofer + * Datum: 10.09.2021 + * + * Version: 2.1 + * History: + * 10.09.2021 ML create project + * 09.03.2022 ML port from STM32F042K6T6 to STM32G431KBT6U + * 18.02.2025 TK changed projectname to "C: GPIO) + * + * Status: under development + * + * Description: + * Blinks the red LED of STefi Light, currently. + * This file contains the main routine and the initialization. + * + * Notes: + * - MCU speed at startup is 16 MHz + * + * Todo: + * - Change the example code to match the description and requirements + * of the requested application in the lab exercise guide. + * + ************************************************************************************** */ + +/* ------------------------------------ INCLUDES -------------------------------------- */ +#include "stm32g431xx.h" +#include "STefi-Light.h" + + +/* ------------------------------------ DEFINES --------------------------------------- */ +#define LOOPS_PER_MS 1244 // NOP-loops for delay() +#define WAITTIME 500 +#define FIRST_LED 0 +#define LAST_LED 3 + + +/* ------------------------------------ TYPE DEFINITIONS ------------------------------ */ +/* ------------------------------------ GLOBAL VARIABLES ------------------------------ */ +int state = 0; +/* ------------------------------------ PRIVATE VARIABLES ----------------------------- */ + + +/* ------------------------------------ PROTOTYPES ------------------------------------ */ +static void GPIO_init(void); +static void delay(const uint16_t ms); +static void blink(const unint numLED); + + +/* ------------------------------------ M A I N --------------------------------------- */ +int main(void) +{ + /* --- initialization --- */ + __disable_irq(); // disable interrupts globally + + GPIO_init(); + + __enable_irq(); // enable interrupts globally + + + /* --- one time tasks --- */ + + + /* --- infinite processing loop --- */ + while (1) + { + /* ... add your code to implement the lab assignment ... */ + int direction; + int i = 0; + while(1){ + if(i == FIRST_LED){ + direction = 1; + } + else if(i == LAST_LED){ + direction = -1; + } + blink(i); + if(direction > 0){ + i++; + } + else if(direction < 0){ + i--; + } + } + + + + switch (state) { + case 0: + GPIOA->ODR &= ~(1 << 0); // LED0 on + GPIOA->ODR &= ~(1 << 1); + GPIOA->ODR &= ~(1 << 2); + GPIOA->ODR &= ~(1 << 3); + + state++; + break; + case 1: + delay(WAITTIME); // wait + state++; + break; + case 2: + GPIOA->ODR |= (1 << 0); // LED0 off + GPIOA->ODR |= (1 << 1); + GPIOA->ODR |= (1 << 2); + GPIOA->ODR |= (1 << 3); + delay(WAITTIME); // wait + state = 0; + break; + default: + break; + } + } + + return 1; +} + + +/* ------------------------------------ GLOBAL FUNCTIONS ------------------------------ */ + + +/* ------------------------------------ PRIVATE FUNCTIONS ----------------------------- */ + +/* ------------------------------------------------------------------------------------ *\ + * method: static void GPIO_init(void) + * + * Initializes GPIOs on STefi Light for pins with peripherals attached. + * + * requires: - nothing - + * parameters: - none - + * returns: - nothing - +\* ------------------------------------------------------------------------------------ */ +static void GPIO_init(void) +{ + /* enable port clocks */ + RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN; // LEDs: A + + + /* --- LEDs --- */ + GPIOA->ODR |= MASK_LED_ALL; + GPIOA->MODER &= ~(3 << 0); + GPIOA->MODER &= ~(3 << 2); + GPIOA->MODER &= ~(3 << 4); + GPIOA->MODER &= ~(3 << 6); + GPIOA->MODER |= (1 << 0); // set LED pin to output + GPIOA->MODER |= (1 << 2); + GPIOA->MODER |= (1 << 4); + GPIOA->MODER |= (1 << 6); +} + + +/* ------------------------------------------------------------------------------------ *\ + * method: static void delay(const uint16_t ms) + * + * Realizes a millisecond delay by very bad busy-wait. + * + * requires: - nothing - + * parameters: ms - delay time in milliseconds + * returns: - nothing - +\* ------------------------------------------------------------------------------------ */ +static void delay(const uint16_t ms) +{ + for (uint16_t i = 0; i < ms; ++i) + { + for (uint16_t j = 0; j < LOOPS_PER_MS; ++j) + { + __asm("NOP"); + } + } +} + +static void blink(const uint numLED) +{ + switch (state) { + case 0: + GPIOA->ODR &= ~(1 << numLED); // LED0 on + state++; + break; + case 1: + delay(WAITTIME); // wait + state++; + break; + case 2: + GPIOA->ODR |= (1 << numLED); // LED0 off + delay(WAITTIME); // wait + state = 0; + break; + default: + break; +} + + +/* ************************************ E O F ***************************************** */ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f7/007e02b9a81b00111e1997f66d7c19f4 b/.metadata/.plugins/org.eclipse.core.resources/.history/f7/007e02b9a81b00111e1997f66d7c19f4 new file mode 100644 index 0000000..d3cd1f5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f7/007e02b9a81b00111e1997f66d7c19f4 @@ -0,0 +1,205 @@ +/* *************************************************************************************** + * Project: task1 - C:GPIO + * File: task1.c + * + * Language: C + * + * Hardware: STefi Light v1.1 + * Processor: STM32G431KBT6U + * + * Author: Manuel Lederhofer + * Datum: 10.09.2021 + * + * Version: 2.1 + * History: + * 10.09.2021 ML create project + * 09.03.2022 ML port from STM32F042K6T6 to STM32G431KBT6U + * 18.02.2025 TK changed projectname to "C: GPIO) + * + * Status: under development + * + * Description: + * Blinks the red LED of STefi Light, currently. + * This file contains the main routine and the initialization. + * + * Notes: + * - MCU speed at startup is 16 MHz + * + * Todo: + * - Change the example code to match the description and requirements + * of the requested application in the lab exercise guide. + * + ************************************************************************************** */ + +/* ------------------------------------ INCLUDES -------------------------------------- */ +#include "stm32g431xx.h" +#include "STefi-Light.h" + + +/* ------------------------------------ DEFINES --------------------------------------- */ +#define LOOPS_PER_MS 1244 // NOP-loops for delay() +#define WAITTIME 500 +#define FIRST_LED 0 +#define LAST_LED 3 +#define UP 1 +#define DOWN -1 + + +/* ------------------------------------ TYPE DEFINITIONS ------------------------------ */ +/* ------------------------------------ GLOBAL VARIABLES ------------------------------ */ +int state = 0; +/* ------------------------------------ PRIVATE VARIABLES ----------------------------- */ + + +/* ------------------------------------ PROTOTYPES ------------------------------------ */ +static void GPIO_init(void); +static void delay(const uint16_t ms); +static void blink(const unint numLED); + + +/* ------------------------------------ M A I N --------------------------------------- */ +int main(void) +{ + /* --- initialization --- */ + __disable_irq(); // disable interrupts globally + + GPIO_init(); + + __enable_irq(); // enable interrupts globally + + + /* --- one time tasks --- */ + + + /* --- infinite processing loop --- */ + + while (1) + { + /* ... add your code to implement the lab assignment ... */ + int direction; + + while(1){ + if(i == FIRST_LED){ + direction = UP; + } + else if(i == LAST_LED){ + direction = DOWN; + } + + blink(i); //One full LED blink cylce + + if(direction == UP){ + i++; + } + else if(direction == DOWN){ + i--; + } + } + + + + switch (state) { + case 0: + GPIOA->ODR &= ~(1 << 0); // LED0 on + GPIOA->ODR &= ~(1 << 1); + GPIOA->ODR &= ~(1 << 2); + GPIOA->ODR &= ~(1 << 3); + + state++; + break; + case 1: + delay(WAITTIME); // wait + state++; + break; + case 2: + GPIOA->ODR |= (1 << 0); // LED0 off + GPIOA->ODR |= (1 << 1); + GPIOA->ODR |= (1 << 2); + GPIOA->ODR |= (1 << 3); + delay(WAITTIME); // wait + state = 0; + break; + default: + break; + } + } + + return 1; +} + + +/* ------------------------------------ GLOBAL FUNCTIONS ------------------------------ */ + + +/* ------------------------------------ PRIVATE FUNCTIONS ----------------------------- */ + +/* ------------------------------------------------------------------------------------ *\ + * method: static void GPIO_init(void) + * + * Initializes GPIOs on STefi Light for pins with peripherals attached. + * + * requires: - nothing - + * parameters: - none - + * returns: - nothing - +\* ------------------------------------------------------------------------------------ */ +static void GPIO_init(void) +{ + /* enable port clocks */ + RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN; // LEDs: A + int i = FIRST_LED; + + /* --- LEDs --- */ + GPIOA->ODR |= MASK_LED_ALL; + GPIOA->MODER &= ~(3 << 0); + GPIOA->MODER &= ~(3 << 2); + GPIOA->MODER &= ~(3 << 4); + GPIOA->MODER &= ~(3 << 6); + GPIOA->MODER |= (1 << 0); // set LED pin to output + GPIOA->MODER |= (1 << 2); + GPIOA->MODER |= (1 << 4); + GPIOA->MODER |= (1 << 6); +} + + +/* ------------------------------------------------------------------------------------ *\ + * method: static void delay(const uint16_t ms) + * + * Realizes a millisecond delay by very bad busy-wait. + * + * requires: - nothing - + * parameters: ms - delay time in milliseconds + * returns: - nothing - +\* ------------------------------------------------------------------------------------ */ +static void delay(const uint16_t ms) +{ + for (uint16_t i = 0; i < ms; ++i) + { + for (uint16_t j = 0; j < LOOPS_PER_MS; ++j) + { + __asm("NOP"); + } + } +} + +static void blink(const uint numLED) +{ + switch (state) { + case 0: + GPIOA->ODR &= ~(1 << numLED); // LEDX on + state++; + break; + case 1: + delay(WAITTIME); // wait + state++; + break; + case 2: + GPIOA->ODR |= (1 << numLED); // LEDX off + delay(WAITTIME); // wait + state = 0; + break; + default: + break; +} + + +/* ************************************ E O F ***************************************** */ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/task1/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/task1/.markers.snap index 6594120..9bd290e 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/task1/.markers.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/task1/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/task1/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/task1/.syncinfo.snap index 91d6c54..414a6b3 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/task1/.syncinfo.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/task1/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/task2/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/task2/.markers.snap index 91d6c54..414a6b3 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/task2/.markers.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/task2/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/task2/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/task2/.syncinfo.snap index 91d6c54..414a6b3 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/task2/.syncinfo.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/task2/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/task3/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/task3/.markers.snap index 91d6c54..414a6b3 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/task3/.markers.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/task3/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/task3/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/task3/.syncinfo.snap index 91d6c54..414a6b3 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/task3/.syncinfo.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/task3/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/task4/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/task4/.markers.snap index 91d6c54..414a6b3 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/task4/.markers.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/task4/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/task4/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/task4/.syncinfo.snap index 91d6c54..414a6b3 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/task4/.syncinfo.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/task4/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap index 91d6c54..414a6b3 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap and b/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/63.snap b/.metadata/.plugins/org.eclipse.core.resources/63.snap index 0be2b7b..afe7740 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/63.snap and b/.metadata/.plugins/org.eclipse.core.resources/63.snap differ diff --git a/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi b/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi index 0a1058f..36c481d 100644 --- a/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi +++ b/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi @@ -1,8 +1,8 @@ - + activeSchemeId:org.eclipse.ui.defaultAcceleratorConfiguration - + @@ -11,9 +11,9 @@ topLevel shellMaximized - - - + + + persp.actionSet:com.st.stm32cube.ide.mcu.informationcenter.actionSet3 persp.actionSet:org.eclipse.ui.cheatsheets.actionSet @@ -67,70 +67,70 @@ persp.viewSC:com.st.stm32cube.ide.mcu.buildanalyzer.view persp.viewSC:com.st.stm32cube.ide.mcu.stackanalyzer.stackanalyzer.view persp.viewSC:com.st.stm32cube.ide.mcu.sfrview - - - + + + View categoryTag:General - + View categoryTag:C/C++ - + View categoryTag:General - - - - - - + + + + + + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + General - + View categoryTag:C/C++ - + View categoryTag:C/C++ - + View categoryTag:General - - + + View categoryTag:General - + View categoryTag:General - + View categoryTag:Make @@ -138,7 +138,7 @@ - + persp.actionSet:com.st.stm32cube.ide.mcu.informationcenter.actionSet3 persp.actionSet:org.eclipse.ui.cheatsheets.actionSet @@ -192,121 +192,121 @@ persp.editorOnboardingCommand:Step Over$$$F6 persp.editorOnboardingCommand:Step Return$$$F7 persp.editorOnboardingCommand:Resume$$$F8 - - - + + + org.eclipse.e4.primaryNavigationStack - + View categoryTag:Debug - + View categoryTag:General - - + + View categoryTag:Debug - - - - + + + + org.eclipse.e4.secondaryNavigationStack - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + Debug noFocus - + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug @@ -315,76 +315,76 @@ - - + + View categoryTag:Help - + View categoryTag:General - + View categoryTag:Help - + View categoryTag:Help - + View categoryTag:General - + ViewMenu menuContribution:menu - + - + View categoryTag:Help - - + + org.eclipse.e4.primaryDataStack EditorStack active - + Editor removeOnHide org.eclipse.cdt.ui.editor.asm.AsmEditor - + Editor removeOnHide org.eclipse.cdt.ui.editor.CEditor - + Editor removeOnHide org.eclipse.cdt.ui.editor.CEditor - + Editor removeOnHide org.eclipse.cdt.ui.editor.CEditor - - + + Editor removeOnHide org.eclipse.cdt.ui.editor.CEditor @@ -392,2102 +392,2102 @@ - + View categoryTag:General - + ViewMenu menuContribution:menu - + - + View categoryTag:C/C++ - + View categoryTag:General - + View categoryTag:General - + ViewMenu menuContribution:menu - + - + View categoryTag:General - + ViewMenu menuContribution:menu - + - + View categoryTag:General - + ViewMenu menuContribution:menu - + - + View categoryTag:General - + ViewMenu menuContribution:menu - + - + View categoryTag:General - + ViewMenu menuContribution:menu - + - + View categoryTag:General - + View categoryTag:Make - + ViewMenu menuContribution:menu - + - + View categoryTag:C/C++ - + ViewMenu menuContribution:menu - + - + View categoryTag:C/C++ - + ViewMenu menuContribution:menu - + - + View categoryTag:Debug - + ViewMenu menuContribution:menu - + - + View categoryTag:Debug - + ViewMenu menuContribution:menu - + - + View categoryTag:General - + View categoryTag:Debug - + ViewMenu menuContribution:menu - + - + View categoryTag:Debug - + ViewMenu menuContribution:menu - + - + View categoryTag:Debug - + ViewMenu menuContribution:menu - + - + View categoryTag:General - + View categoryTag:Debug - + View categoryTag:Debug - + ViewMenu menuContribution:menu - + - + View categoryTag:Debug - + ViewMenu menuContribution:menu - + - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + ViewMenu menuContribution:menu - + - + View categoryTag:Debug - + View categoryTag:Debug - + ViewMenu menuContribution:menu - + - + View categoryTag:Debug activeOnClose - + ViewMenu menuContribution:menu - + - + View categoryTag:Debug - + ViewMenu menuContribution:menu - + - + View categoryTag:General - + ViewMenu menuContribution:menu - + - - + + toolbarSeparator - + - + Draggable - + - + toolbarSeparator - + - + Draggable - - + + - + toolbarSeparator - + - + Draggable - + Draggable - + Draggable - + Draggable - + toolbarSeparator - + - + Draggable - + - + Draggable - + toolbarSeparator - + - + toolbarSeparator - + - + Draggable - + stretch SHOW_RESTORE_MENU - + Draggable HIDEABLE SHOW_RESTORE_MENU - - + + stretch - + Draggable - + Draggable - - + + TrimStack Draggable - + TrimStack Draggable - + TrimStack Draggable - - + + TrimStack Draggable - + TrimStack Draggable - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + platform:gtk - + platform:gtk - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - + + + + + + + - - + + - - - - + + + + - - - - + + + + - - - - - + + + + + - - + + - - + + - - - - - - - - - - - + + + + + + + + + + + - - + + - - - - - - + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + type:user - + type:user - - + + - - - - - - - - - - + + + + + + + + + + - - - - - - - + + + + + + + - - - + + + - - - - + + + + - - - - - - + + + + + + - - - - - - - + + + + + + + - - - - + + + + - - - + + + - - + + - - - - - - + + + + + + - - - - + + + + - - + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Editor removeOnHide - + View categoryTag:Device Configuration Tool - + View categoryTag:C/C++ - + View categoryTag:SWV - + View categoryTag:SWV - + View categoryTag:SWV - + View categoryTag:SWV - + View categoryTag:SWV - + View categoryTag:SWV - + View categoryTag:Debug - + View categoryTag:FreeRTOS - + View categoryTag:FreeRTOS - + View categoryTag:FreeRTOS - + View categoryTag:FreeRTOS - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:C/C++ - + View categoryTag:ThreadX - + View categoryTag:ThreadX - + View categoryTag:ThreadX - + View categoryTag:ThreadX - + View categoryTag:ThreadX - + View categoryTag:ThreadX - + View categoryTag:ThreadX - + View categoryTag:ThreadX - + View categoryTag:C/C++ - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Make - + View categoryTag:C/C++ - + View categoryTag:C/C++ - + View categoryTag:C/C++ - + View categoryTag:C/C++ - + View categoryTag:C/C++ - + View categoryTag:General - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Debug - + View categoryTag:Help - + View categoryTag:Connections - + View categoryTag:General - + View categoryTag:Version Control (Team) - + View categoryTag:Version Control (Team) - + View categoryTag:General - + View categoryTag:General - + View categoryTag:Help - + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + View categoryTag:General - + View categoryTag:C/C++ - + View categoryTag:Debug - + View categoryTag:Other - - + + glue move_after:PerspectiveSpacer SHOW_RESTORE_MENU - + move_after:Spacer Glue HIDEABLE SHOW_RESTORE_MENU - + glue move_after:SearchField SHOW_RESTORE_MENU - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - + + + + - - - - - - - + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - + + + - - + + - - - - - + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/task1/Src/task1.c b/task1/Src/task1.c index 7e3d2e2..0e54182 100644 --- a/task1/Src/task1.c +++ b/task1/Src/task1.c @@ -39,6 +39,10 @@ /* ------------------------------------ DEFINES --------------------------------------- */ #define LOOPS_PER_MS 1244 // NOP-loops for delay() #define WAITTIME 500 +#define FIRST_LED 0 +#define LAST_LED 3 +#define UP 1 +#define DOWN -1 /* ------------------------------------ TYPE DEFINITIONS ------------------------------ */ @@ -50,6 +54,7 @@ int state = 0; /* ------------------------------------ PROTOTYPES ------------------------------------ */ static void GPIO_init(void); static void delay(const uint16_t ms); +static void blink(const unint numLED); /* ------------------------------------ M A I N --------------------------------------- */ @@ -67,9 +72,31 @@ int main(void) /* --- infinite processing loop --- */ + while (1) { /* ... add your code to implement the lab assignment ... */ + int direction; + + while(1){ + if(i == FIRST_LED){ + direction = UP; + } + else if(i == LAST_LED){ + direction = DOWN; + } + + blink(i); //One full LED blink cylce + + if(direction == UP){ + i++; + } + else if(direction == DOWN){ + i--; + } + } + + switch (state) { case 0: @@ -119,7 +146,7 @@ static void GPIO_init(void) { /* enable port clocks */ RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN; // LEDs: A - + int i = FIRST_LED; /* --- LEDs --- */ GPIOA->ODR |= MASK_LED_ALL; @@ -154,5 +181,25 @@ static void delay(const uint16_t ms) } } +static void blink(const uint numLED) +{ + switch (state) { + case 0: + GPIOA->ODR &= ~(1 << numLED); // LEDX on + state++; + break; + case 1: + delay(WAITTIME); // wait + state++; + break; + case 2: + GPIOA->ODR |= (1 << numLED); // LEDX off + delay(WAITTIME); // wait + state = default; + break; + default: + break; +} + /* ************************************ E O F ***************************************** */