main.c 1.9 KB
Newer Older
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
1 2
#include "ch.h"
#include "hal.h"
3 4
#include "board.h"

5 6 7
#include "./threads/status.h"
#include "./threads/display.h"
#include "./usb/usbcfg.h"
8

9
// Callback placeholders
10 11 12
#define usb_lld_connect_bus(usbp)
#define usb_lld_disconnect_bus(usbp)

Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Application entry point.
 */
int main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

28 29 30
  palSetPadMode(GPIOA, 11, PAL_MODE_ALTERNATE(14));
  palSetPadMode(GPIOA, 12, PAL_MODE_ALTERNATE(14));

31 32 33
  /*
   * Initializes USB serial interfaces
   */
34 35 36 37 38 39 40 41
  sduObjectInit(&SDU1);
  sduStart(&SDU1, &serusbcfg1);
  sduObjectInit(&SDU2);
  sduStart(&SDU2, &serusbcfg2);

  usbStart(serusbcfg1.usbp, &usbcfg);
  usbConnectBus(serusbcfg1.usbp);

Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
42 43 44 45 46 47
  /*
   * Activates the serial driver 3 using the driver default configuration.
   */
  sdStart(&SD3, NULL);

  /*
48
   * Configures GPIO
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
49
   */
50 51 52 53 54 55 56
  palSetLineMode(LINE_LED0, PAL_MODE_OUTPUT_PUSHPULL); // LED0 output
  palSetLineMode(LINE_LED1, PAL_MODE_OUTPUT_PUSHPULL); // LED1 output
  palSetLineMode(LINE_LED2, PAL_MODE_OUTPUT_PUSHPULL); // LED2 output
  palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(4)); // I2C1 SCL
  palSetPadMode(GPIOB, 7, PAL_MODE_ALTERNATE(4)); // I2C1 SDA
  palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(7)); // UART3
  palSetPadMode(GPIOB, 11, PAL_MODE_ALTERNATE(7)); // UART3
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
57

58 59 60 61 62
  /*
   * Starts running the threads
   */
  chThdCreateStatic(waStatus, sizeof(waStatus), NORMALPRIO, Status, NULL);
  chThdCreateStatic(waDisplay, sizeof(waDisplay), NORMALPRIO, Display, NULL);
63
  
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
64 65

  /*
66 67
   * Normal main() thread activity.
   * For now it just sleeps in a loop.
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
68 69 70 71 72
   */
  while (true) {
    chThdSleepMilliseconds(500);
  }
}