From 5611462c089599e5318eb565c7fb38d45a1e19dc Mon Sep 17 00:00:00 2001 From: jmug Date: Sun, 18 May 2025 23:06:58 -0700 Subject: [PATCH] Add the assembly blink to the sdk examble. Signed-off-by: jmug --- CMakeLists.txt | 1 + hello_world.c | 15 +++++++++------ led.s | 25 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 led.s diff --git a/CMakeLists.txt b/CMakeLists.txt index a006037..891544c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ pico_sdk_init() # rest of your project add_executable(hello_world hello_world.c + led.s ) # Add pico_stdlib library which aggregates commonly used features diff --git a/hello_world.c b/hello_world.c index e588b0e..668c54f 100644 --- a/hello_world.c +++ b/hello_world.c @@ -41,13 +41,16 @@ void pico_set_led(bool led_on) { #endif } +void blink(); + int main() { int rc = pico_led_init(); hard_assert(rc == PICO_OK); - while (true) { - pico_set_led(true); - sleep_ms(LED_DELAY_MS); - pico_set_led(false); - sleep_ms(LED_DELAY_MS); - } + blink(); + /* while (true) { */ + /* pico_set_led(true); */ + /* sleep_ms(LED_DELAY_MS); */ + /* pico_set_led(false); */ + /* sleep_ms(LED_DELAY_MS); */ + /* } */ } diff --git a/led.s b/led.s new file mode 100644 index 0000000..3135625 --- /dev/null +++ b/led.s @@ -0,0 +1,25 @@ +.section .text +.equ sio_base, 0xd0000000 +.equ big_num, 0x00f00000 // For the delay. + +.thumb_func +.global blink +blink: + ldr r0, =sio_base + mov r1, #1 + lsl r1, r1, #25 +led_loop: + str r1, [r0, #0x18] // GPIO_OUT_SET + ldr r3, =big_num + bl delay + + str r1, [r0, #0x20] // GPIO_OUT_CLR + ldr r3, =big_num + bl delay + + b led_loop + +delay: + sub r3, #1 + bne delay + bx lr