From c03d2eb70f20844e62b5522fdce1e366a2318401 Mon Sep 17 00:00:00 2001 From: Philippe Boutin Date: Sat, 24 Aug 2019 01:58:51 -0400 Subject: [PATCH 1/3] Fixed everything to work with the newer version of ChibiOS --- .cargo/config | 3 - .gitmodules | 2 +- Cargo.toml | 12 ++-- ChibiOS | 2 +- build.rs | 26 +++---- chconf.h | 194 +++++++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 214 insertions(+), 25 deletions(-) diff --git a/.cargo/config b/.cargo/config index 1a3c422..964be98 100644 --- a/.cargo/config +++ b/.cargo/config @@ -7,7 +7,6 @@ rustflags = [ "-C", "link-arg=-Tlink.x", "-C", "link-arg=--gc-sections", "-C", "linker=arm-none-eabi-ld", - "-Z", "linker-flavor=ld", ] [target.thumbv7m-none-eabi] @@ -18,7 +17,6 @@ rustflags = [ "-C", "link-arg=-Tlink.x", "-C", "link-arg=--gc-sections", "-C", "linker=arm-none-eabi-ld", - "-Z", "linker-flavor=ld", ] [target.thumbv7em-none-eabi] @@ -29,5 +27,4 @@ rustflags = [ "-C", "link-arg=-Tlink.x", "-C", "link-arg=--gc-sections", "-C", "linker=arm-none-eabi-ld", - "-Z", "linker-flavor=ld", ] diff --git a/.gitmodules b/.gitmodules index 08660ef..71b5f2e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "ChibiOS"] path = ChibiOS - url = https://github.com/ChibiOS/ChibiOS.git + url = https://github.com/ChibiOS/ChibiOS diff --git a/Cargo.toml b/Cargo.toml index ae506e8..75475ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,19 +1,19 @@ [package] name = "chibi-os-rust" -version = "0.3.0" -authors = ["Brandon Matthews "] +version = "0.4.0" +authors = ["Brandon Matthews ", "Philippe Boutin "] build = "build.rs" [build-dependencies] -gcc = "0.3" -bindgen = "0.26.3" +cc = "*" +bindgen = "*" [dependencies] -cty = "0.1" +cty = "*" [dependencies.cortex-m-rt] features = ["abort-on-panic"] -version = "0.3.0" +version = "*" [features] # The features you specify will control the particular port devince and chip diff --git a/ChibiOS b/ChibiOS index 6ee9c27..2074271 160000 --- a/ChibiOS +++ b/ChibiOS @@ -1 +1 @@ -Subproject commit 6ee9c2788555e3b31d0ca62a0442121ebf0b158d +Subproject commit 20742714c0099084e5d63a7c6d47020bde2e81e7 diff --git a/build.rs b/build.rs index 00e834e..19a8e4d 100644 --- a/build.rs +++ b/build.rs @@ -2,7 +2,7 @@ use std::env; use std::path::PathBuf; extern crate bindgen; -extern crate gcc; +extern crate cc; /// In order to build ChibiOS and generate bindings, ChibiOS must know about its chip type, /// its device type, and its port. Each of these things controls slightly different aspects @@ -26,7 +26,7 @@ fn main() { let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); - let mut builder = gcc::Config::new(); + let mut builder = cc::Build::new(); let bindings = bindgen::Builder::default() .header("./ChibiOS/os/common/abstractions/cmsis_os/cmsis_os.h") @@ -53,10 +53,11 @@ fn main() { "./ChibiOS/os/rt/src/chevents.c", "./ChibiOS/os/rt/src/chmsg.c", "./ChibiOS/os/rt/src/chdynamic.c", - "./ChibiOS/os/common/oslib/src/chmboxes.c", - "./ChibiOS/os/common/oslib/src/chmemcore.c", - "./ChibiOS/os/common/oslib/src/chheap.c", - "./ChibiOS/os/common/oslib/src/chmempools.c", + "./ChibiOS/os/oslib/src/chmboxes.c", + "./ChibiOS/os/oslib/src/chfactory.c", + "./ChibiOS/os/oslib/src/chmemheaps.c", + "./ChibiOS/os/oslib/src/chmemcore.c", + "./ChibiOS/os/oslib/src/chmempools.c", ]; for os_src_file in os_src_files.iter() { @@ -101,10 +102,11 @@ fn main() { "./ChibiOS/os/license", "./ChibiOS/os/various", "./ChibiOS/os/rt/include", // KERNINC, from os/rt/rt.mk - "./ChibiOS/os/common/oslib/include", // KERNINC, from os/rt/rt.mk - "ChibiOS/os/common/ports/ARMCMx", // PORTINC, from os/common/ports/ARMCMx/compilers/GCC/mk/port_v?m.mk - "ChibiOS/os/common/ports/ARMCMx/compilers/GCC", // PORTINC, from os/common/ports/ARMCMx/compilers/GCC/mk/port_v?m.mk - "ChibiOS/os/common/ext/CMSIS/include", // STARTUPINC, from os/common/startup/ARMCMx/compilers/GCC/mk/startup_*.mk + "./ChibiOS/os/oslib/include", // KERNINC, from os/rt/rt.mk + "./ChibiOS/os/common/ports/ARMCMx", // PORTINC, from os/common/ports/ARMCMx/compilers/GCC/mk/port_v?m.mk + "./ChibiOS/os/common/ports/ARMCMx/compilers/GCC", // PORTINC, from os/common/ports/ARMCMx/compilers/GCC/mk/port_v?m.mk + "./ChibiOS/os/common/ext/CMSIS/include", // STARTUPINC, from os/common/startup/ARMCMx/compilers/GCC/mk/startup_*.mk + "./ChibiOS/os/common/ext/ARM/CMSIS/Core/Include" ]; for include_dir in include_dirs.iter() { @@ -115,8 +117,8 @@ fn main() { #[cfg(feature="device_stm32f4xx")] let device_include_dirs = [ - "ChibiOS/os/common/startup/ARMCMx/devices/STM32F4xx", // STARTUPINC, from os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk - "ChibiOS/os/common/ext/CMSIS/ST/STM32F4xx", // STARTUPINC, from os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk + "./ChibiOS/os/common/startup/ARMCMx/devices/STM32F4xx", // STARTUPINC, from os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk + "./ChibiOS/os/common/ext/ST/STM32F4xx", // STARTUPINC, from os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk ]; #[cfg(feature="device_stm32f0xx")] diff --git a/chconf.h b/chconf.h index b7c3d86..a7bd7f6 100644 --- a/chconf.h +++ b/chconf.h @@ -29,6 +29,7 @@ #define CHCONF_H #define _CHIBIOS_RT_CONF_ +#define _CHIBIOS_RT_CONF_VER_6_0_ /*===========================================================================*/ /** @@ -50,6 +51,22 @@ */ #define CH_CFG_ST_FREQUENCY 1000 +/** + * @brief Time intervals data size. + * @note Allowed values are 16, 32 or 64 bits. + */ +#if !defined(CH_CFG_INTERVALS_SIZE) +#define CH_CFG_INTERVALS_SIZE 32 +#endif + +/** + * @brief Time types data size. + * @note Allowed values are 16 or 32 bits. + */ +#if !defined(CH_CFG_TIME_TYPES_SIZE) +#define CH_CFG_TIME_TYPES_SIZE 32 +#endif + /** * @brief Time delta constant for the tick-less mode. * @note If this value is zero then the system uses the classic @@ -58,7 +75,9 @@ * The value one is not valid, timeouts are rounded up to * this value. */ +#if !defined(CH_CFG_ST_TIMEDELTA) #define CH_CFG_ST_TIMEDELTA 0 +#endif /** @} */ @@ -81,7 +100,9 @@ * @note The round robin preemption is not supported in tickless mode and * must be set to zero in that case. */ +#if !defined(CH_CFG_TIME_QUANTUM) #define CH_CFG_TIME_QUANTUM 0 +#endif /** * @brief Managed RAM size. @@ -94,7 +115,9 @@ * provide the @p __heap_base__ and @p __heap_end__ symbols. * @note Requires @p CH_CFG_USE_MEMCORE. */ +#if !defined(CH_CFG_MEMCORE_SIZE) #define CH_CFG_MEMCORE_SIZE 0 +#endif /** * @brief Idle thread automatic spawn suppression. @@ -103,7 +126,9 @@ * function becomes the idle thread and must implement an * infinite loop. */ +#if !defined(CH_CFG_NO_IDLE_THREAD) #define CH_CFG_NO_IDLE_THREAD FALSE +#endif /** @} */ @@ -122,7 +147,9 @@ * @note This is not related to the compiler optimization options. * @note The default is @p TRUE. */ +#if !defined(CH_CFG_OPTIMIZE_SPEED) #define CH_CFG_OPTIMIZE_SPEED TRUE +#endif /** @} */ @@ -140,7 +167,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_TM) #define CH_CFG_USE_TM FALSE +#endif /** * @brief Threads registry APIs. @@ -148,7 +177,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_REGISTRY) #define CH_CFG_USE_REGISTRY TRUE +#endif /** * @brief Threads synchronization APIs. @@ -157,7 +188,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_WAITEXIT) #define CH_CFG_USE_WAITEXIT TRUE +#endif /** * @brief Semaphores APIs. @@ -165,7 +198,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_SEMAPHORES) #define CH_CFG_USE_SEMAPHORES TRUE +#endif /** * @brief Semaphores queuing mode. @@ -176,7 +211,9 @@ * requirements. * @note Requires @p CH_CFG_USE_SEMAPHORES. */ +#if !defined(CH_CFG_USE_SEMAPHORES_PRIORITY) #define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE +#endif /** * @brief Mutexes APIs. @@ -184,7 +221,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_MUTEXES) #define CH_CFG_USE_MUTEXES TRUE +#endif /** * @brief Enables recursive behavior on mutexes. @@ -194,7 +233,9 @@ * @note The default is @p FALSE. * @note Requires @p CH_CFG_USE_MUTEXES. */ +#if !defined(CH_CFG_USE_MUTEXES_RECURSIVE) #define CH_CFG_USE_MUTEXES_RECURSIVE FALSE +#endif /** * @brief Conditional Variables APIs. @@ -204,7 +245,9 @@ * @note The default is @p TRUE. * @note Requires @p CH_CFG_USE_MUTEXES. */ +#if !defined(CH_CFG_USE_CONDVARS) #define CH_CFG_USE_CONDVARS TRUE +#endif /** * @brief Conditional Variables APIs with timeout. @@ -214,7 +257,9 @@ * @note The default is @p TRUE. * @note Requires @p CH_CFG_USE_CONDVARS. */ +#if !defined(CH_CFG_USE_CONDVARS_TIMEOUT) #define CH_CFG_USE_CONDVARS_TIMEOUT TRUE +#endif /** * @brief Events Flags APIs. @@ -222,7 +267,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_EVENTS) #define CH_CFG_USE_EVENTS TRUE +#endif /** * @brief Events Flags APIs with timeout. @@ -232,7 +279,9 @@ * @note The default is @p TRUE. * @note Requires @p CH_CFG_USE_EVENTS. */ +#if !defined(CH_CFG_USE_EVENTS_TIMEOUT) #define CH_CFG_USE_EVENTS_TIMEOUT TRUE +#endif /** * @brief Synchronous Messages APIs. @@ -241,7 +290,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_MESSAGES) #define CH_CFG_USE_MESSAGES TRUE +#endif /** * @brief Synchronous Messages queuing mode. @@ -252,7 +303,9 @@ * requirements. * @note Requires @p CH_CFG_USE_MESSAGES. */ +#if !defined(CH_CFG_USE_MESSAGES_PRIORITY) #define CH_CFG_USE_MESSAGES_PRIORITY FALSE +#endif /** * @brief Mailboxes APIs. @@ -262,7 +315,9 @@ * @note The default is @p TRUE. * @note Requires @p CH_CFG_USE_SEMAPHORES. */ +#if !defined(CH_CFG_USE_MAILBOXES) #define CH_CFG_USE_MAILBOXES TRUE +#endif /** * @brief Core Memory Manager APIs. @@ -271,7 +326,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_MEMCORE) #define CH_CFG_USE_MEMCORE TRUE +#endif /** * @brief Heap Allocator APIs. @@ -283,7 +340,9 @@ * @p CH_CFG_USE_SEMAPHORES. * @note Mutexes are recommended. */ +#if !defined(CH_CFG_USE_HEAP) #define CH_CFG_USE_HEAP TRUE +#endif /** * @brief Memory Pools Allocator APIs. @@ -292,7 +351,31 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_MEMPOOLS) #define CH_CFG_USE_MEMPOOLS TRUE +#endif + +/** + * @brief Objects FIFOs APIs. + * @details If enabled then the objects FIFOs APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_CFG_USE_OBJ_FIFOS) +#define CH_CFG_USE_OBJ_FIFOS TRUE +#endif + +/** + * @brief Pipes APIs. + * @details If enabled then the pipes APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_CFG_USE_PIPES) +#define CH_CFG_USE_PIPES TRUE +#endif /** * @brief Dynamic Threads APIs. @@ -303,7 +386,80 @@ * @note Requires @p CH_CFG_USE_WAITEXIT. * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS. */ +#if !defined(CH_CFG_USE_DYNAMIC) #define CH_CFG_USE_DYNAMIC TRUE +#endif + +/** @} */ + +/*===========================================================================*/ +/** + * @name Objects factory options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Objects Factory APIs. + * @details If enabled then the objects factory APIs are included in the + * kernel. + * + * @note The default is @p FALSE. + */ +#if !defined(CH_CFG_USE_FACTORY) +#define CH_CFG_USE_FACTORY TRUE +#endif + +/** + * @brief Maximum length for object names. + * @details If the specified length is zero then the name is stored by + * pointer but this could have unintended side effects. + */ +#if !defined(CH_CFG_FACTORY_MAX_NAMES_LENGTH) +#define CH_CFG_FACTORY_MAX_NAMES_LENGTH 8 +#endif + +/** + * @brief Enables the registry of generic objects. + */ +#if !defined(CH_CFG_FACTORY_OBJECTS_REGISTRY) +#define CH_CFG_FACTORY_OBJECTS_REGISTRY TRUE +#endif + +/** + * @brief Enables factory for generic buffers. + */ +#if !defined(CH_CFG_FACTORY_GENERIC_BUFFERS) +#define CH_CFG_FACTORY_GENERIC_BUFFERS TRUE +#endif + +/** + * @brief Enables factory for semaphores. + */ +#if !defined(CH_CFG_FACTORY_SEMAPHORES) +#define CH_CFG_FACTORY_SEMAPHORES TRUE +#endif + +/** + * @brief Enables factory for mailboxes. + */ +#if !defined(CH_CFG_FACTORY_MAILBOXES) +#define CH_CFG_FACTORY_MAILBOXES TRUE +#endif + +/** + * @brief Enables factory for objects FIFOs. + */ +#if !defined(CH_CFG_FACTORY_OBJ_FIFOS) +#define CH_CFG_FACTORY_OBJ_FIFOS TRUE +#endif + +/** + * @brief Enables factory for Pipes. + */ +#if !defined(CH_CFG_FACTORY_PIPES) || defined(__DOXYGEN__) +#define CH_CFG_FACTORY_PIPES TRUE +#endif /** @} */ @@ -319,7 +475,9 @@ * * @note The default is @p FALSE. */ +#if !defined(CH_DBG_STATISTICS) #define CH_DBG_STATISTICS FALSE +#endif /** * @brief Debug option, system state check. @@ -328,7 +486,9 @@ * * @note The default is @p FALSE. */ +#if !defined(CH_DBG_SYSTEM_STATE_CHECK) #define CH_DBG_SYSTEM_STATE_CHECK FALSE +#endif /** * @brief Debug option, parameters checks. @@ -337,7 +497,9 @@ * * @note The default is @p FALSE. */ +#if !defined(CH_DBG_ENABLE_CHECKS) #define CH_DBG_ENABLE_CHECKS FALSE +#endif /** * @brief Debug option, consistency checks. @@ -347,7 +509,9 @@ * * @note The default is @p FALSE. */ +#if !defined(CH_DBG_ENABLE_ASSERTS) #define CH_DBG_ENABLE_ASSERTS FALSE +#endif /** * @brief Debug option, trace buffer. @@ -355,14 +519,18 @@ * * @note The default is @p CH_DBG_TRACE_MASK_DISABLED. */ +#if !defined(CH_DBG_TRACE_MASK) #define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED +#endif /** * @brief Trace buffer entries. * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is * different from @p CH_DBG_TRACE_MASK_DISABLED. */ +#if !defined(CH_DBG_TRACE_BUFFER_SIZE) #define CH_DBG_TRACE_BUFFER_SIZE 128 +#endif /** * @brief Debug option, stack checks. @@ -374,7 +542,9 @@ * @note The default failure mode is to halt the system with the global * @p panic_msg variable set to @p NULL. */ +#if !defined(CH_DBG_ENABLE_STACK_CHECK) #define CH_DBG_ENABLE_STACK_CHECK FALSE +#endif /** * @brief Debug option, stacks initialization. @@ -384,7 +554,9 @@ * * @note The default is @p FALSE. */ +#if !defined(CH_DBG_FILL_THREADS) #define CH_DBG_FILL_THREADS FALSE +#endif /** * @brief Debug option, threads profiling. @@ -395,7 +567,9 @@ * @note This debug option is not currently compatible with the * tickless mode. */ +#if !defined(CH_DBG_THREADS_PROFILING) #define CH_DBG_THREADS_PROFILING FALSE +#endif /** @} */ @@ -406,6 +580,22 @@ */ /*===========================================================================*/ +/** + * @brief System structure extension. + * @details User fields added to the end of the @p ch_system_t structure. + */ +#define CH_CFG_SYSTEM_EXTRA_FIELDS \ + /* Add threads custom fields here.*/ + +/** + * @brief System initialization hook. + * @details User initialization code added to the @p chSysInit() function + * just before interrupts are enabled globally. + */ +#define CH_CFG_SYSTEM_INIT_HOOK() { \ + /* Add threads initialization code here.*/ \ +} + /** * @brief Threads descriptor structure extension. * @details User fields added to the end of the @p thread_t structure. @@ -415,9 +605,9 @@ /** * @brief Threads initialization hook. - * @details User initialization code added to the @p chThdInit() API. + * @details User initialization code added to the @p _thread_init() function. * - * @note It is invoked from within @p chThdInit() and implicitly from all + * @note It is invoked from within @p _thread_init() and implicitly from all * the threads creation APIs. */ #define CH_CFG_THREAD_INIT_HOOK(tp) { \ From 1845ff726ac8a1c7a510b0e9a642576610f9068e Mon Sep 17 00:00:00 2001 From: Philippe Boutin Date: Fri, 23 Aug 2019 23:03:16 -0400 Subject: [PATCH 2/3] Forgot to add new commits --- ChibiOS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChibiOS b/ChibiOS index 2074271..6ee9c27 160000 --- a/ChibiOS +++ b/ChibiOS @@ -1 +1 @@ -Subproject commit 20742714c0099084e5d63a7c6d47020bde2e81e7 +Subproject commit 6ee9c2788555e3b31d0ca62a0442121ebf0b158d From a09922d46517f5a9bd399cb5dea9d0670bc2c29d Mon Sep 17 00:00:00 2001 From: Philippe Boutin Date: Sun, 25 Aug 2019 11:58:48 -0400 Subject: [PATCH 3/3] Changes to Cargo.toml so that there is more consistent compiling --- Cargo.toml | 10 +++++----- ChibiOS | 2 +- src/app.rs | 1 - src/main.rs | 1 - 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 75475ae..66d52c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,19 +1,19 @@ [package] name = "chibi-os-rust" -version = "0.4.0" +version = "0.5.0" authors = ["Brandon Matthews ", "Philippe Boutin "] build = "build.rs" [build-dependencies] -cc = "*" -bindgen = "*" +cc = "^1.0" +bindgen = "^0.26" [dependencies] -cty = "*" +cty = "0.1.5" [dependencies.cortex-m-rt] features = ["abort-on-panic"] -version = "*" +version = "^0.3" [features] # The features you specify will control the particular port devince and chip diff --git a/ChibiOS b/ChibiOS index 6ee9c27..07e1919 160000 --- a/ChibiOS +++ b/ChibiOS @@ -1 +1 @@ -Subproject commit 6ee9c2788555e3b31d0ca62a0442121ebf0b158d +Subproject commit 07e1919e90bba603e65b41aa64dc98c40a012d00 diff --git a/src/app.rs b/src/app.rs index 2ecd439..a16caf0 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,4 +1,3 @@ - use chibios; extern "C" fn thread_one(_: chibios::RawOSArg) { diff --git a/src/main.rs b/src/main.rs index 2112628..c4554de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ - #![feature(used)] #![no_std]