Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

At this point, you should be familiar with the basics of our build system and flashed your first project. You should also be aware of ourĀ Git Workflow andĀ Coding Standards.

...

Code Block
languagecpp
titlemain.c
// Turns the LED on and sits forever
#include <stdbool.h>
#include "gpio.h"
#include "log.h"

int main(void) {
  LOG_DEBUG("Hello World!\n");

  // Init GPIO module
  gpio_init();

  // Set up PC9 as an output, default to output 0 (GND)
  GPIOAddressGpioAddress led = {
    .port = GPIO_PORT_CB,  //
    .pin = 95,             //
  };
  GPIOSettingsGpioSettings gpio_settings = {
    .direction = GPIO_DIR_OUT,  //
    .state = GPIO_STATE_LOWHIGH,    //
  };
  gpio_init_pin(&led, &gpio_settings);

  // Add infinite loop so we don't exit
  while (true) {
  }

  return 0;
}

...

Code Block
# Just make we're following the style guide :)
make format
make lint


# Build and flash to the DiscoveryController boardBoard
make program PROJECT=getting_started PROBE=stlink-v2

Great! You should see a solid LED on the Discovery boardController Board. This is pretty simple.

Blinking an LED - HAL

...

Code Block
languagecpp
titlemain.c
// Blink an LED
#include <stdbool.h>
#include "gpio.h"
#include "interrupt.h"
#include "log.h"
#include "soft_timer.h"
#include "wait.h"

#define BLINK_LED_TIMEOUT_SECS 1

// Timeout callback
static void prv_blink_timeout(SoftTimerIDSoftTimerId timer_id, void *context) {
  GPIOAddressGpioAddress *led = context;
  gpio_toggle_state(led);

  LOG_DEBUG("Toggling LED\n");

  // Schedule another timer - this creates a periodic timer
  soft_timer_start_seconds(BLINK_LED_TIMEOUT_SECS, prv_blink_timeout, led, NULL);
}

int main(void) {
  LOG_DEBUG("Hello World!\n");

  // Initialize our modules
  gpio_init();
  interrupt_init();
  soft_timer_init();

  // Set up the pin
  GPIOAddressGpioAddress led = {
    .port = GPIO_PORT_CB,  //
    .pin = 95,             //
  };
  GPIOSettingsGpioSettings gpio_settings = {
    .direction = GPIO_DIR_OUT,  //
    .state = GPIO_STATE_LOWHIGH,    //
  };
  gpio_init_pin(&led, &gpio_settings);

  // Begin a timer
  soft_timer_start_seconds(BLINK_LED_TIMEOUT_SECS, prv_blink_timeout, &led, NULL);

  // Infinite loop
  while (true) {
    // Wait for interrupts
    wait();
  }

  return 0;
}

...