diff --git a/hw/bsp/rm-c/debug/stm32f407xx.cfg b/hw/bsp/rm-c/debug/stm32f407xx.cfg new file mode 100644 index 0000000000000000000000000000000000000000..b8a35a695b76a7702210fd1ad127aad59483b312 --- /dev/null +++ b/hw/bsp/rm-c/debug/stm32f407xx.cfg @@ -0,0 +1,8 @@ +source [find interface/jlink.cfg] + +transport select swd + +set WORKAREASIZE 0x2000 +source [find target/stm32f4x.cfg] + +reset_config none \ No newline at end of file diff --git a/src/device/led_rgb/dev_led_rgb.cpp b/src/device/led_rgb/dev_led_rgb.cpp index 65e0081ef2cdfee8fe6811f79a052bb5e2b73c28..af2f4889d5b21588dab849cfa5450581676873cf 100644 --- a/src/device/led_rgb/dev_led_rgb.cpp +++ b/src/device/led_rgb/dev_led_rgb.cpp @@ -36,6 +36,9 @@ RGB::RGB(bool auto_start) { led->Set(BLUE, 1); led_fsm = 0; break; + default: + led_fsm = 0; + break; } led->thread_.SleepUntil(250, last_online_time); @@ -51,25 +54,20 @@ RGB::RGB(bool auto_start) { bool RGB::Set(RGB::Channel ch, float duty_cycle) { clampf(&duty_cycle, 0.0f, 1.0f); - bsp_pwm_channel_t pwm_ch = BSP_PWM_NUMBER; - switch (ch) { case RED: bsp_pwm_set_comp(BSP_PWM_LED_RED, duty_cycle); - pwm_ch = BSP_PWM_LED_RED; break; case GREEN: bsp_pwm_set_comp(BSP_PWM_LED_GRN, duty_cycle); - pwm_ch = BSP_PWM_LED_GRN; break; case BLUE: bsp_pwm_set_comp(BSP_PWM_LED_BLU, duty_cycle); - pwm_ch = BSP_PWM_LED_BLU; break; default: - pwm_ch = BSP_PWM_LED_RED; + break; } return true; diff --git a/src/system/FreeRTOS/Kconfig b/src/system/FreeRTOS/Kconfig index 9dfe3577a7b4cde0d58b0cb35cf3ad43cc04399a..0faa8736c927d8cddc684bbed11ed6970407542d 100644 --- a/src/system/FreeRTOS/Kconfig +++ b/src/system/FreeRTOS/Kconfig @@ -10,14 +10,34 @@ config FREERTOS_TIMER_TASK_STACK_DEPTH range 128 4096 default 256 -config FREERTOS_USB_TASK_STACK_DEPTH - int "USB任务堆栈大小" - range 128 4096 - default 256 +config ENABLE_DATABASE + bool "是否开启Flash数据库" + default y + +config ENABLE_MINISHELL + bool "是否开启MiniShell" + default y + +if ENABLE_MINISHELL config FREERTOS_TERM_TASK_STACK_DEPTH int "终端任务堆栈大小" range 128 4096 default 512 -endmenu +config ENABLE_TINYUSB_TASK + bool "是否开启TinyUSB任务" + default y + +if ENABLE_TINYUSB_TASK + +config FREERTOS_USB_TASK_STACK_DEPTH + int "USB任务堆栈大小" + range 128 4096 + default 256 + +endif +endif + + +endmenu \ No newline at end of file diff --git a/src/system/FreeRTOS/semaphore.hpp b/src/system/FreeRTOS/semaphore.hpp index a264cc9e3b9d65aed2465497e93d63e7f3c1c58c..7a3080460735108bcf9cab606d0ba100c992f85e 100644 --- a/src/system/FreeRTOS/semaphore.hpp +++ b/src/system/FreeRTOS/semaphore.hpp @@ -7,44 +7,48 @@ #include "semphr.h" namespace System { -class Semaphore { - public: - Semaphore(uint32_t init_count) - : handle_(xSemaphoreCreateCounting(UINT32_MAX, init_count)) {} - - ~Semaphore() { vSemaphoreDelete(handle_); } - - void Post() { - if (bsp_sys_in_isr()) { - BaseType_t px_higher_priority_task_woken = 0; - xSemaphoreGiveFromISR(this->handle_, &px_higher_priority_task_woken); - if (px_higher_priority_task_woken != pdFALSE) { - portYIELD(); - } - } else { - xSemaphoreGive(this->handle_); +class Semaphore +{ + SemaphoreHandle_t handle_; +public: + Semaphore(uint32_t init_count) + : handle_(xSemaphoreCreateCounting(UINT32_MAX, init_count)) + { } - } - - bool Wait(uint32_t timeout = UINT32_MAX) { - if (!bsp_sys_in_isr()) { - return xSemaphoreTake(this->handle_, timeout) == pdTRUE; - } else { - BaseType_t px_higher_priority_task_woken = 0; - BaseType_t ans = - xSemaphoreTakeFromISR(this->handle_, - &px_higher_priority_task_woken) == pdTRUE; - if (px_higher_priority_task_woken != pdFALSE) { - portYIELD(); - } - return ans == pdPASS; + ~Semaphore() { vSemaphoreDelete(handle_); } + bool Wait(uint32_t timeout = UINT32_MAX) { + if (!bsp_sys_in_isr()) { + return xSemaphoreTake(this->handle_, timeout) == pdTRUE; + } else { + BaseType_t px_higher_priority_task_woken = 0; + BaseType_t ans = + xSemaphoreTakeFromISR(this->handle_, + &px_higher_priority_task_woken) == pdTRUE; + + if (px_higher_priority_task_woken != pdFALSE) { + portYIELD(); + } + return ans == pdPASS; + } + } + void Post() + { + if (bsp_sys_in_isr()) + { + BaseType_t px_higher_priority_task_woken = 0; + xSemaphoreGiveFromISR(this->handle_, &px_higher_priority_task_woken); + if (px_higher_priority_task_woken != pdFALSE) + { + portYIELD(); + } + } + else + { + xSemaphoreGive(this->handle_); + } } - } - - uint32_t Value() { return uxSemaphoreGetCount(&handle_); } - private: - SemaphoreHandle_t handle_; + uint32_t Value() { return uxSemaphoreGetCount(this->handle_); } }; -} // namespace System +} \ No newline at end of file diff --git a/src/system/FreeRTOS/system.hpp b/src/system/FreeRTOS/system.hpp index 91469d21ac27e408c1d5bf1b91a1bbf74b57bf2a..2f4cb09b0c8ca5f28117a8ec07e3d4296456bd05 100644 --- a/src/system/FreeRTOS/system.hpp +++ b/src/system/FreeRTOS/system.hpp @@ -1,9 +1,13 @@ +#if defined(ENABLE_DATABASE) && (ENABLE_DATABASE != 0) #include +#endif #include #include #include #include +#if defined(ENABLE_MINISHELL) && (ENABLE_MINISHELL != 0) #include +#endif #include #include @@ -15,10 +19,15 @@ void Start(RobotParam... param) { auto init_fun = [](RobotParam... param) { Message* msg = static_cast(pvPortMalloc(sizeof(Message))); new (msg) Message(); +#if defined(ENABLE_MINISHELL) && (ENABLE_MINISHELL != 0) Term* term = static_cast(pvPortMalloc(sizeof(Term))); new (term) Term(); +#endif + +#if defined(ENABLE_DATABASE) && (ENABLE_DATABASE != 0) Database* database = static_cast(pvPortMalloc(sizeof(Database))); new (database) Database(); +#endif Timer* timer = static_cast(pvPortMalloc(sizeof(Timer))); new (timer) Timer(); diff --git a/src/system/FreeRTOS/term.cpp b/src/system/FreeRTOS/term.cpp index 0b6536a883f68dcc0e685afc3d5684adefea7aec..438ae68ac04ff0e250c4016e9108dce3a8656e15 100644 --- a/src/system/FreeRTOS/term.cpp +++ b/src/system/FreeRTOS/term.cpp @@ -1,7 +1,9 @@ #include #include +#if defined(ENABLE_MINISHELL) && (ENABLE_MINISHELL != 0) #include +#endif #include #include "bsp_sys.h" @@ -55,7 +57,7 @@ int printf(const char *format, ...) { return 0; } - +#if defined(ENABLE_MINISHELL) && (ENABLE_MINISHELL != 0) Term::Term() { bsp_usb_init(); @@ -123,7 +125,7 @@ Term::Term() { ms_cmd_add(&date); #endif - +#if defined(ENABLE_TINYUSB_TASK) && (ENABLE_TINYUSB_TASK != 0) auto usb_thread_fn = [](void *arg) { XB_UNUSED(arg); while (1) { @@ -134,7 +136,7 @@ Term::Term() { usb_thread.Create(usb_thread_fn, static_cast(0), "usb_thread", FREERTOS_USB_TASK_STACK_DEPTH, System::Thread::HIGH); - +#endif auto term_thread_fn = [](void *arg) { XB_UNUSED(arg); while (1) { @@ -155,7 +157,8 @@ Term::Term() { } } }; - term_thread.Create(term_thread_fn, static_cast(0), "term_thread", FREERTOS_TERM_TASK_STACK_DEPTH, System::Thread::REALTIME); } +#endif +