From 0de96b017a8f11c2abe1a256ba4d1524b58da4c2 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 30 Jul 2023 16:36:04 +0000 Subject: [PATCH] STM32C031 demo compiles, ready for testing. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@16353 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- demos/STM32/NIL-STM32C031C6-NUCLEO64/Makefile | 4 +- demos/STM32/NIL-STM32C031C6-NUCLEO64/main.c | 72 ++++++++++++++++++- os/hal/ports/STM32/STM32C0xx/hal_lld.h | 5 ++ 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/demos/STM32/NIL-STM32C031C6-NUCLEO64/Makefile b/demos/STM32/NIL-STM32C031C6-NUCLEO64/Makefile index 6603cfa20..7f01302fb 100644 --- a/demos/STM32/NIL-STM32C031C6-NUCLEO64/Makefile +++ b/demos/STM32/NIL-STM32C031C6-NUCLEO64/Makefile @@ -109,8 +109,8 @@ include $(CHIBIOS)/os/common/ports/ARMv6-M/compilers/GCC/mk/port.mk # Auto-build files in ./source recursively. include $(CHIBIOS)/tools/mk/autobuild.mk # Other files (optional). -#include $(CHIBIOS)/os/test/test.mk -#include $(CHIBIOS)/test/nil/nil_test.mk +include $(CHIBIOS)/os/test/test.mk +include $(CHIBIOS)/test/nil/nil_test.mk #include $(CHIBIOS)/test/oslib/oslib_test.mk # Define linker script file here diff --git a/demos/STM32/NIL-STM32C031C6-NUCLEO64/main.c b/demos/STM32/NIL-STM32C031C6-NUCLEO64/main.c index 7ef08096a..e6e8f1087 100644 --- a/demos/STM32/NIL-STM32C031C6-NUCLEO64/main.c +++ b/demos/STM32/NIL-STM32C031C6-NUCLEO64/main.c @@ -14,13 +14,83 @@ limitations under the License. */ -#include +#include "hal.h" +#include "ch.h" +#include "nil_test_root.h" +//#include "oslib_test_root.h" + +/* + * Blinker thread #1. + */ +static THD_WORKING_AREA(waThread1, 128); +static THD_FUNCTION(Thread1, arg) { + + (void)arg; + + while (true) { + while (true) { + palClearLine(LINE_LED_GREEN); + chThdSleepMilliseconds(500); + palSetLine(LINE_LED_GREEN); + chThdSleepMilliseconds(500); + } + } +} + +/* + * Tester thread. + */ +THD_WORKING_AREA(waThread3, 256); +THD_FUNCTION(Thread3, arg) { + + (void)arg; + + /* + * Activates the serial driver 1 using the driver default configuration. + * PA9 and PA10 are routed to USART1. + */ + sdStart(&SD2, NULL); + + /* Welcome message.*/ + chnWrite(&SD2, (const uint8_t *)"Hello World!\r\n", 14); + + /* Waiting for button push and activation of the test suite.*/ + while (true) { + if (palReadLine(LINE_BUTTON) == PAL_LOW) { + test_execute((BaseSequentialStream *)&SD2, &nil_test_suite); + //test_execute((BaseSequentialStream *)&SD2, &oslib_test_suite); + } + chThdSleepMilliseconds(500); + } +} + +/* + * Threads creation table, one entry per thread. + */ +THD_TABLE_BEGIN + THD_TABLE_THREAD(0, "blinker1", waThread1, Thread1, NULL) + THD_TABLE_THREAD(4, "tester", waThread3, Thread3, NULL) +THD_TABLE_END /* * Application entry point. */ int main(void) { + /* + * System initializations. + * - HAL initialization, this also initializes the configured device drivers + * and performs the board-specific initializations. + * - Kernel initialization, the main() function becomes a thread and the + * RTOS is active. + */ + halInit(); + chSysInit(); + + /* This is now the idle thread loop, you may perform here a low priority + task but you must never try to sleep or wait in this loop. Note that + this tasks runs at the lowest priority level so any instruction added + here will be executed after all other tasks have been started.*/ while (true) { } } diff --git a/os/hal/ports/STM32/STM32C0xx/hal_lld.h b/os/hal/ports/STM32/STM32C0xx/hal_lld.h index e188a5c57..49cd5dbf2 100644 --- a/os/hal/ports/STM32/STM32C0xx/hal_lld.h +++ b/os/hal/ports/STM32/STM32C0xx/hal_lld.h @@ -870,6 +870,11 @@ #error "invalid source selected for USART1 clock" #endif +/** + * @brief USART2 clock frequency. + */ +#define STM32_USART2CLK hal_lld_get_clock_point(CLK_PCLK) + /** * @brief I2C1 clock frequency. */