Konstantin Oblaukhov 10 лет назад
Родитель
Сommit
6710423f68

+ 4 - 3
cmake/Modules/FindChibiOS.cmake

@@ -3,13 +3,14 @@ IF(NOT CHIBIOS_ROOT)
     MESSAGE(STATUS "No CHIBIOS_ROOT specified, using default: ${CHIBIOS_ROOT}")
 ENDIF()
 
-IF((NOT ChibiOS_FIND_VERSION_MAJOR) OR (ChibiOS_FIND_VERSION_MAJOR EQUAL 2))
-  INCLUDE(ChibiOS2)
-ELSE()
+IF(ChibiOS_FIND_VERSION_MAJOR EQUAL 2)
+  MESSAGE(FATAL_ERROR "ChibiOS v2.x.x is not supported. Use older version of stm32-cmake")
+ELSEIF((NOT ChibiOS_FIND_VERSION_MAJOR) OR (ChibiOS_FIND_VERSION_MAJOR EQUAL 3))
   INCLUDE(ChibiOS3)
 ENDIF()
 
 LIST(REMOVE_DUPLICATES ChibiOS_INCLUDE_DIRS)
+LIST(REMOVE_DUPLICATES ChibiOS_SOURCES)
 
 INCLUDE(FindPackageHandleStandardArgs)
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(ChibiOS DEFAULT_MSG ChibiOS_SOURCES ChibiOS_INCLUDE_DIRS ChibiOS_LINKER_SCRIPT)

+ 3 - 1
stm32-chibios/CMakeLists.txt

@@ -3,7 +3,7 @@ PROJECT(stm32-chibios)
 CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
 ENABLE_LANGUAGE(ASM)
 
-FIND_PACKAGE(ChibiOS COMPONENTS kernel hal pal serial REQUIRED)
+FIND_PACKAGE(ChibiOS COMPONENTS nil hal pal serial REQUIRED)
 
 INCLUDE_DIRECTORIES(
     ${CMAKE_CURRENT_SOURCE_DIR}    
@@ -15,6 +15,8 @@ SET(PROJECT_SOURCES
     board.c
 )
 
+ADD_DEFINITIONS(-DCORTEX_USE_FPU=FALSE)
+
 SET(STM32_LINKER_SCRIPT ${ChibiOS_LINKER_SCRIPT})
 
 ADD_EXECUTABLE(${CMAKE_PROJECT_NAME} ${PROJECT_SOURCES} ${ChibiOS_SOURCES})

+ 0 - 1
stm32-chibios/board.c

@@ -1,4 +1,3 @@
-#include "ch.h"
 #include "hal.h"
 
 const PALConfig pal_default_config =

+ 0 - 172
stm32-chibios/chconf.h

@@ -1,172 +0,0 @@
-#ifndef _CHCONF_H_
-#define _CHCONF_H_
-
-#if !defined(CH_FREQUENCY)
-#define CH_FREQUENCY                    1000
-#endif
-
-#if !defined(CH_TIME_QUANTUM)
-#define CH_TIME_QUANTUM                 20
-#endif
-
-#if !defined(CH_MEMCORE_SIZE)
-#define CH_MEMCORE_SIZE                 0
-#endif
-
-#if !defined(CH_NO_IDLE_THREAD)
-#define CH_NO_IDLE_THREAD               FALSE
-#endif
-
-#if !defined(CH_OPTIMIZE_SPEED)
-#define CH_OPTIMIZE_SPEED               TRUE
-#endif
-
-#if !defined(CH_USE_REGISTRY)
-#define CH_USE_REGISTRY                 TRUE
-#endif
-
-#if !defined(CH_USE_WAITEXIT)
-#define CH_USE_WAITEXIT                 TRUE
-#endif
-
-#if !defined(CH_USE_SEMAPHORES)
-#define CH_USE_SEMAPHORES               TRUE
-#endif
-
-#if !defined(CH_USE_SEMAPHORES_PRIORITY)
-#define CH_USE_SEMAPHORES_PRIORITY      FALSE
-#endif
-
-#if !defined(CH_USE_SEMSW)
-#define CH_USE_SEMSW                    TRUE
-#endif
-
-#if !defined(CH_USE_MUTEXES)
-#define CH_USE_MUTEXES                  TRUE
-#endif
-
-#if !defined(CH_USE_CONDVARS)
-#define CH_USE_CONDVARS                 TRUE
-#endif
-
-
-#if !defined(CH_USE_CONDVARS_TIMEOUT)
-#define CH_USE_CONDVARS_TIMEOUT         TRUE
-#endif
-
-#if !defined(CH_USE_EVENTS)
-#define CH_USE_EVENTS                   TRUE
-#endif
-
-#if !defined(CH_USE_EVENTS_TIMEOUT)
-#define CH_USE_EVENTS_TIMEOUT           TRUE
-#endif
-
-#if !defined(CH_USE_MESSAGES)
-#define CH_USE_MESSAGES                 TRUE
-#endif
-
-#if !defined(CH_USE_MESSAGES_PRIORITY)
-#define CH_USE_MESSAGES_PRIORITY        FALSE
-#endif
-
-#if !defined(CH_USE_MAILBOXES)
-#define CH_USE_MAILBOXES                TRUE
-#endif
-
-#if !defined(CH_USE_QUEUES)
-#define CH_USE_QUEUES                   TRUE
-#endif
-
-#if !defined(CH_USE_MEMCORE)
-#define CH_USE_MEMCORE                  TRUE
-#endif
-
-#if !defined(CH_USE_HEAP)
-#define CH_USE_HEAP                     TRUE
-#endif
-
-#if !defined(CH_USE_MALLOC_HEAP)
-#define CH_USE_MALLOC_HEAP              FALSE
-#endif
-
-#if !defined(CH_USE_MEMPOOLS)
-#define CH_USE_MEMPOOLS                 TRUE
-#endif
-
-#if !defined(CH_USE_DYNAMIC)
-#define CH_USE_DYNAMIC                  TRUE
-#endif
-
-#if !defined(CH_DBG_SYSTEM_STATE_CHECK)
-#define CH_DBG_SYSTEM_STATE_CHECK       FALSE
-#endif
-
-#if !defined(CH_DBG_ENABLE_CHECKS)
-#define CH_DBG_ENABLE_CHECKS            FALSE
-#endif
-
-#if !defined(CH_DBG_ENABLE_ASSERTS)
-#define CH_DBG_ENABLE_ASSERTS           FALSE
-#endif
-
-#if !defined(CH_DBG_ENABLE_TRACE)
-#define CH_DBG_ENABLE_TRACE             FALSE
-#endif
-
-#if !defined(CH_DBG_ENABLE_STACK_CHECK)
-#define CH_DBG_ENABLE_STACK_CHECK       FALSE
-#endif
-
-#if !defined(CH_DBG_FILL_THREADS)
-#define CH_DBG_FILL_THREADS             FALSE
-#endif
-
-#if !defined(CH_DBG_THREADS_PROFILING)
-#define CH_DBG_THREADS_PROFILING        TRUE
-#endif
-
-#if !defined(THREAD_EXT_FIELDS)
-#define THREAD_EXT_FIELDS                                                   \
-  /* Add threads custom fields here.*/
-#endif
-
-#if !defined(THREAD_EXT_INIT_HOOK)
-#define THREAD_EXT_INIT_HOOK(tp) {                                          \
-  /* Add threads initialization code here.*/                                \
-}
-#endif
-
-#if !defined(THREAD_EXT_EXIT_HOOK)
-#define THREAD_EXT_EXIT_HOOK(tp) {                                          \
-  /* Add threads finalization code here.*/                                  \
-}
-#endif
-
-#if !defined(THREAD_CONTEXT_SWITCH_HOOK)
-#define THREAD_CONTEXT_SWITCH_HOOK(ntp, otp) {                              \
-  /* System halt code here.*/                                               \
-}
-#endif
-
-#if !defined(IDLE_LOOP_HOOK)
-#define IDLE_LOOP_HOOK() {                                                  \
-  /* Idle loop code here.*/                                                 \
-}
-#endif
-
-#if !defined(SYSTEM_TICK_EVENT_HOOK)
-#define SYSTEM_TICK_EVENT_HOOK() {                                          \
-  /* System tick event code here.*/                                         \
-}
-#endif
-
-#if !defined(SYSTEM_HALT_HOOK)
-#define SYSTEM_HALT_HOOK() {                                                \
-  /* System halt code here.*/                                               \
-}
-#endif
-
-#define CORTEX_USE_FPU                  FALSE
-
-#endif

+ 229 - 36
stm32-chibios/halconf.h

@@ -1,141 +1,334 @@
+/*
+    ChibiOS - Copyright (C) 2006..2015 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.
+*/
+
+/**
+ * @file    templates/halconf.h
+ * @brief   HAL configuration header.
+ * @details HAL configuration file, this file allows to enable or disable the
+ *          various device drivers from your application. You may also use
+ *          this file in order to override the device drivers default settings.
+ *
+ * @addtogroup HAL_CONF
+ * @{
+ */
+
 #ifndef _HALCONF_H_
 #define _HALCONF_H_
 
 #include "mcuconf.h"
 
-#if !defined(HAL_USE_TM)
-#define HAL_USE_TM                  FALSE
-#endif
-
-#if !defined(HAL_USE_PAL)
+/**
+ * @brief   Enables the PAL subsystem.
+ */
+#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)
 #define HAL_USE_PAL                 TRUE
 #endif
 
-#if !defined(HAL_USE_ADC)
+/**
+ * @brief   Enables the ADC subsystem.
+ */
+#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)
 #define HAL_USE_ADC                 FALSE
 #endif
 
-#if !defined(HAL_USE_CAN)
+/**
+ * @brief   Enables the CAN subsystem.
+ */
+#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
 #define HAL_USE_CAN                 FALSE
 #endif
 
-#if !defined(HAL_USE_EXT)
+/**
+ * @brief   Enables the DAC subsystem.
+ */
+#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__)
+#define HAL_USE_DAC                 FALSE
+#endif
+
+/**
+ * @brief   Enables the EXT subsystem.
+ */
+#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__)
 #define HAL_USE_EXT                 FALSE
 #endif
 
-#if !defined(HAL_USE_GPT)
+/**
+ * @brief   Enables the GPT subsystem.
+ */
+#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)
 #define HAL_USE_GPT                 FALSE
 #endif
 
-#if !defined(HAL_USE_I2C)
+/**
+ * @brief   Enables the I2C subsystem.
+ */
+#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
 #define HAL_USE_I2C                 FALSE
 #endif
 
-#if !defined(HAL_USE_ICU)
+/**
+ * @brief   Enables the I2S subsystem.
+ */
+#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__)
+#define HAL_USE_I2S                 FALSE
+#endif
+
+/**
+ * @brief   Enables the ICU subsystem.
+ */
+#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)
 #define HAL_USE_ICU                 FALSE
 #endif
 
-#if !defined(HAL_USE_MAC)
+/**
+ * @brief   Enables the MAC subsystem.
+ */
+#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__)
 #define HAL_USE_MAC                 FALSE
 #endif
 
-#if !defined(HAL_USE_MMC_SPI)
+/**
+ * @brief   Enables the MMC_SPI subsystem.
+ */
+#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__)
 #define HAL_USE_MMC_SPI             FALSE
 #endif
 
-#if !defined(HAL_USE_PWM)
+/**
+ * @brief   Enables the PWM subsystem.
+ */
+#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
 #define HAL_USE_PWM                 FALSE
 #endif
 
-#if !defined(HAL_USE_RTC)
+/**
+ * @brief   Enables the RTC subsystem.
+ */
+#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)
 #define HAL_USE_RTC                 FALSE
 #endif
 
-#if !defined(HAL_USE_SDC)
+/**
+ * @brief   Enables the SDC subsystem.
+ */
+#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__)
 #define HAL_USE_SDC                 FALSE
 #endif
 
-#if !defined(HAL_USE_SERIAL)
+/**
+ * @brief   Enables the SERIAL subsystem.
+ */
+#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
 #define HAL_USE_SERIAL              TRUE
 #endif
 
-#if !defined(HAL_USE_SERIAL_USB)
+/**
+ * @brief   Enables the SERIAL over USB subsystem.
+ */
+#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
 #define HAL_USE_SERIAL_USB          FALSE
 #endif
 
-#if !defined(HAL_USE_SPI)
+/**
+ * @brief   Enables the SPI subsystem.
+ */
+#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)
 #define HAL_USE_SPI                 FALSE
 #endif
 
-#if !defined(HAL_USE_UART)
+/**
+ * @brief   Enables the UART subsystem.
+ */
+#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
 #define HAL_USE_UART                FALSE
 #endif
 
-#if !defined(HAL_USE_USB)
+/**
+ * @brief   Enables the USB subsystem.
+ */
+#if !defined(HAL_USE_USB) || defined(__DOXYGEN__)
 #define HAL_USE_USB                 FALSE
 #endif
 
+/*===========================================================================*/
+/* ADC driver related settings.                                              */
+/*===========================================================================*/
 
-#if !defined(ADC_USE_WAIT)
+/**
+ * @brief   Enables synchronous APIs.
+ * @note    Disabling this option saves both code and data space.
+ */
+#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__)
 #define ADC_USE_WAIT                TRUE
 #endif
 
-#if !defined(ADC_USE_MUTUAL_EXCLUSION)
+/**
+ * @brief   Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs.
+ * @note    Disabling this option saves both code and data space.
+ */
+#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
 #define ADC_USE_MUTUAL_EXCLUSION    TRUE
 #endif
 
+/*===========================================================================*/
+/* CAN driver related settings.                                              */
+/*===========================================================================*/
 
-#if !defined(CAN_USE_SLEEP_MODE)
+/**
+ * @brief   Sleep mode related APIs inclusion switch.
+ */
+#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__)
 #define CAN_USE_SLEEP_MODE          TRUE
 #endif
 
+/*===========================================================================*/
+/* I2C driver related settings.                                              */
+/*===========================================================================*/
 
-#if !defined(I2C_USE_MUTUAL_EXCLUSION)
+/**
+ * @brief   Enables the mutual exclusion APIs on the I2C bus.
+ */
+#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
 #define I2C_USE_MUTUAL_EXCLUSION    TRUE
 #endif
 
+/*===========================================================================*/
+/* MAC driver related settings.                                              */
+/*===========================================================================*/
 
-#if !defined(MAC_USE_ZERO_COPY)
+/**
+ * @brief   Enables an event sources for incoming packets.
+ */
+#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__)
 #define MAC_USE_ZERO_COPY           FALSE
 #endif
 
-#if !defined(MAC_USE_EVENTS)
+/**
+ * @brief   Enables an event sources for incoming packets.
+ */
+#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__)
 #define MAC_USE_EVENTS              TRUE
 #endif
 
-#if !defined(MMC_NICE_WAITING)
+/*===========================================================================*/
+/* MMC_SPI driver related settings.                                          */
+/*===========================================================================*/
+
+/**
+ * @brief   Delays insertions.
+ * @details If enabled this options inserts delays into the MMC waiting
+ *          routines releasing some extra CPU time for the threads with
+ *          lower priority, this may slow down the driver a bit however.
+ *          This option is recommended also if the SPI driver does not
+ *          use a DMA channel and heavily loads the CPU.
+ */
+#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__)
 #define MMC_NICE_WAITING            TRUE
 #endif
 
+/*===========================================================================*/
+/* SDC driver related settings.                                              */
+/*===========================================================================*/
 
-#if !defined(SDC_INIT_RETRY)
+/**
+ * @brief   Number of initialization attempts before rejecting the card.
+ * @note    Attempts are performed at 10mS intervals.
+ */
+#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__)
 #define SDC_INIT_RETRY              100
 #endif
 
-#if !defined(SDC_MMC_SUPPORT)
+/**
+ * @brief   Include support for MMC cards.
+ * @note    MMC support is not yet implemented so this option must be kept
+ *          at @p FALSE.
+ */
+#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__)
 #define SDC_MMC_SUPPORT             FALSE
 #endif
 
-#if !defined(SDC_NICE_WAITING)
+/**
+ * @brief   Delays insertions.
+ * @details If enabled this options inserts delays into the MMC waiting
+ *          routines releasing some extra CPU time for the threads with
+ *          lower priority, this may slow down the driver a bit however.
+ */
+#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__)
 #define SDC_NICE_WAITING            TRUE
 #endif
 
+/*===========================================================================*/
+/* SERIAL driver related settings.                                           */
+/*===========================================================================*/
 
-#if !defined(SERIAL_DEFAULT_BITRATE)
+/**
+ * @brief   Default bit rate.
+ * @details Configuration parameter, this is the baud rate selected for the
+ *          default configuration.
+ */
+#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__)
 #define SERIAL_DEFAULT_BITRATE      115200
 #endif
 
-#if !defined(SERIAL_BUFFERS_SIZE)
+/**
+ * @brief   Serial buffers size.
+ * @details Configuration parameter, you can change the depth of the queue
+ *          buffers depending on the requirements of your application.
+ * @note    The default is 64 bytes for both the transmission and receive
+ *          buffers.
+ */
+#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
 #define SERIAL_BUFFERS_SIZE         16
 #endif
 
+/*===========================================================================*/
+/* SERIAL_USB driver related setting.                                        */
+/*===========================================================================*/
+
+/**
+ * @brief   Serial over USB buffers size.
+ * @details Configuration parameter, the buffer size must be a multiple of
+ *          the USB data endpoint maximum packet size.
+ * @note    The default is 64 bytes for both the transmission and receive
+ *          buffers.
+ */
+#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)
+#define SERIAL_USB_BUFFERS_SIZE     256
+#endif
+
+/*===========================================================================*/
+/* SPI driver related settings.                                              */
+/*===========================================================================*/
 
-#if !defined(SPI_USE_WAIT)
+/**
+ * @brief   Enables synchronous APIs.
+ * @note    Disabling this option saves both code and data space.
+ */
+#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__)
 #define SPI_USE_WAIT                TRUE
 #endif
 
-#if !defined(SPI_USE_MUTUAL_EXCLUSION)
+/**
+ * @brief   Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs.
+ * @note    Disabling this option saves both code and data space.
+ */
+#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
 #define SPI_USE_MUTUAL_EXCLUSION    TRUE
 #endif
 
-#endif
+#endif /* _HALCONF_H_ */
+
+/** @} */

+ 19 - 20
stm32-chibios/main.c

@@ -1,12 +1,10 @@
-#include "ch.h"
 #include "hal.h"
+#include "nil.h"
 
-static WORKING_AREA(blinkyThreadArea, 128);
-
-static msg_t blinky(void *arg)
+THD_WORKING_AREA(waBlinky, 128);
+THD_FUNCTION(blinky, arg)
 {
     (void)arg;
-    chRegSetThreadName("blinky");
     for(;;)
     {
         palSetPad(GPIOH, GPIOH_LED1);
@@ -18,33 +16,34 @@ static msg_t blinky(void *arg)
 }
 
 
-static msg_t hello(void *arg)
+THD_WORKING_AREA(waHello, 128);
+THD_FUNCTION(hello, arg)
 {
     (void)arg;
-    chRegSetThreadName("hello");
-    while (TRUE)
-    {
-        palSetPad(GPIOH, GPIOH_LED1);
-        chThdSleepMilliseconds(500);
 
-        palClearPad(GPIOH, GPIOH_LED1);
-        chThdSleepMilliseconds(500);
+    palSetPadMode(GPIOC, GPIOC_USART3_TX, PAL_MODE_ALTERNATE(7));
+    palSetPadMode(GPIOC, GPIOC_USART3_RX, PAL_MODE_ALTERNATE(7));
+
+    sdStart(&SD3, NULL);
+
+    for (;;)
+    {
+        chnWrite((BaseChannel*)&SD3, "Hello, World!\r\n", sizeof("Hello, World!\r\n"));
+        chThdSleepMilliseconds(1000);
     }
 }
 
+THD_TABLE_BEGIN
+  THD_TABLE_ENTRY(waBlinky, "blinky", blinky, NULL)
+  THD_TABLE_ENTRY(waHello, "hello", hello, NULL)
+THD_TABLE_END
+
 int main(void) 
 {
     halInit();
     chSysInit();
 
-    sdStart(&SD3, NULL);
-    palSetPadMode(GPIOC, GPIOC_USART3_TX, PAL_MODE_ALTERNATE(7));
-    palSetPadMode(GPIOC, GPIOC_USART3_RX, PAL_MODE_ALTERNATE(7));
-
-    chThdCreateStatic(blinkyThreadArea, sizeof(blinkyThreadArea), NORMALPRIO, blinky, NULL);
     for(;;)
     {
-        chSequentialStreamWrite((BaseSequentialStream*)&SD3, "Hello, World!\r\n", sizeof("Hello, World!\r\n"));
-        chThdSleepMilliseconds(1000);
     }
 }

+ 70 - 6
stm32-chibios/mcuconf.h

@@ -1,3 +1,36 @@
+/*
+    ChibiOS - Copyright (C) 2006..2015 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.
+*/
+
+#ifndef _MCUCONF_H_
+#define _MCUCONF_H_
+
+/*
+ * STM32F4xx drivers configuration.
+ * The following settings override the default settings present in
+ * the various device driver implementation headers.
+ * Note that the settings for each driver only have effect if the whole
+ * driver is enabled in halconf.h.
+ *
+ * IRQ priorities:
+ * 15...0       Lowest...Highest.
+ *
+ * DMA priorities:
+ * 0...3        Lowest...Highest.
+ */
+
 #define STM32F4xx_MCUCONF
 
 /*
@@ -57,6 +90,19 @@
 #define STM32_CAN_CAN1_IRQ_PRIORITY         11
 #define STM32_CAN_CAN2_IRQ_PRIORITY         11
 
+/*
+ * DAC driver system settings.
+ */
+#define STM32_DAC_DUAL_MODE                 FALSE
+#define STM32_DAC_USE_DAC1_CH1              FALSE
+#define STM32_DAC_USE_DAC1_CH2              FALSE
+#define STM32_DAC_DAC1_CH1_IRQ_PRIORITY     10
+#define STM32_DAC_DAC1_CH2_IRQ_PRIORITY     10
+#define STM32_DAC_DAC1_CH1_DMA_PRIORITY     2
+#define STM32_DAC_DAC1_CH2_DMA_PRIORITY     2
+#define STM32_DAC_DAC1_CH1_DMA_STREAM       STM32_DMA_STREAM_ID(1, 5)
+#define STM32_DAC_DAC1_CH2_DMA_STREAM       STM32_DMA_STREAM_ID(1, 6)
+
 /*
  * EXT driver system settings.
  */
@@ -109,6 +155,7 @@
 #define STM32_I2C_USE_I2C1                  FALSE
 #define STM32_I2C_USE_I2C2                  FALSE
 #define STM32_I2C_USE_I2C3                  FALSE
+#define STM32_I2C_BUSY_TIMEOUT              50
 #define STM32_I2C_I2C1_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 0)
 #define STM32_I2C_I2C1_TX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 6)
 #define STM32_I2C_I2C2_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 2)
@@ -121,9 +168,7 @@
 #define STM32_I2C_I2C1_DMA_PRIORITY         3
 #define STM32_I2C_I2C2_DMA_PRIORITY         3
 #define STM32_I2C_I2C3_DMA_PRIORITY         3
-#define STM32_I2C_I2C1_DMA_ERROR_HOOK()     chSysHalt()
-#define STM32_I2C_I2C2_DMA_ERROR_HOOK()     chSysHalt()
-#define STM32_I2C_I2C3_DMA_ERROR_HOOK()     chSysHalt()
+#define STM32_I2C_DMA_ERROR_HOOK(i2cp)      osalSysHalt("DMA failure")
 
 /*
  * ICU driver system settings.
@@ -173,6 +218,17 @@
 #define STM32_PWM_TIM8_IRQ_PRIORITY         7
 #define STM32_PWM_TIM9_IRQ_PRIORITY         7
 
+/*
+ * SDC driver system settings.
+ */
+#define STM32_SDC_SDIO_DMA_PRIORITY         3
+#define STM32_SDC_SDIO_IRQ_PRIORITY         9
+#define STM32_SDC_WRITE_TIMEOUT_MS          250
+#define STM32_SDC_READ_TIMEOUT_MS           25
+#define STM32_SDC_CLOCK_ACTIVATION_DELAY    10
+#define STM32_SDC_SDIO_UNALIGNED_SUPPORT    TRUE
+#define STM32_SDC_SDIO_DMA_STREAM           STM32_DMA_STREAM_ID(2, 3)
+
 /*
  * SERIAL driver system settings.
  */
@@ -193,7 +249,7 @@
  * SPI driver system settings.
  */
 #define STM32_SPI_USE_SPI1                  FALSE
-#define STM32_SPI_USE_SPI2                  TRUE
+#define STM32_SPI_USE_SPI2                  FALSE
 #define STM32_SPI_USE_SPI3                  FALSE
 #define STM32_SPI_SPI1_RX_DMA_STREAM        STM32_DMA_STREAM_ID(2, 0)
 #define STM32_SPI_SPI1_TX_DMA_STREAM        STM32_DMA_STREAM_ID(2, 3)
@@ -207,7 +263,13 @@
 #define STM32_SPI_SPI1_IRQ_PRIORITY         10
 #define STM32_SPI_SPI2_IRQ_PRIORITY         10
 #define STM32_SPI_SPI3_IRQ_PRIORITY         10
-#define STM32_SPI_DMA_ERROR_HOOK(spip)      chSysHalt()
+#define STM32_SPI_DMA_ERROR_HOOK(spip)      osalSysHalt("DMA failure")
+
+/*
+ * ST driver system settings.
+ */
+#define STM32_ST_IRQ_PRIORITY               8
+#define STM32_ST_USE_TIMER                  2
 
 /*
  * UART driver system settings.
@@ -242,7 +304,7 @@
 #define STM32_UART_UART4_DMA_PRIORITY       0
 #define STM32_UART_UART5_DMA_PRIORITY       0
 #define STM32_UART_USART6_DMA_PRIORITY      0
-#define STM32_UART_DMA_ERROR_HOOK(uartp)    chSysHalt()
+#define STM32_UART_DMA_ERROR_HOOK(uartp)    osalSysHalt("DMA failure")
 
 /*
  * USB driver system settings.
@@ -256,3 +318,5 @@
 #define STM32_USB_OTG_THREAD_PRIO           LOWPRIO
 #define STM32_USB_OTG_THREAD_STACK_SIZE     128
 #define STM32_USB_OTGFIFO_FILL_BASEPRI      0
+
+#endif /* _MCUCONF_H_ */

+ 179 - 0
stm32-chibios/nilconf.h

@@ -0,0 +1,179 @@
+/*
+    ChibiOS - Copyright (C) 2006..2015 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.
+*/
+
+/**
+ * @file    nilconf.h
+ * @brief   Configuration file template.
+ * @details A copy of this file must be placed in each project directory, it
+ *          contains the application specific kernel settings.
+ *
+ * @addtogroup config
+ * @details Kernel related settings and hooks.
+ * @{
+ */
+
+#ifndef _NILCONF_H_
+#define _NILCONF_H_
+
+/*===========================================================================*/
+/**
+ * @name Kernel parameters and options
+ * @{
+ */
+/*===========================================================================*/
+
+/**
+ * @brief   Number of user threads in the application.
+ * @note    This number is not inclusive of the idle thread which is
+ *          Implicitly handled.
+ */
+#define NIL_CFG_NUM_THREADS                 2
+
+/** @} */
+
+/*===========================================================================*/
+/**
+ * @name System timer settings
+ * @{
+ */
+/*===========================================================================*/
+
+/**
+ * @brief   System time counter resolution.
+ * @note    Allowed values are 16 or 32 bits.
+ */
+#define NIL_CFG_ST_RESOLUTION               32
+
+/**
+ * @brief   System tick frequency.
+ * @note    This value together with the @p NIL_CFG_ST_RESOLUTION
+ *          option defines the maximum amount of time allowed for
+ *          timeouts.
+ */
+#define NIL_CFG_ST_FREQUENCY                50000
+
+/**
+ * @brief   Time delta constant for the tick-less mode.
+ * @note    If this value is zero then the system uses the classic
+ *          periodic tick. This value represents the minimum number
+ *          of ticks that is safe to specify in a timeout directive.
+ *          The value one is not valid, timeouts are rounded up to
+ *          this value.
+ */
+#define NIL_CFG_ST_TIMEDELTA                2
+
+/** @} */
+
+/*===========================================================================*/
+/**
+ * @name Subsystem options
+ * @{
+ */
+/*===========================================================================*/
+
+/**
+ * @brief   Events Flags APIs.
+ * @details If enabled then the event flags APIs are included in the kernel.
+ *
+ * @note    The default is @p TRUE.
+ */
+#define NIL_CFG_USE_EVENTS                  TRUE
+
+/** @} */
+
+/*===========================================================================*/
+/**
+ * @name Debug options
+ * @{
+ */
+/*===========================================================================*/
+
+/**
+ * @brief   System assertions.
+ */
+#define NIL_CFG_ENABLE_ASSERTS              FALSE
+
+/**
+ * @brief   Stack check.
+ */
+#define NIL_CFG_ENABLE_STACK_CHECK          FALSE
+
+/** @} */
+
+/*===========================================================================*/
+/**
+ * @name Kernel hooks
+ * @{
+ */
+/*===========================================================================*/
+
+/**
+ * @brief   System initialization hook.
+ */
+#if !defined(NIL_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__)
+#define NIL_CFG_SYSTEM_INIT_HOOK() {                                        \
+}
+#endif
+
+/**
+ * @brief   Threads descriptor structure extension.
+ * @details User fields added to the end of the @p thread_t structure.
+ */
+#define NIL_CFG_THREAD_EXT_FIELDS                                           \
+  /* Add threads custom fields here.*/
+
+/**
+ * @brief   Threads initialization hook.
+ */
+#define NIL_CFG_THREAD_EXT_INIT_HOOK(tr) {                                  \
+  /* Add custom threads initialization code here.*/                         \
+}
+
+/**
+ * @brief   Idle thread enter hook.
+ * @note    This hook is invoked within a critical zone, no OS functions
+ *          should be invoked from here.
+ * @note    This macro can be used to activate a power saving mode.
+ */
+#define NIL_CFG_IDLE_ENTER_HOOK() {                                         \
+}
+
+/**
+ * @brief   Idle thread leave hook.
+ * @note    This hook is invoked within a critical zone, no OS functions
+ *          should be invoked from here.
+ * @note    This macro can be used to deactivate a power saving mode.
+ */
+#define NIL_CFG_IDLE_LEAVE_HOOK() {                                         \
+}
+
+/**
+ * @brief   System halt hook.
+ */
+#if !defined(NIL_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__)
+#define NIL_CFG_SYSTEM_HALT_HOOK(reason) {                                  \
+}
+#endif
+
+/** @} */
+
+/*===========================================================================*/
+/* Port-specific settings (override port settings defaulted in nilcore.h).   */
+/*===========================================================================*/
+
+#endif  /* _NILCONF_H_ */
+
+/** @} */

+ 67 - 0
stm32-chibios/osalconf.h

@@ -0,0 +1,67 @@
+/*
+    ChibiOS - Copyright (C) 2006..2015 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.
+*/
+
+/**
+ * @file    templates/halconf.h
+ * @brief   Bare-metal OSAL configuration header.
+ *
+ * @addtogroup OSAL_CONF
+ * @{
+ */
+
+#ifndef _OSALCONF_H_
+#define _OSALCONF_H_
+
+/**
+ * @brief   Frequency in Hertz of the system tick.
+ */
+#if !defined(OSAL_ST_FREQUENCY) || defined(__DOXYGEN__)
+#define OSAL_ST_FREQUENCY                   1000
+#endif
+
+/**
+ * @brief   Enables OSAL assertions.
+ */
+#if !defined(OSAL_DBG_ENABLE_ASSERTS) || defined(__DOXYGEN__)
+#define OSAL_DBG_ENABLE_ASSERTS             FALSE
+#endif
+
+/**
+ * @brief   Enables OSAL functions parameters checks.
+ */
+#if !defined(OSAL_DBG_ENABLE_CHECKS) || defined(__DOXYGEN__)
+#define OSAL_DBG_ENABLE_CHECKS              FALSE
+#endif
+
+/**
+ * @brief   OSAL initialization hook.
+ */
+#if !defined(OSAL_INIT_HOOK) || defined(__DOXYGEN__)
+#define OSAL_INIT_HOOK() {                                                  \
+}
+#endif
+
+/**
+ * @brief   Idle loop hook macro.
+ */
+#if !defined(OSAL_IDLE_HOOK) || defined(__DOXYGEN__)
+#define OSAL_IDLE_HOOK() {                                                  \
+}
+#endif
+
+#endif /* _OSALCONF_H_ */
+
+/** @} */