diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2014-04-21 09:25:40 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2014-04-21 09:25:40 +0000 |
commit | 92f59d89f168c8e5aa01fee358e1e0d7b8a7aa72 (patch) | |
tree | 280f97fdc64d02521e0ccc6cd66a9f9d6e1bb0c9 /demos/ARMCM4-STM32F401C-DISCOVERY/main.c | |
parent | 3f72932d474ba60725ce8c4772f35645c8cea16d (diff) | |
download | ChibiOS-92f59d89f168c8e5aa01fee358e1e0d7b8a7aa72.tar.gz ChibiOS-92f59d89f168c8e5aa01fee358e1e0d7b8a7aa72.tar.bz2 ChibiOS-92f59d89f168c8e5aa01fee358e1e0d7b8a7aa72.zip |
Fixed STM32F401 support.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@6856 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'demos/ARMCM4-STM32F401C-DISCOVERY/main.c')
-rw-r--r-- | demos/ARMCM4-STM32F401C-DISCOVERY/main.c | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/demos/ARMCM4-STM32F401C-DISCOVERY/main.c b/demos/ARMCM4-STM32F401C-DISCOVERY/main.c new file mode 100644 index 000000000..f68d36aa6 --- /dev/null +++ b/demos/ARMCM4-STM32F401C-DISCOVERY/main.c @@ -0,0 +1,181 @@ +/*
+ ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include "ch.h"
+#include "hal.h"
+
+#include "chprintf.h"
+#include "shell.h"
+
+#include "usbcfg.h"
+
+/* Virtual serial port over USB.*/
+SerialUSBDriver SDU1;
+
+/*===========================================================================*/
+/* Command line related. */
+/*===========================================================================*/
+
+#define SHELL_WA_SIZE THD_WA_SIZE(2048)
+#define TEST_WA_SIZE THD_WA_SIZE(256)
+
+static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
+ size_t n, size;
+
+ (void)argv;
+ if (argc > 0) {
+ chprintf(chp, "Usage: mem\r\n");
+ return;
+ }
+ n = chHeapStatus(NULL, &size);
+ chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
+ chprintf(chp, "heap fragments : %u\r\n", n);
+ chprintf(chp, "heap free total : %u bytes\r\n", size);
+}
+
+static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
+ static const char *states[] = {THD_STATE_NAMES};
+ Thread *tp;
+
+ (void)argv;
+ if (argc > 0) {
+ chprintf(chp, "Usage: threads\r\n");
+ return;
+ }
+ chprintf(chp, " addr stack prio refs state time\r\n");
+ tp = chRegFirstThread();
+ do {
+ chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n",
+ (uint32_t)tp, (uint32_t)tp->p_ctx.r13,
+ (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
+ states[tp->p_state], (uint32_t)tp->p_time);
+ tp = chRegNextThread(tp);
+ } while (tp != NULL);
+}
+
+static const ShellCommand commands[] = {
+ {"mem", cmd_mem},
+ {"threads", cmd_threads},
+ {NULL, NULL}
+};
+
+static const ShellConfig shell_cfg1 = {
+ (BaseSequentialStream *)&SDU1,
+ commands
+};
+
+/*
+ * Blinker thread
+ */
+static WORKING_AREA(waThread1, 256);
+
+static msg_t Thread1(void *arg) {
+
+ (void)arg;
+ chRegSetThreadName("thread1");
+
+ while (TRUE) {
+ palSetPad(GPIOD, GPIOD_LED3);
+ chThdSleepMilliseconds(200);
+ palSetPad(GPIOD, GPIOD_LED4);
+ chThdSleepMilliseconds(200);
+ palSetPad(GPIOD, GPIOD_LED5);
+ chThdSleepMilliseconds(200);
+ palSetPad(GPIOD, GPIOD_LED6);
+ chThdSleepMilliseconds(200);
+
+ palClearPad(GPIOD, GPIOD_LED6);
+ chThdSleepMilliseconds(200);
+ palClearPad(GPIOD, GPIOD_LED5);
+ chThdSleepMilliseconds(200);
+ palClearPad(GPIOD, GPIOD_LED4);
+ chThdSleepMilliseconds(200);
+ palClearPad(GPIOD, GPIOD_LED3);
+ chThdSleepMilliseconds(200);
+ }
+
+ return RDY_OK;
+}
+
+/*===========================================================================*/
+/* Initialization and main thread. */
+/*===========================================================================*/
+
+/*
+ * Application entry point.
+ */
+int main(void) {
+ Thread *shelltp = NULL;
+
+ /*
+ * 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();
+
+ /*
+ * Shell manager initialization.
+ */
+ shellInit();
+
+ /*
+ * Initializes a serial-over-USB CDC driver.
+ */
+ sduObjectInit(&SDU1);
+ sduStart(&SDU1, &serusbcfg);
+
+ /*
+ * Activates the USB driver and then the USB bus pull-up on D+.
+ * Note, a delay is inserted in order to not have to disconnect the cable
+ * after a reset.
+ */
+ usbDisconnectBus(serusbcfg.usbp);
+ chThdSleepMilliseconds(1000);
+ usbStart(serusbcfg.usbp, &usbcfg);
+ usbConnectBus(serusbcfg.usbp);
+
+ /*
+ * Creates the example thread.
+ */
+ chThdCreateStatic(waThread1, sizeof(waThread1),
+ NORMALPRIO + 10, Thread1, NULL);
+
+ /*
+ * Normal main() thread activity, in this demo it just performs
+ * a shell respawn upon its termination.
+ */
+ while (TRUE) {
+ if (!shelltp) {
+ if (SDU1.config->usbp->state == USB_ACTIVE) {
+ /* Spawns a new shell.*/
+ shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
+ }
+ }
+ else {
+ /* If the previous shell exited.*/
+ if (chThdTerminated(shelltp)) {
+ /* Recovers memory of the previous shell.*/
+ chThdRelease(shelltp);
+ shelltp = NULL;
+ }
+ }
+ chThdSleepMilliseconds(500);
+ }
+}
|