aboutsummaryrefslogtreecommitdiffstats
path: root/testex
diff options
context:
space:
mode:
authorRocco Marco Guglielmi <roccomarco.guglielmi@gmail.com>2018-03-08 15:59:15 +0000
committerRocco Marco Guglielmi <roccomarco.guglielmi@gmail.com>2018-03-08 15:59:15 +0000
commit0c61d9bddf55dd5a70e74b53ef87fa7004b41509 (patch)
tree4a44eb0dffe8b25f8b70da0a52c4dcd7d7d0ccfd /testex
parentc02e7a5abc74eafc69e7a134bf90e0dda6069c96 (diff)
downloadChibiOS-0c61d9bddf55dd5a70e74b53ef87fa7004b41509.tar.gz
ChibiOS-0c61d9bddf55dd5a70e74b53ef87fa7004b41509.tar.bz2
ChibiOS-0c61d9bddf55dd5a70e74b53ef87fa7004b41509.zip
Updated STM32/STM32F4xx/SPI-L3GD20
git-svn-id: https://svn.code.sf.net/p/chibios/svn2/trunk@11645 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'testex')
-rw-r--r--testex/STM32/STM32F4xx/I2C-LSM303DLHC/Makefile2
-rw-r--r--testex/STM32/STM32F4xx/SPI-L3GD20/Makefile32
-rw-r--r--testex/STM32/STM32F4xx/SPI-L3GD20/main.c166
-rw-r--r--testex/STM32/STM32F4xx/SPI-L3GD20/readme.txt3
4 files changed, 45 insertions, 158 deletions
diff --git a/testex/STM32/STM32F4xx/I2C-LSM303DLHC/Makefile b/testex/STM32/STM32F4xx/I2C-LSM303DLHC/Makefile
index 363d8023c..dcebca5db 100644
--- a/testex/STM32/STM32F4xx/I2C-LSM303DLHC/Makefile
+++ b/testex/STM32/STM32F4xx/I2C-LSM303DLHC/Makefile
@@ -193,7 +193,7 @@ CPPWARN = -Wall -Wextra -Wundef
#
# List all user C define here, like -D_DEBUG=1
-UDEFS = -DCHPRINTF_USE_FLOAT=1 -DSHELL_CMD_TEST_ENABLED=0 \
+UDEFS = -DCHPRINTF_USE_FLOAT=1 \
-DLSM303DLHC_ACC_USE_ADVANCED=0 -DLSM303DLHC_COMP_USE_ADVANCED=0 \
-DLSM303DLHC_SHARED_I2C=0
# Define ASM defines here
diff --git a/testex/STM32/STM32F4xx/SPI-L3GD20/Makefile b/testex/STM32/STM32F4xx/SPI-L3GD20/Makefile
index 655a35ddb..9b50b7efa 100644
--- a/testex/STM32/STM32F4xx/SPI-L3GD20/Makefile
+++ b/testex/STM32/STM32F4xx/SPI-L3GD20/Makefile
@@ -87,6 +87,9 @@ PROJECT = ch
# Imported source files and paths
CHIBIOS = ../../../..
+
+# Licensing files.
+include $(CHIBIOS)/os/license/license.mk
# Startup files.
include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk
# HAL-OSAL files (optional).
@@ -97,31 +100,23 @@ include $(CHIBIOS)/os/hal/osal/rt/osal.mk
# RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
-# Other files (optional).
+# EX files (optional).
include $(CHIBIOS)/os/ex/ST/l3gd20.mk
+# Other files (optional).
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
-include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here
LDSCRIPT= $(STARTUPLD)/STM32F401xC.ld
# C sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
-CSRC = $(STARTUPSRC) \
- $(KERNSRC) \
- $(PORTSRC) \
- $(OSALSRC) \
- $(HALSRC) \
- $(PLATFORMSRC) \
- $(BOARDSRC) \
- $(L3GD20SRC) \
- $(STREAMSSRC) \
- $(SHELLSRC) \
+CSRC = $(ALLCSRC) \
+ $(TESTSRC) \
usbcfg.c main.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
-CPPSRC =
+CPPSRC = $(AllCPPSRC)
# C sources to be compiled in ARM mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
@@ -147,10 +142,11 @@ TCPPSRC =
ASMSRC =
ASMXSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
-INCDIR = $(CHIBIOS)/os/license \
- $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
- $(HALINC) $(PLATFORMINC) $(BOARDINC) $(L3GD20INC) \
- $(STREAMSINC) $(SHELLINC)
+# List ASM source files here
+ASMSRC = $(ALLASMSRC)
+ASMXSRC = $(ALLXASMSRC)
+
+INCDIR = $(ALLINC) $(TESTINC)
#
# Project, sources and paths
@@ -200,7 +196,7 @@ CPPWARN = -Wall -Wextra -Wundef
#
# List all user C define here, like -D_DEBUG=1
-UDEFS = -DCHPRINTF_USE_FLOAT=1 -DSHELL_CMD_TEST_ENABLED=0 \
+UDEFS = -DCHPRINTF_USE_FLOAT=1 \
-DL3GD20_USE_ADVANCED=0 -DL3GD20_SHARED_SPI=0
# Define ASM defines here
diff --git a/testex/STM32/STM32F4xx/SPI-L3GD20/main.c b/testex/STM32/STM32F4xx/SPI-L3GD20/main.c
index 2e41585f6..b95b356dc 100644
--- a/testex/STM32/STM32F4xx/SPI-L3GD20/main.c
+++ b/testex/STM32/STM32F4xx/SPI-L3GD20/main.c
@@ -18,12 +18,11 @@
#include "hal.h"
#include "usbcfg.h"
-#include "string.h"
-#include "shell.h"
#include "chprintf.h"
-
#include "l3gd20.h"
+#define cls(chp) chprintf(chp, "\033[2J\033[1;1H")
+
/*===========================================================================*/
/* L3GD20 related. */
/*===========================================================================*/
@@ -31,10 +30,10 @@
/* L3GD20 Driver: This object represent an L3GD20 instance.*/
static L3GD20Driver L3GD20D1;
-static int32_t rawdata[L3GD20_NUMBER_OF_AXES];
-static float cookeddata[L3GD20_NUMBER_OF_AXES];
+static int32_t gyroraw[L3GD20_GYRO_NUMBER_OF_AXES];
+static float gyrocooked[L3GD20_GYRO_NUMBER_OF_AXES];
-static char axisID[L3GD20_NUMBER_OF_AXES] = {'X', 'Y', 'Z'};
+static char axisID[L3GD20_GYRO_NUMBER_OF_AXES] = {'X', 'Y', 'Z'};
static uint32_t i;
static const SPIConfig spicfg = {
@@ -64,128 +63,10 @@ static L3GD20Config l3gd20cfg = {
};
/*===========================================================================*/
-/* Command line related. */
-/*===========================================================================*/
-
-/* Enable use of special ANSI escape sequences.*/
-#define CHPRINTF_USE_ANSI_CODE TRUE
-#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
-
-static void cmd_read(BaseSequentialStream *chp, int argc, char *argv[]) {
- (void)argv;
- if (argc != 1) {
- chprintf(chp, "Usage: read [raw|cooked]\r\n");
- return;
- }
-
- while (chnGetTimeout((BaseChannel *)chp, 150) == Q_TIMEOUT) {
- if (!strcmp (argv[0], "raw")) {
-#if CHPRINTF_USE_ANSI_CODE
- chprintf(chp, "\033[2J\033[1;1H");
-#endif
- gyroscopeReadRaw(&L3GD20D1, rawdata);
- chprintf(chp, "L3GD20 Gyroscope raw data...\r\n");
- for(i = 0; i < L3GD20_NUMBER_OF_AXES; i++) {
- chprintf(chp, "%c-axis: %d\r\n", axisID[i], rawdata[i]);
- }
- }
- else if (!strcmp (argv[0], "cooked")) {
-#if CHPRINTF_USE_ANSI_CODE
- chprintf(chp, "\033[2J\033[1;1H");
-#endif
- gyroscopeReadCooked(&L3GD20D1, cookeddata);
- chprintf(chp, "L3GD20 Gyroscope cooked data...\r\n");
- for(i = 0; i < L3GD20_NUMBER_OF_AXES; i++) {
- chprintf(chp, "%c-axis: %.4f DPS\r\n", axisID[i], cookeddata[i]);
- }
- }
- else {
- chprintf(chp, "Usage: read [raw|cooked]\r\n");
- return;
- }
- }
- chprintf(chp, "Stopped\r\n");
-}
-
-static void cmd_fullscale(BaseSequentialStream *chp, int argc, char *argv[]) {
- (void)argv;
- if (argc != 1) {
- chprintf(chp, "Usage: fullscale [250|500|2000]\r\n");
- return;
- }
-#if CHPRINTF_USE_ANSI_CODE
- chprintf(chp, "\033[2J\033[1;1H");
-#endif
- if(!strcmp (argv[0], "250")) {
- gyroscopeSetFullScale(&L3GD20D1, L3GD20_FS_250DPS);
- chprintf(chp, "L3GD20 Gyroscope full scale set to 250 dps...\r\n");
- }
- else if(!strcmp (argv[0], "500")) {
- gyroscopeSetFullScale(&L3GD20D1, L3GD20_FS_500DPS);
- chprintf(chp, "L3GD20 Gyroscope full scale set to 500 dps...\r\n");
- }
- else if(!strcmp (argv[0], "2000")) {
- gyroscopeSetFullScale(&L3GD20D1, L3GD20_FS_2000DPS);
- chprintf(chp, "L3GD20 Gyroscope full scale set to 2000 dps...\r\n");
- }
- else {
- chprintf(chp, "Usage: fullscale [250|500|2000]\r\n");
- return;
- }
-}
-
-static void cmd_bias(BaseSequentialStream *chp, int argc, char *argv[]) {
- (void)argv;
- if (argc != 1) {
- chprintf(chp, "Usage: bias [sample|reset]\r\n");
- return;
- }
- if(!strcmp (argv[0], "sample")) {
-#if CHPRINTF_USE_ANSI_CODE
- chprintf(chp, "\033[2J\033[1;1H");
-#endif
- chprintf(chp, "Please don't move the device while Green LED is on!\r\n");
- chprintf(chp, "Press a key to start...\r\n");
- while (chnGetTimeout((BaseChannel *)chp, 500) == Q_TIMEOUT)
- ;
- palSetLine(LINE_LED4);
-
- chThdSleepMilliseconds(1000);
- gyroscopeSampleBias(&L3GD20D1);
- palClearLine(LINE_LED4);
-
-
- chprintf(chp, "Procedure completed!\r\n");
- }
- else if(!strcmp (argv[0], "reset")) {
-#if CHPRINTF_USE_ANSI_CODE
- chprintf(chp, "\033[2J\033[1;1H");
-#endif
- gyroscopeResetBias(&L3GD20D1);
- chprintf(chp, "Bias correction removed!\r\n");
- }
- else {
- chprintf(chp, "Usage: bias [sample|reset]\r\n");
- return;
- }
-}
-
-static const ShellCommand commands[] = {
- {"read", cmd_read},
- {"fullscale", cmd_fullscale},
- {"bias", cmd_bias},
- {NULL, NULL}
-};
-
-static const ShellConfig shell_cfg1 = {
- (BaseSequentialStream *)&SDU1,
- commands
-};
-
-/*===========================================================================*/
/* Main code. */
/*===========================================================================*/
+static BaseSequentialStream* chp = (BaseSequentialStream*)&SDU1;
/*
* LED blinker thread, times are in milliseconds.
*/
@@ -237,24 +118,35 @@ int main(void) {
/* Creates the blinker thread.*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1, NULL);
- /* L3GD20 Object Initialization.*/
+ /*
+ * L3GD20 Object Initialization
+ */
l3gd20ObjectInit(&L3GD20D1);
- /* Activates the L3GD20 driver.*/
+ /*
+ * Activates the L3GD20 driver.
+ */
l3gd20Start(&L3GD20D1, &l3gd20cfg);
- /* Shell manager initialization.*/
- shellInit();
+ /*
+ * Normal main() thread activity, printing MEMS data on the serial over usb
+ * driver 1.
+ */
+ while (true) {
+ l3gd20GyroscopeReadRaw(&L3GD20D1, gyroraw);
+ chprintf(chp, "L3GD20 Gyroscope raw data...\r\n");
+ for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++) {
+ chprintf(chp, "%c-axis: %d\r\n", axisID[i], gyroraw[i]);
+ }
- while(TRUE) {
- if (SDU1.config->usbp->state == USB_ACTIVE) {
- thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- "shell", NORMALPRIO + 1,
- shellThread, (void *)&shell_cfg1);
- chThdWait(shelltp); /* Waiting termination. */
+ l3gd20GyroscopeReadCooked(&L3GD20D1, gyrocooked);
+ chprintf(chp, "L3GD20 Gyroscope cooked data...\r\n");
+ for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++) {
+ chprintf(chp, "%c-axis: %.3f\r\n", axisID[i], gyrocooked[i]);
}
- chThdSleepMilliseconds(1000);
+
+ chThdSleepMilliseconds(100);
+ cls(chp);
}
l3gd20Stop(&L3GD20D1);
- return 0;
}
diff --git a/testex/STM32/STM32F4xx/SPI-L3GD20/readme.txt b/testex/STM32/STM32F4xx/SPI-L3GD20/readme.txt
index 2dd9006e4..3dc487ee6 100644
--- a/testex/STM32/STM32F4xx/SPI-L3GD20/readme.txt
+++ b/testex/STM32/STM32F4xx/SPI-L3GD20/readme.txt
@@ -8,8 +8,7 @@ The demo runs on an STM32F401C Discovery board.
** The Demo **
-The demo uses the ChibiOS Shell in order to test L3GD20 APIs.
-Shell is used on the SDU1 BaseSequentialStream.
+The demo prints L3GD20 data on the SDU1 BaseSequentialStream.
** Build Procedure **