From: Keith Packard Date: Mon, 31 Oct 2016 02:08:14 +0000 (-0700) Subject: altos/nucleo-32: Add basic support for STM32F042 Nucleo-32 board X-Git-Tag: 1.7~210 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=e3d8ad6de7d2dfabe45a285b27f465ba68844f05 altos/nucleo-32: Add basic support for STM32F042 Nucleo-32 board This hooks up the LED, USB and the USART. Signed-off-by: Keith Packard --- diff --git a/src/nucleao-32/Makefile b/src/nucleao-32/Makefile new file mode 100644 index 00000000..a160fd2f --- /dev/null +++ b/src/nucleao-32/Makefile @@ -0,0 +1,71 @@ +# +# AltOS build +# +# + +include ../stmf0/Makefile.defs + +INC = \ + ao.h \ + ao_arch.h \ + ao_arch_funcs.h \ + ao_boot.h \ + ao_pins.h \ + ao_product.h \ + ao_task.h \ + stm32f0.h \ + Makefile + +ALTOS_SRC = \ + ao_boot_chain.c \ + ao_interrupt.c \ + ao_product.c \ + ao_romconfig.c \ + ao_cmd.c \ + ao_config.c \ + ao_task.c \ + ao_led.c \ + ao_dma_stm.c \ + ao_stdio.c \ + ao_panic.c \ + ao_timer.c \ + ao_mutex.c \ + ao_usb_stm.c \ + ao_serial_stm.c \ + ao_exti_stm.c + +PRODUCT=Nucleo-32 +PRODUCT_DEF=-DNUCLEO +IDPRODUCT=0x000a + +CFLAGS = $(PRODUCT_DEF) $(STMF0_CFLAGS) -Os -g + +PROGNAME=nucleo-32 +PROG=$(PROGNAME)-$(VERSION).elf +HEX=$(PROGNAME)-$(VERSION).ihx + +SRC=$(ALTOS_SRC) ao_nucleo.c +OBJ=$(SRC:.c=.o) + +all: $(PROG) $(HEX) + +$(PROG): Makefile $(OBJ) altos.ld + $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(LIBS) + +$(OBJ): $(INC) + +ao_product.h: ao-make-product.5c ../Version + $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@ + +load: $(PROG) + stm-load $(PROG) + +distclean: clean + +clean: + rm -f *.o $(PROGNAME)-*.elf $(PROGNAME)-*.ihx + rm -f ao_product.h + +install: + +uninstall: diff --git a/src/nucleao-32/ao_nucleo.c b/src/nucleao-32/ao_nucleo.c new file mode 100644 index 00000000..cda889c6 --- /dev/null +++ b/src/nucleao-32/ao_nucleo.c @@ -0,0 +1,63 @@ +/* + * Copyright © 2016 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include + +static uint16_t blink_delay, blink_running; + +static void blink(void) { + blink_running = 1; + while (blink_delay) { + ao_led_on(AO_LED_GREEN); + ao_delay(blink_delay); + ao_led_off(AO_LED_GREEN); + ao_delay(blink_delay); + } + blink_running = 0; + ao_wakeup(&blink_running); + ao_exit(); +} + +struct ao_task blink_task; + +static void blink_cmd() { + ao_cmd_decimal(); + blink_delay = ao_cmd_lex_i; + if (blink_delay && !blink_running) + ao_add_task(&blink_task, blink, "blink"); + if (!blink_delay) + while (blink_running) + ao_sleep(&blink_running); +} + +static const struct ao_cmds blink_cmds[] = { + { blink_cmd, "b \0Blink the green LED" }, + { 0, 0 } +}; + +void main(void) +{ + ao_led_init(LEDS_AVAILABLE); + ao_clock_init(); + ao_task_init(); + ao_timer_init(); + ao_dma_init(); + ao_usb_init(); + ao_serial_init(); + ao_cmd_init(); + ao_cmd_register(blink_cmds); + ao_start_scheduler(); +} + + diff --git a/src/nucleao-32/ao_pins.h b/src/nucleao-32/ao_pins.h new file mode 100644 index 00000000..76200176 --- /dev/null +++ b/src/nucleao-32/ao_pins.h @@ -0,0 +1,56 @@ +/* + * Copyright © 2016 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#ifndef _AO_PINS_H_ +#define _AO_PINS_H_ + +#define LED_PORT_ENABLE STM_RCC_AHBENR_IOPBEN +#define LED_PORT (&stm_gpiob) +#define LED_PIN_GREEN 3 +#define AO_LED_GREEN (1 << LED_PIN_GREEN) +#define AO_LED_PANIC AO_LED_GREEN + +#define LEDS_AVAILABLE (AO_LED_GREEN) + +#define AO_POWER_MANAGEMENT 0 + +/* 48MHz clock based on USB */ +#define AO_HSI48 1 + +/* HCLK = 48MHz */ +#define AO_AHB_PRESCALER 1 +#define AO_RCC_CFGR_HPRE_DIV STM_RCC_CFGR_HPRE_DIV_1 + +/* APB = 48MHz */ +#define AO_APB_PRESCALER 1 +#define AO_RCC_CFGR_PPRE_DIV STM_RCC_CFGR_PPRE_DIV_1 + +#define HAS_USB 1 +#define AO_USB_DIRECTIO 0 +#define AO_PA11_PA12_RMP 0 +#define HAS_BEEP 0 + +#define IS_FLASH_LOADER 0 + +#define HAS_SERIAL_2 1 +#define SERIAL_2_PA2_PA15 1 +#define USE_SERIAL_2_FLOW 0 +#define USE_SERIAL_2_STDIN 1 +#define DELAY_SERIAL_2_STDIN 0 + +#endif /* _AO_PINS_H_ */ diff --git a/src/nucleao-32/flash-loader/Makefile b/src/nucleao-32/flash-loader/Makefile new file mode 100644 index 00000000..2392e998 --- /dev/null +++ b/src/nucleao-32/flash-loader/Makefile @@ -0,0 +1,8 @@ +# +# AltOS flash loader build +# +# + +TOPDIR=../.. +HARDWARE=nucleo-32 +include $(TOPDIR)/stmf0/Makefile-flash.defs diff --git a/src/nucleao-32/flash-loader/ao_pins.h b/src/nucleao-32/flash-loader/ao_pins.h new file mode 100644 index 00000000..8bdbdb1a --- /dev/null +++ b/src/nucleao-32/flash-loader/ao_pins.h @@ -0,0 +1,37 @@ +/* + * Copyright © 2016 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#ifndef _AO_PINS_H_ +#define _AO_PINS_H_ + +#include + +/* Pin D3, which is PB0 */ + +#define AO_BOOT_PIN 1 +#define AO_BOOT_APPLICATION_GPIO stm_gpiob +#define AO_BOOT_APPLICATION_PIN 0 +#define AO_BOOT_APPLICATION_VALUE 1 +#define AO_BOOT_APPLICATION_MODE AO_EXTI_MODE_PULL_UP + +/* USB */ +#define HAS_USB 1 +#define AO_USB_DIRECTIO 0 +#define AO_PA11_PA12_RMP 0 + +#endif /* _AO_PINS_H_ */