From 045a1e20d5699387929e12bb42e98bf1df7daa6b Mon Sep 17 00:00:00 2001 From: rmanach Date: Fri, 21 Feb 2025 12:50:04 +0100 Subject: [PATCH] typo + main fixes --- Makefile | 6 +++--- README.md | 2 +- config/FreeRTOSConfig.h | 3 +-- simple_led/main.c | 39 +++++++++++++++++++++++---------------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 48f0647..33032f0 100644 --- a/Makefile +++ b/Makefile @@ -24,14 +24,14 @@ ifeq ($(strip $(name)), "") @false endif -project: .check-name - @./scripts/scaffold_project.bash $(name) $(SDK_VERSION) - ifeq ($(shell test -d $(name) && echo "ok"),) @echo "error: project $(name) does not exist" @false endif +project: .check-name + @./scripts/scaffold_project.bash $(name) $(SDK_VERSION) + format: .check-name @test -f "$(shell find /usr/bin/ -name astyle)" && astyle --style=java --indent=spaces=4 -K -xC120 $(name)/*.c diff --git a/README.md b/README.md index 734857d..b1b9040 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ make push name= **NOTE**: you have to USB plug your Pico device in **BOOTSEL** mode before executing the command. -After the load, the device will automatically reboot and be unpluged. And the program fresly pushed will start. +After the load, the device will automatically reboot and be unpluged. And the program freshly pushed will start. ## Get device info When plugging your device in **BOOTSEL** mode, you can get the device information using: diff --git a/config/FreeRTOSConfig.h b/config/FreeRTOSConfig.h index fbee0ef..e9afd14 100644 --- a/config/FreeRTOSConfig.h +++ b/config/FreeRTOSConfig.h @@ -61,9 +61,8 @@ #define configENABLE_FPU 1 // 1: Enable Floating Point Unit #define configUSE_TASK_FPU_SUPPORT 1 // Enable FPU context save/restore #define configENABLE_TRUSTZONE 0 // 1: Enable TrustZone -#define configRUN_FREERTOS_SECURE_ONLY 0 // Non-secure mode to match port -#define configENABLE_MPU 0 // 1: Enable Memory Protection Unit (defined twice in original) #define configRUN_FREERTOS_SECURE_ONLY 1 // 1: Run in secure mode only +#define configENABLE_MPU 0 // 1: Enable Memory Protection Unit (defined twice in original) #define configUSE_16_BIT_TICKS 0 // 0: Use 32-bit ticks, 1: Use 16-bit ticks // SMP Configuration diff --git a/simple_led/main.c b/simple_led/main.c index 33eec00..fb55d3d 100644 --- a/simple_led/main.c +++ b/simple_led/main.c @@ -38,16 +38,18 @@ struct params { state *s; }; -static state global_state = { - .counter = 0, - .can_incr = true, - .on_reset = false, - .is_reset = false, - .status = RUNNING, -}; - void init_state(state *s) { - s->lock = xSemaphoreCreateMutex(); + if (s != NULL) { + *s = (state) { + .counter = 0, + .can_incr = true, + .on_reset = false, + .is_reset = false, + .status = RUNNING, + }; + + s->lock = xSemaphoreCreateMutex(); + } } void incr_counter(state *s) { @@ -112,9 +114,11 @@ bool is_resetting(state *s) { } void reset(state *s) { - s->push_clock = 0; - s->counter = 0; - s->is_reset = true; + if (s != NULL) { + s->push_clock = 0; + s->counter = 0; + s->is_reset = true; + } } void blink_success(uint gpio, uint32_t delay_ms, bool in_task) { @@ -239,7 +243,7 @@ void run_led_control(state *s) { /** * Initialize needed GPIO. */ -void init_gpio() { +void init_gpio(void) { #ifdef PICO_DEFAULT_LED_PIN gpio_init(PICO_DEFAULT_LED_PIN); gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); @@ -253,7 +257,7 @@ void init_gpio() { } /** - * Callback when unable to initialize task (not enough stask memory). + * Callback when unable to initialize task (not enough stack memory). * Increase `uxStackDepth` arg when creating task if needed. */ void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName) { @@ -276,17 +280,20 @@ void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName) { * You can then push the button and see the red led lights on. * After 10 pushed, the red light lights off and the default led too. * To reset the application, holds the button ~2 secs, the red light will - * blink two time and the application will be started again. + * blink three times and the application will be started again. * */ -int main() { +int main(void) { stdio_init_all(); init_gpio(); + state global_state; init_state(&global_state); run_health(&global_state); run_led_control(&global_state); vTaskStartScheduler(); + + blink_failed(PICO_DEFAULT_LED_PIN, 200, false); } \ No newline at end of file