aboutsummaryrefslogtreecommitdiffstats
path: root/testex/STM32
diff options
context:
space:
mode:
authorRocco Marco Guglielmi <roccomarco.guglielmi@gmail.com>2018-03-11 16:46:12 +0000
committerRocco Marco Guglielmi <roccomarco.guglielmi@gmail.com>2018-03-11 16:46:12 +0000
commitc3e3f6d5cf648ce07e05c08add7002db34d9ef91 (patch)
treefe5e799b00a7eceee6a647bf2735c07212231193 /testex/STM32
parent502f971ea45ea334aff59f035a7aeb33d30eb7db (diff)
downloadChibiOS-c3e3f6d5cf648ce07e05c08add7002db34d9ef91.tar.gz
ChibiOS-c3e3f6d5cf648ce07e05c08add7002db34d9ef91.tar.bz2
ChibiOS-c3e3f6d5cf648ce07e05c08add7002db34d9ef91.zip
Updated LIS3MDL driver
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11705 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'testex/STM32')
-rw-r--r--testex/STM32/STM32F4xx/I2C-LIS3MLD/Makefile34
-rw-r--r--testex/STM32/STM32F4xx/I2C-LIS3MLD/debug/STM32F4xx-I2C-LIS3MDL (OpenOCD, Flash and Run).launch2
-rw-r--r--testex/STM32/STM32F4xx/I2C-LIS3MLD/main.c157
-rw-r--r--testex/STM32/STM32F4xx/I2C-LPS25H/readme.txt2
4 files changed, 54 insertions, 141 deletions
diff --git a/testex/STM32/STM32F4xx/I2C-LIS3MLD/Makefile b/testex/STM32/STM32F4xx/I2C-LIS3MLD/Makefile
index 227b708bd..16c7f7c57 100644
--- a/testex/STM32/STM32F4xx/I2C-LIS3MLD/Makefile
+++ b/testex/STM32/STM32F4xx/I2C-LIS3MLD/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/lis3mdl.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)/STM32F401xE.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) \
- $(LIS3MDLSRC) \
- $(STREAMSSRC) \
- $(SHELLSRC) \
+CSRC = $(ALLCSRC) \
+ $(TESTSRC) \
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) $(LIS3MDLINC) \
- $(STREAMSINC) $(SHELLINC)
+# List ASM source files here
+ASMSRC = $(ALLASMSRC)
+ASMXSRC = $(ALLXASMSRC)
+
+INCDIR = $(ALLINC) $(TESTINC)
#
# Project, sources and paths
@@ -200,8 +196,8 @@ CPPWARN = -Wall -Wextra -Wundef
#
# List all user C define here, like -D_DEBUG=1
-UDEFS = -DCHPRINTF_USE_FLOAT=1 -DSHELL_CMD_TEST_ENABLED=0 \
- -DLIS3MDL_USE_ADVANCED=0 -DLIS3MDL_SHARED_I2C=0
+UDEFS = -DCHPRINTF_USE_FLOAT=1 \
+ -LIS3MDL_COMP_USE_ADVANCED=0 -DLIS3MDL_SHARED_I2C=0
# Define ASM defines here
UADEFS =
diff --git a/testex/STM32/STM32F4xx/I2C-LIS3MLD/debug/STM32F4xx-I2C-LIS3MDL (OpenOCD, Flash and Run).launch b/testex/STM32/STM32F4xx/I2C-LIS3MLD/debug/STM32F4xx-I2C-LIS3MDL (OpenOCD, Flash and Run).launch
index b82cd6efd..44580bcc6 100644
--- a/testex/STM32/STM32F4xx/I2C-LIS3MLD/debug/STM32F4xx-I2C-LIS3MDL (OpenOCD, Flash and Run).launch
+++ b/testex/STM32/STM32F4xx/I2C-LIS3MLD/debug/STM32F4xx-I2C-LIS3MDL (OpenOCD, Flash and Run).launch
@@ -33,7 +33,7 @@
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
-<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;SR2-i2c-null-main-(format)&quot; val=&quot;2&quot;/&gt;&lt;content id=&quot;null-read_raw-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;sr-i2c_lld_serve_error_interrupt-(format)&quot; val=&quot;2&quot;/&gt;&lt;content id=&quot;i2c-null-main-(format)&quot; val=&quot;0&quot;/&gt;&lt;/contentList&gt;"/>
+<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;i2c-null-main-(format)&quot; val=&quot;0&quot;/&gt;&lt;content id=&quot;sr-i2c_lld_serve_error_interrupt-(format)&quot; val=&quot;2&quot;/&gt;&lt;content id=&quot;null-read_raw-(format)&quot; val=&quot;1&quot;/&gt;&lt;content id=&quot;SR2-i2c-null-main-(format)&quot; val=&quot;2&quot;/&gt;&lt;/contentList&gt;"/>
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;globalVariableList/&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList/&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>
diff --git a/testex/STM32/STM32F4xx/I2C-LIS3MLD/main.c b/testex/STM32/STM32F4xx/I2C-LIS3MLD/main.c
index 922003997..a80a8b0a5 100644
--- a/testex/STM32/STM32F4xx/I2C-LIS3MLD/main.c
+++ b/testex/STM32/STM32F4xx/I2C-LIS3MLD/main.c
@@ -16,12 +16,11 @@
#include "ch.h"
#include "hal.h"
-#include "string.h"
-#include "shell.h"
#include "chprintf.h"
-
#include "lis3mdl.h"
+#define cls(chp) chprintf(chp, "\033[2J\033[1;1H")
+
/*===========================================================================*/
/* LIS3MDL related. */
/*===========================================================================*/
@@ -29,10 +28,11 @@
/* LIS3MDL Driver: This object represent an LIS3MDL instance.*/
static LIS3MDLDriver LIS3MDLD1;
-static int32_t rawdata[LIS3MDL_NUMBER_OF_AXES];
-static float cookeddata[LIS3MDL_NUMBER_OF_AXES];
+static int32_t compraw[LIS3MDL_COMP_NUMBER_OF_AXES];
+
+static float compcooked[LIS3MDL_COMP_NUMBER_OF_AXES];
-static char axisID[LIS3MDL_NUMBER_OF_AXES] = {'X', 'Y', 'Z'};
+static char axisID[LIS3MDL_COMP_NUMBER_OF_AXES] = {'X', 'Y', 'Z'};
static uint32_t i;
static const I2CConfig i2ccfg = {
@@ -41,114 +41,29 @@ static const I2CConfig i2ccfg = {
FAST_DUTY_CYCLE_2,
};
-static LIS3MDLConfig LIS3MDLcfg = {
+static LIS3MDLConfig lis3mdlcfg = {
&I2CD1,
&i2ccfg,
+ LIS3MDL_SAD_VCC,
NULL,
NULL,
- LIS3MDL_SAD_VCC,
- LIS3MDL_FS_4GA,
- LIS3MDL_ODR_40HZ,
-#if LIS3MDL_USE_ADVANCED
- LIS3MDL_LP_ENABLED,
- LIS3MDL_MD_CONTINUOUS,
- LIS3MDL_OMXY_LOW_POWER,
- LIS3MDL_OMZ_LOW_POWER,
+ LIS3MDL_COMP_FS_4GA,
+ LIS3MDL_COMP_ODR_40HZ,
+#if LIS3MDL_COMP_USE_ADVANCED
+ LIS3MDL_COMP_LP_ENABLED,
+ LIS3MDL_COMP_MD_CONTINUOUS,
+ LIS3MDL_COMP_OMXY_LP,
+ LIS3MDL_COMP_OMZ_LP,
LIS3MDL_BDU_CONTINUOUS,
LIS3MDL_END_LITTLE
#endif
};
/*===========================================================================*/
-/* 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
- compassReadRaw(&LIS3MDLD1, rawdata);
- chprintf(chp, "LIS3MDL compass raw data...\r\n");
- for(i = 0; i < LIS3MDL_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
- compassReadCooked(&LIS3MDLD1, cookeddata);
- chprintf(chp, "LIS3MDL compass cooked data...\r\n");
- for(i = 0; i < LIS3MDL_NUMBER_OF_AXES; i++) {
- chprintf(chp, "%c-axis: %.3f Gauss\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 [4|8|12|16]\r\n");
- return;
- }
-#if CHPRINTF_USE_ANSI_CODE
- chprintf(chp, "\033[2J\033[1;1H");
-#endif
- if(!strcmp (argv[0], "4")) {
- compassSetFullScale(&LIS3MDLD1, LIS3MDL_FS_4GA);
- chprintf(chp, "LIS3MDL compass full scale set to 4 Gauss...\r\n");
- }
- else if(!strcmp (argv[0], "8")) {
- compassSetFullScale(&LIS3MDLD1, LIS3MDL_FS_8GA);
- chprintf(chp, "LIS3MDL compass full scale set to 8 Gauss...\r\n");
- }
- else if(!strcmp (argv[0], "12")) {
- compassSetFullScale(&LIS3MDLD1, LIS3MDL_FS_12GA);
- chprintf(chp, "LIS3MDL compass full scale set to 12 Gauss...\r\n");
- }
- else if(!strcmp (argv[0], "16")) {
- compassSetFullScale(&LIS3MDLD1, LIS3MDL_FS_16GA);
- chprintf(chp, "LIS3MDL compass full scale set to 16 Gauss...\r\n");
- }
- else {
- chprintf(chp, "Usage: fullscale [4|8|12|16]\r\n");
- return;
- }
-}
-
-static const ShellCommand commands[] = {
- {"read", cmd_read},
- {"fullscale", cmd_fullscale},
- {NULL, NULL}
-};
-
-static const ShellConfig shell_cfg1 = {
- (BaseSequentialStream *)&SD2,
- commands
-};
-
-/*===========================================================================*/
-/* Main code. */
+/* Generic code. */
/*===========================================================================*/
+static BaseSequentialStream* chp = (BaseSequentialStream*)&SD2;
/*
* LED blinker thread, times are in milliseconds.
*/
@@ -158,10 +73,8 @@ static THD_FUNCTION(Thread1, arg) {
(void)arg;
chRegSetThreadName("blinker");
while (true) {
- palClearLine(LINE_LED_GREEN);
- chThdSleepMilliseconds(250);
- palSetLine(LINE_LED_GREEN);
- chThdSleepMilliseconds(250);
+ palToggleLine(LINE_LED_GREEN);
+ chThdSleepMilliseconds(500);
}
}
@@ -180,35 +93,39 @@ int main(void) {
halInit();
chSysInit();
+ /* Configuring I2C SCK and I2C SDA related GPIOs .*/
palSetLineMode(LINE_ARD_D15, PAL_MODE_ALTERNATE(4) |
PAL_STM32_OSPEED_HIGHEST | PAL_STM32_OTYPE_OPENDRAIN);
palSetLineMode(LINE_ARD_D14, PAL_MODE_ALTERNATE(4) |
PAL_STM32_OSPEED_HIGHEST | PAL_STM32_OTYPE_OPENDRAIN);
- /*
- * Activates the serial driver 2 using the driver default configuration.
- */
+ /* Activates the serial driver 1 using the driver default configuration.*/
sdStart(&SD2, NULL);
-
/* Creates the blinker thread.*/
- chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1, NULL);
+ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/* LIS3MDL Object Initialization.*/
lis3mdlObjectInit(&LIS3MDLD1);
/* Activates the LIS3MDL driver.*/
- lis3mdlStart(&LIS3MDLD1, &LIS3MDLcfg);
+ lis3mdlStart(&LIS3MDLD1, &lis3mdlcfg);
- /* Shell manager initialization.*/
- shellInit();
+ /* Normal main() thread activity, printing MEMS data on the SD2. */
+ while (true) {
+ lis3mdlCompassReadRaw(&LIS3MDLD1, compraw);
+ chprintf(chp, "LIS3MDL Compass raw data...\r\n");
+ for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++) {
+ chprintf(chp, "%c-axis: %d\r\n", axisID[i], compraw[i]);
+ }
- while(TRUE) {
- thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- "shell", NORMALPRIO + 1,
- shellThread, (void *)&shell_cfg1);
- chThdWait(shelltp); /* Waiting termination. */
+ lis3mdlCompassReadCooked(&LIS3MDLD1, compcooked);
+ chprintf(chp, "LIS3MDL Compass cooked data...\r\n");
+ for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++) {
+ chprintf(chp, "%c-axis: %.3f\r\n", axisID[i], compcooked[i]);
+ }
+ chThdSleepMilliseconds(100);
+ cls(chp);
}
lis3mdlStop(&LIS3MDLD1);
- return 0;
}
diff --git a/testex/STM32/STM32F4xx/I2C-LPS25H/readme.txt b/testex/STM32/STM32F4xx/I2C-LPS25H/readme.txt
index 0bbfd4932..a7342717a 100644
--- a/testex/STM32/STM32F4xx/I2C-LPS25H/readme.txt
+++ b/testex/STM32/STM32F4xx/I2C-LPS25H/readme.txt
@@ -1,5 +1,5 @@
*****************************************************************************
-** ChibiOS/HAL + ChibiOS/EX - I2C + LPS25H demo for STM32L4xx. **
+** ChibiOS/HAL + ChibiOS/EX - I2C + LPS25H demo for STM32F4xx. **
*****************************************************************************
** TARGET **