Skip to content

Commit

Permalink
Rearrange MCU namespace so that STM32 is one subtype.
Browse files Browse the repository at this point in the history
This will allow fitting AT32 alongside, which is an "almost" STM32 clone
with a slightly different and confusing naming scheme.
  • Loading branch information
keirf committed Apr 27, 2021
1 parent fb93abe commit 2809d34
Show file tree
Hide file tree
Showing 35 changed files with 60 additions and 60 deletions.
8 changes: 4 additions & 4 deletions Makefile
Expand Up @@ -26,10 +26,10 @@ all: scripts/greaseweazle/version.py
srec_cat bootloader/Bootloader.hex -Intel src/$(PROJ).hex -Intel \
-o $(PROJ)-$(VER).hex -Intel
$(PYTHON) ./scripts/mk_update.py new $(PROJ)-$(VER).upd \
bootloader/Bootloader.bin src/$(PROJ).bin $(stm32)
bootloader/Bootloader.bin src/$(PROJ).bin $(mcu)

blinky:
$(MAKE) debug=y stm32=f1 -C blinky_test -f $(ROOT)/Rules.mk \
$(MAKE) debug=y mcu=stm32f1 -C blinky_test -f $(ROOT)/Rules.mk \
Blinky.elf Blinky.bin Blinky.hex

clean::
Expand All @@ -45,7 +45,7 @@ dist:
mkdir -p $(PROJ)-$(VER)/scripts/misc
mkdir -p $(PROJ)-$(VER)/alt
$(MAKE) clean
$(MAKE) stm32=f1 all blinky
$(MAKE) mcu=stm32f1 all blinky
cp -a $(PROJ)-$(VER).hex $(PROJ)-$(VER)/$(PROJ)-F1-$(VER).hex
cp -a $(PROJ)-$(VER).upd $(PROJ)-$(VER)/$(PROJ)-$(VER).upd
cp -a blinky_test/Blinky.hex $(PROJ)-$(VER)/alt/Blinky_Test-$(VER).hex
Expand All @@ -60,7 +60,7 @@ dist:
cp -a scripts/misc/*.py $(PROJ)-$(VER)/scripts/misc/
cp -a RELEASE_NOTES $(PROJ)-$(VER)/
$(MAKE) clean
$(MAKE) stm32=f7 all
$(MAKE) mcu=stm32f7 all
cp -a $(PROJ)-$(VER).hex $(PROJ)-$(VER)/$(PROJ)-F7-$(VER).hex
$(PYTHON) ./scripts/mk_update.py cat $(PROJ)-$(VER)/$(PROJ)-$(VER).upd \
$(PROJ)-$(VER)/$(PROJ)-$(VER).upd $(PROJ)-$(VER).upd
Expand Down
8 changes: 4 additions & 4 deletions Rules.mk
Expand Up @@ -24,11 +24,11 @@ FLAGS += -fno-common -fno-exceptions -fno-strict-aliasing
FLAGS += -mlittle-endian -mthumb -mfloat-abi=soft
FLAGS += -Wno-unused-value -ffunction-sections

ifeq ($(stm32),f1)
FLAGS += -mcpu=cortex-m3 -DSTM32F=1
ifeq ($(mcu),stm32f1)
FLAGS += -mcpu=cortex-m3 -DSTM32F1=1 -DMCU=1
stm32f1=y
else ifeq ($(stm32),f7)
FLAGS += -mcpu=cortex-m7 -DSTM32F=7
else ifeq ($(mcu),stm32f7)
FLAGS += -mcpu=cortex-m7 -DSTM32F7=7 -DMCU=7
stm32f7=y
endif

Expand Down
2 changes: 1 addition & 1 deletion blinky_test/f1/Makefile
@@ -1,4 +1,4 @@
RPATH = $(ROOT)/src/f1
RPATH = $(ROOT)/src/mcu/stm32f1

OBJS += stm32.o
OBJS += fpec.o
4 changes: 2 additions & 2 deletions bootloader/Bootloader.ld.S
@@ -1,10 +1,10 @@

#if STM32F == 1
#if MCU == STM32F1

#define FLASH_BASE 0x08000000
#define FLASH_LEN 8K

#elif STM32F == 7
#elif MCU == STM32F7

#define FLASH_BASE 0x08000000
#define FLASH_LEN 16K
Expand Down
4 changes: 1 addition & 3 deletions bootloader/Makefile
Expand Up @@ -13,9 +13,7 @@ OBJS += util.o

OBJS-$(debug) += console.o

SUBDIRS += usb
SUBDIRS-$(stm32f1) += f1
SUBDIRS-$(stm32f7) += f7
SUBDIRS += mcu usb

.PHONY: $(RPATH)/build_info.c
build_info.o: CFLAGS += -DFW_MAJOR=$(FW_MAJOR) -DFW_MINOR=$(FW_MINOR)
2 changes: 2 additions & 0 deletions bootloader/mcu/Makefile
@@ -0,0 +1,2 @@
SUBDIRS-$(stm32f1) += stm32f1
SUBDIRS-$(stm32f7) += stm32f7
2 changes: 1 addition & 1 deletion bootloader/f1/Makefile → bootloader/mcu/stm32f1/Makefile
@@ -1,4 +1,4 @@
RPATH = $(ROOT)/src/f1
RPATH = $(ROOT)/src/mcu/stm32f1

OBJS += stm32.o
OBJS += fpec.o
2 changes: 1 addition & 1 deletion bootloader/f7/Makefile → bootloader/mcu/stm32f7/Makefile
@@ -1,4 +1,4 @@
RPATH = $(ROOT)/src/f7
RPATH = $(ROOT)/src/mcu/stm32f7

OBJS += stm32.o
OBJS += fpec.o
16 changes: 8 additions & 8 deletions inc/decls.h
Expand Up @@ -16,14 +16,14 @@
#include <limits.h>

#include "util.h"
#include "stm32/common_regs.h"
#include "stm32/common.h"
#if STM32F == 1
#include "stm32/f1_regs.h"
#include "stm32/f1.h"
#elif STM32F == 7
#include "stm32/f7_regs.h"
#include "stm32/f7.h"
#include "mcu/stm32/common_regs.h"
#include "mcu/stm32/common.h"
#if MCU == STM32F1
#include "mcu/stm32/f1_regs.h"
#include "mcu/stm32/f1.h"
#elif MCU == STM32F7
#include "mcu/stm32/f7_regs.h"
#include "mcu/stm32/f7.h"
#endif
#include "intrinsics.h"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion scripts/mk_update.py
Expand Up @@ -46,7 +46,7 @@ def mk_cat_entry(dat, hw_model, sig):

def new_upd(argv):
dat = b'GWUP'
hw_model = int(re.match("f(\d)", argv[2]).group(1))
hw_model = int(re.match("\w+f(\d)$", argv[2]).group(1))
with open(argv[1], "rb") as gw_f:
dat += mk_cat_entry(gw_f.read(), hw_model, b'GW')
with open(argv[0], "rb") as bl_f:
Expand Down
6 changes: 3 additions & 3 deletions scripts/stm32.ld.S
Expand Up @@ -3,9 +3,9 @@ ENTRY(vector_table)
MEMORY
{
FLASH (rx) : ORIGIN = FLASH_BASE, LENGTH = FLASH_LEN
#if STM32F == 1
#if MCU == STM32F1
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
#elif STM32F == 7
#elif MCU == STM32F7
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
EXT_RAM (rwx) : ORIGIN = 0x20010000, LENGTH = 192K
#endif
Expand Down Expand Up @@ -51,7 +51,7 @@ SECTIONS
_ebss = .;
} >RAM

#if STM32F == 7
#if MCU == STM32F7
.ext_ram (NOLOAD) : {
. = ALIGN(8);
_ext_ram_start = .;
Expand Down
4 changes: 2 additions & 2 deletions src/Greaseweazle.ld.S
@@ -1,10 +1,10 @@

#if STM32F == 1
#if MCU == STM32F1

#define FLASH_BASE 0x08002000
#define FLASH_LEN 56K

#elif STM32F == 7
#elif MCU == STM32F7

#define FLASH_BASE 0x08004000
#define FLASH_LEN 48K
Expand Down
4 changes: 1 addition & 3 deletions src/Makefile
Expand Up @@ -12,9 +12,7 @@ OBJS += floppy.o

OBJS-$(debug) += console.o

SUBDIRS += usb
SUBDIRS-$(stm32f1) += f1
SUBDIRS-$(stm32f7) += f7
SUBDIRS += mcu usb

.PHONY: build_info.c
build_info.o: CFLAGS += -DFW_MAJOR=$(FW_MAJOR) -DFW_MINOR=$(FW_MINOR)
8 changes: 4 additions & 4 deletions src/board.c
Expand Up @@ -20,10 +20,10 @@ static void gpio_pull_up_pins(GPIO gpio, uint16_t mask)
}
}

#if STM32F == 1
#include "f1/board.c"
#elif STM32F == 7
#include "f7/board.c"
#if MCU == STM32F1
#include "mcu/stm32f1/board.c"
#elif MCU == STM32F7
#include "mcu/stm32f7/board.c"
#endif

void board_init(void)
Expand Down
16 changes: 8 additions & 8 deletions src/console.c
Expand Up @@ -13,21 +13,21 @@
#define BAUD 3000000 /* 3Mbaud */
#endif

#if STM32F == 1
#if MCU == STM32F1
#define PCLK SYSCLK
#elif STM32F == 7
#elif MCU == STM32F7
#define PCLK (APB2_MHZ * 1000000)
#endif

#define USART1_IRQ 37

static void ser_putc(uint8_t c)
{
#if STM32F == 1
#if MCU == STM32F1
while (!(usart1->sr & USART_SR_TXE))
cpu_relax();
usart1->dr = c;
#elif STM32F == 7
#elif MCU == STM32F7
while (!(usart1->isr & USART_ISR_TXE))
cpu_relax();
usart1->tdr = c;
Expand Down Expand Up @@ -83,10 +83,10 @@ void console_init(void)
peripheral_clock_delay();

/* Enable TX pin (PA9) for USART output, RX pin (PA10) as input. */
#if STM32F == 1
#if MCU == STM32F1
gpio_configure_pin(gpioa, 9, AFO_pushpull(_10MHz));
gpio_configure_pin(gpioa, 10, GPI_pull_up);
#elif STM32F == 7
#elif MCU == STM32F7
gpio_set_af(gpioa, 9, 7);
gpio_set_af(gpioa, 10, 7);
gpio_configure_pin(gpioa, 9, AFO_pushpull(IOSPD_MED));
Expand All @@ -102,9 +102,9 @@ void console_init(void)
* any serial input to cause a crash dump of the stuck context. */
void console_crash_on_input(void)
{
#if STM32F == 1
#if MCU == STM32F1
(void)usart1->dr; /* clear UART_SR_RXNE */
#elif STM32F == 7
#elif MCU == STM32F7
usart1->rqr = USART_RQR_RXFRQ; /* clear ISR_RXNE */
usart1->icr = USART_ICR_ORECF; /* clear ISR_ORE */
#endif
Expand Down
12 changes: 6 additions & 6 deletions src/floppy.c
Expand Up @@ -45,10 +45,10 @@ static const struct gw_delay factory_delay_params = {
.watchdog = 10000
};

#if STM32F == 1
#include "f1/floppy.c"
#elif STM32F == 7
#include "f7/floppy.c"
#if MCU == STM32F1
#include "mcu/stm32f1/floppy.c"
#elif MCU == STM32F7
#include "mcu/stm32f7/floppy.c"
#endif

static struct index {
Expand Down Expand Up @@ -356,7 +356,7 @@ struct gw_info gw_info = {
.is_main_firmware = 1,
.max_cmd = CMD_MAX,
.sample_freq = 72000000u,
.hw_model = STM32F
.hw_model = MCU
};

static void watchdog_kick(void)
Expand Down Expand Up @@ -1318,7 +1318,7 @@ static void process_command(void)
sink_source_prep(&ssb);
break;
}
#if STM32F == 7
#if MCU == STM32F7
case CMD_SWITCH_FW_MODE: {
uint8_t mode = u_buf[2];
if ((len != 3) || (mode & ~1))
Expand Down
12 changes: 6 additions & 6 deletions src/fw_update.c
Expand Up @@ -9,11 +9,11 @@
* See the file COPYING for more details, or visit <http://unlicense.org>.
*/

#if STM32F == 1
#if MCU == STM32F1
/* 8kB-64kB (56kB total) */
#define FIRMWARE_START 0x08002000
#define FIRMWARE_END 0x08010000
#elif STM32F == 7
#elif MCU == STM32F7
/* 16kB-64KB (48kB total) */
#define FIRMWARE_START 0x08004000
#define FIRMWARE_END 0x08010000
Expand All @@ -40,7 +40,7 @@ static bool_t upd_strapped;
struct gw_info gw_info = {
.is_main_firmware = 0,
.max_cmd = CMD_MAX,
.hw_model = STM32F
.hw_model = MCU
};

static void blink_init(void)
Expand Down Expand Up @@ -159,7 +159,7 @@ static void process_command(void)
update_prep(u_len);
break;
}
#if STM32F == 7
#if MCU == STM32F7
case CMD_SWITCH_FW_MODE: {
uint8_t mode = u_buf[2];
if ((len != 3) || (mode & ~1))
Expand Down Expand Up @@ -223,7 +223,7 @@ static void update_process(void)
}
}

#if STM32F == 1
#if MCU == STM32F1

static bool_t enter_bootloader(void)
{
Expand All @@ -247,7 +247,7 @@ static bool_t enter_bootloader(void)
return upd_strapped;
}

#elif STM32F == 7
#elif MCU == STM32F7

static bool_t check_update_requested(void)
{
Expand Down
2 changes: 2 additions & 0 deletions src/mcu/Makefile
@@ -0,0 +1,2 @@
SUBDIRS-$(stm32f1) += stm32f1
SUBDIRS-$(stm32f7) += stm32f7
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/timer.c
Expand Up @@ -9,12 +9,12 @@
* See the file COPYING for more details, or visit <http://unlicense.org>.
*/

#if STM32F == 1
#if MCU == STM32F1
void IRQ_25(void) __attribute__((alias("IRQ_timer")));
#define TIMER_IRQ 25
#define tim tim1
#define tim_bits 16
#elif STM32F == 7
#elif MCU == STM32F7
void IRQ_50(void) __attribute__((alias("IRQ_timer")));
#define TIMER_IRQ 50
#define tim tim5 /* 32-bit timer */
Expand Down Expand Up @@ -114,7 +114,7 @@ void timer_cancel(struct timer *timer)

void timers_init(void)
{
#if STM32F == 7
#if MCU == STM32F7
rcc->apb1enr |= RCC_APB1ENR_TIM5EN;
peripheral_clock_delay();
#endif
Expand Down

0 comments on commit 2809d34

Please sign in to comment.