From 9eff782ffe349e946c19f4df32c56faaaa5aa64c Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Sat, 6 Aug 2022 13:53:11 -0700 Subject: [PATCH] simple code that blinks the led.. --- blinkled/Makefile | 52 +++++++++++++++++++++++++++++++++++ blinkled/main.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 blinkled/Makefile create mode 100644 blinkled/main.c diff --git a/blinkled/Makefile b/blinkled/Makefile new file mode 100644 index 0000000..ead20eb --- /dev/null +++ b/blinkled/Makefile @@ -0,0 +1,52 @@ +# Copyright 2021 John-Mark Gurney. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +.if $(.OBJDIR) == $(.CURDIR) +.error Need to set MAKEOBJDIR. +.endif + +PLATFORM != uname -s + +.if $(PLATFORM) == "Darwin" +SOEXT=dylib +.else +.error Unsupported platform: $(PLATFORM) +.endif + +PROGS = blinkled + +SRCS.blinkled = main.c +SRCS.blinkled+= $(SRCTOP)/rs485hid/memdebug.c + +CFLAGS+= -I$(.CURDIR) +CFLAGS+= -g +#CFLAGS+= -DNDEBUG + +WITH_STM32F103 = yes + +.include <../mk/boards.mk> + +CFLAGS+= -Werror -Wall + +.include <../mk/mu.progs.mk> diff --git a/blinkled/main.c b/blinkled/main.c new file mode 100644 index 0000000..77c1774 --- /dev/null +++ b/blinkled/main.c @@ -0,0 +1,70 @@ +/*- + * Copyright 2021 John-Mark Gurney. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include + +#include + +#include + +#include + +static void +c13led(const void *none) +{ + GPIO_InitTypeDef GPIO_InitStruct; + + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOC_CLK_ENABLE(); + + GPIO_InitStruct = (GPIO_InitTypeDef){ + .Pin = GPIO_PIN_13, + .Mode = GPIO_MODE_OUTPUT_PP, + .Pull = GPIO_NOPULL, + .Speed = GPIO_SPEED_FREQ_LOW, + }; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); +} +SYSINIT(c13led, SI_SUB_HAL, SI_ORDER_SECOND, c13led, NULL); + +int +main(void) +{ + + sysinit_run(); + + debug_printf("starting...\n"); + + /* toggle on LED */ + for (;;) { + HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); + HAL_Delay(250); + HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET); + HAL_Delay(250); + } +}