Skip to content

Commit

Permalink
AT32F435: Initial port
Browse files Browse the repository at this point in the history
  • Loading branch information
keirf committed Mar 10, 2022
1 parent 71d33fb commit 7f5642a
Show file tree
Hide file tree
Showing 44 changed files with 2,463 additions and 509 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ dist:
mkdir -p flashfloppy-$(VER)/alt/io-test
mkdir -p flashfloppy-$(VER)/alt/quickdisk/logfile
$(MAKE) clean
$(MAKE) gotek
$(MAKE) mcu=stm32f105 gotek
cp -a FF_Gotek-$(VER).dfu flashfloppy-$(VER)/
cp -a FF_Gotek-$(VER).upd flashfloppy-$(VER)/
cp -a FF_Gotek-$(VER).hex flashfloppy-$(VER)/
cp -a FF_Gotek-Bootloader-$(VER).upd flashfloppy-$(VER)/alt/bootloader/
cp -a FF_Gotek-IO-Test-$(VER).upd flashfloppy-$(VER)/alt/io-test/
$(MAKE) clean
$(MAKE) debug=n logfile=y -f $(ROOT)/Rules.mk upd
$(MAKE) mcu=stm32f105 debug=n logfile=y -f $(ROOT)/Rules.mk upd
mv FF.upd flashfloppy-$(VER)/alt/logfile/FF_Gotek-Logfile-$(VER).upd
$(MAKE) clean
$(MAKE) quickdisk=y -f $(ROOT)/Rules.mk upd
$(MAKE) mcu=stm32f105 quickdisk=y -f $(ROOT)/Rules.mk upd
mv FF.upd flashfloppy-$(VER)/alt/quickdisk/FF_Gotek-QuickDisk-$(VER).upd
$(MAKE) clean
$(MAKE) quickdisk=y debug=n logfile=y -f $(ROOT)/Rules.mk upd
$(MAKE) mcu=stm32f105 quickdisk=y debug=n logfile=y -f $(ROOT)/Rules.mk upd
mv FF.upd flashfloppy-$(VER)/alt/quickdisk/logfile/FF_Gotek-QuickDisk-Logfile-$(VER).upd
python3 scripts/mk_qd.py --window=6.5 flashfloppy-$(VER)/alt/quickdisk/Blank.qd
$(MAKE) clean
Expand Down Expand Up @@ -81,7 +81,7 @@ upd:

all:
$(MAKE) -C src -f $(ROOT)/Rules.mk $(PROJ).elf $(PROJ).bin $(PROJ).hex
$(MAKE) bootloader=y logfile=n debug=n -C bootloader \
$(MAKE) bootloader=y logfile=n -C bootloader \
-f $(ROOT)/Rules.mk \
Bootloader.elf Bootloader.bin Bootloader.hex
$(MAKE) logfile=n -C bl_update -f $(ROOT)/Rules.mk \
Expand All @@ -99,15 +99,16 @@ endif

BAUD=115200
DEV=/dev/ttyUSB0
STM32FLASH=stm32flash

ocd: gotek
python3 scripts/openocd/flash.py `pwd`/FF_Gotek-$(VER).hex

flash: gotek
sudo stm32flash -b $(BAUD) -w FF_Gotek-$(VER).hex $(DEV)
sudo $(STM32FLASH) -b $(BAUD) -w FF_Gotek-$(VER).hex $(DEV)

start:
sudo stm32flash -b $(BAUD) -g 0 $(DEV)
sudo $(STM32FLASH) -b $(BAUD) -g 0 $(DEV)

serial:
sudo miniterm.py $(DEV) 3000000
17 changes: 16 additions & 1 deletion Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,24 @@ FLAGS = -g -Os -nostdlib -std=gnu99 -iquote $(ROOT)/inc
FLAGS += -Wall -Werror -Wno-format -Wdeclaration-after-statement
FLAGS += -Wstrict-prototypes -Wredundant-decls -Wnested-externs
FLAGS += -fno-common -fno-exceptions -fno-strict-aliasing
FLAGS += -mlittle-endian -mthumb -mcpu=cortex-m3 -mfloat-abi=soft
FLAGS += -mlittle-endian -mthumb -mfloat-abi=soft
FLAGS += -Wno-unused-value -ffunction-sections

## STM32F105
ifeq ($(mcu),stm32f105)
FLAGS += -mcpu=cortex-m3 -DSTM32F105=1 -DMCU=1
stm32f105=y
ifeq ($(bootloader),y)
# Debug bootloader doesn't fit in 32kB
override debug=n
endif

## AT32F435
else ifeq ($(mcu),at32f435)
FLAGS += -mcpu=cortex-m4 -DAT32F435=4 -DMCU=4
at32f435=y
endif

ifneq ($(debug),y)
FLAGS += -DNDEBUG
endif
Expand Down
4 changes: 2 additions & 2 deletions bl_update/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
RPATH = ../src

OBJS += bl_update.o
OBJS += fpec.o
OBJS += fpec_$(mcu).o

OBJS += build_info.o
OBJS += crc.o
OBJS += vectors.o
OBJS += string.o
OBJS += stm32f10x.o
OBJS += cortex.o mcu_$(mcu).o
OBJS += time.o
OBJS += timer.o
OBJS += util.o
Expand Down
2 changes: 1 addition & 1 deletion bl_update/display/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RPATH = ../../src/display

OBJS += display.o
OBJS += lcd.o
OBJS += lcd_$(mcu).o
OBJS += oled_font_6x13.o
OBJS += led_7seg.o
12 changes: 11 additions & 1 deletion bootloader/Bootloader.ld.S
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@

#if MCU == STM32F105

#define FLASH_BASE 0x08000000
#define FLASH_LEN 32K

#elif MCU == AT32F435

#define FLASH_BASE 0x08000000
#define FLASH_LEN 48K

#endif

#define RAM_BASE 0x20000000
#define RAM_LEN 16K

#include "../scripts/stm32f10x.ld.S"
#include "../scripts/stm32.ld.S"
4 changes: 2 additions & 2 deletions bootloader/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RPATH = ../src

OBJS += fw_update.o
OBJS += fpec.o
OBJS += fpec_$(mcu).o

OBJS += build_info.o
OBJS += cancellation.o
Expand All @@ -11,7 +11,7 @@ OBJS += fs.o
OBJS += sd_spi.o
OBJS += spi.o
OBJS += string.o
OBJS += stm32f10x.o
OBJS += cortex.o mcu_$(mcu).o
OBJS += time.o
OBJS += timer.o
OBJS += util.o
Expand Down
2 changes: 1 addition & 1 deletion bootloader/display/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RPATH = ../../src/display

OBJS += display.o
OBJS += lcd.o
OBJS += lcd_$(mcu).o
OBJS += oled_font_6x13.o
OBJS += led_7seg.o
11 changes: 9 additions & 2 deletions inc/decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
#include <limits.h>

#include "types.h"
#include "stm32f10x_regs.h"
#include "stm32f10x.h"
#include "mcu/common_regs.h"
#include "mcu/common.h"
#if MCU == STM32F105
#include "mcu/stm32f105_regs.h"
#include "mcu/stm32f105.h"
#elif MCU == AT32F435
#include "mcu/at32f435_regs.h"
#include "mcu/at32f435.h"
#endif
#include "intrinsics.h"

#include "time.h"
Expand Down
8 changes: 8 additions & 0 deletions inc/intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ struct exception_frame {
* confirmed on Cortex-M3. */
#define IRQ_restore(oldpri) write_special(basepri, (oldpri))

#define __DEFINE_IRQ(nr, name) \
void IRQ_##nr (void) __attribute__((alias(name)))
#define _DEFINE_IRQ(nr, name) __DEFINE_IRQ(nr, name)
#define DEFINE_IRQ(nr, name) _DEFINE_IRQ(nr, name)

/* Cortex initialisation */
void cortex_init(void);

static inline uint16_t _rev16(uint16_t x)
{
uint16_t result;
Expand Down
80 changes: 80 additions & 0 deletions inc/mcu/at32f435.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* at32f435.h
*
* Core and peripheral registers.
*
* Written & released by Keir Fraser <[email protected]>
*
* This is free and unencumbered software released into the public domain.
* See the file COPYING for more details, or visit <http://unlicense.org>.
*/

/* C pointer types */
#define FLASH_BANK volatile struct flash_bank * const
#define SYSCFG volatile struct syscfg * const
#define DMAMUX volatile struct dmamux * const

/* C-accessible registers. */
static STK stk = (struct stk *)STK_BASE;
static SCB scb = (struct scb *)SCB_BASE;
static NVIC nvic = (struct nvic *)NVIC_BASE;
static DBG dbg = (struct dbg *)DBG_BASE;
static FLASH flash = (struct flash *)FLASH_BASE;
static PWR pwr = (struct pwr *)PWR_BASE;
static BKP bkp = (struct bkp *)BKP_BASE;
static RCC rcc = (struct rcc *)RCC_BASE;
static GPIO gpioa = (struct gpio *)GPIOA_BASE;
static GPIO gpiob = (struct gpio *)GPIOB_BASE;
static GPIO gpioc = (struct gpio *)GPIOC_BASE;
static GPIO gpiod = (struct gpio *)GPIOD_BASE;
static GPIO gpioe = (struct gpio *)GPIOE_BASE;
static GPIO gpiof = (struct gpio *)GPIOF_BASE;
static GPIO gpiog = (struct gpio *)GPIOG_BASE;
static GPIO gpioh = (struct gpio *)GPIOH_BASE;
static SYSCFG syscfg = (struct syscfg *)SYSCFG_BASE;
static EXTI exti = (struct exti *)EXTI_BASE;
static DMA dma1 = (struct dma *)DMA1_BASE;
static DMA dma2 = (struct dma *)DMA2_BASE;
static DMAMUX dmamux1 = (struct dmamux *)DMAMUX1_BASE;
static DMAMUX dmamux2 = (struct dmamux *)DMAMUX2_BASE;
static TIM tim1 = (struct tim *)TIM1_BASE;
static TIM tim2 = (struct tim *)TIM2_BASE;
static TIM tim3 = (struct tim *)TIM3_BASE;
static TIM tim4 = (struct tim *)TIM4_BASE;
static TIM tim5 = (struct tim *)TIM5_BASE;
static TIM tim6 = (struct tim *)TIM6_BASE;
static TIM tim7 = (struct tim *)TIM7_BASE;
static SPI spi1 = (struct spi *)SPI1_BASE;
static SPI spi2 = (struct spi *)SPI2_BASE;
static SPI spi3 = (struct spi *)SPI3_BASE;
static I2C i2c1 = (struct i2c *)I2C1_BASE;
static I2C i2c2 = (struct i2c *)I2C2_BASE;
static USART usart1 = (struct usart *)USART1_BASE;
static USART usart2 = (struct usart *)USART2_BASE;
static USART usart3 = (struct usart *)USART3_BASE;
static USB_OTG usb_otg = (struct usb_otg *)USB_OTG_BASE;

/* Clocks */
#define SYSCLK_MHZ 288
#define AHB_MHZ (SYSCLK_MHZ / 1) /* 288MHz */
#define APB1_MHZ (SYSCLK_MHZ / 2) /* 144MHz */
#define APB2_MHZ (SYSCLK_MHZ / 2) /* 144MHz */

/* GPIO */
void gpio_set_af(GPIO gpio, unsigned int pin, unsigned int af);

#define SOFTIRQ_0 85
#define SOFTIRQ_1 86

extern volatile uint32_t _reset_flag;
#define RESET_FLAG_BOOTLOADER 0xdeadbeefu

/*
* Local variables:
* mode: C
* c-file-style: "Linux"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
Loading

0 comments on commit 7f5642a

Please sign in to comment.