From 4c6b056b8467bb6513224527ff3120ef905de397 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Wed, 11 Nov 2015 14:46:28 -0500 Subject: Lots of cleanup. Clean up and simplify(?) Makefile. Add copyrights as needed. Add include guard to stm-fmc.h. Move MX_USART2_UART_Init back to stm-init.c for possible copyright reasons. Move libc, src, and include files to top level. --- .gitignore | 1 + Drivers/Makefile | 16 +- Makefile | 121 +++++++------ gettimeofday.c | 63 +++++++ include/stm-fmc.h | 18 -- include/stm-init.h | 9 - include/stm-led.h | 16 -- include/stm-uart.h | 17 -- include/stm32f4xx_hal_conf.h | 423 ------------------------------------------- include/stm32f4xx_it.h | 56 ------ libc/gettimeofday.c | 26 --- libc/printf.c | 395 ---------------------------------------- libc/syscalls.c | 195 -------------------- main.c | 33 +++- printf.c | 395 ++++++++++++++++++++++++++++++++++++++++ src/stm-fmc.c | 325 --------------------------------- src/stm-init.c | 189 ------------------- src/stm-uart.c | 76 -------- src/stm32f4xx_hal_msp.c | 143 --------------- src/stm32f4xx_it.c | 73 -------- stm-fmc.c | 355 ++++++++++++++++++++++++++++++++++++ stm-fmc.h | 45 +++++ stm-init.c | 231 +++++++++++++++++++++++ stm-init.h | 43 +++++ stm-led.h | 50 +++++ stm-uart.c | 87 +++++++++ stm-uart.h | 49 +++++ stm32f4xx_hal_conf.h | 423 +++++++++++++++++++++++++++++++++++++++++++ stm32f4xx_hal_msp.c | 143 +++++++++++++++ stm32f4xx_it.c | 73 ++++++++ stm32f4xx_it.h | 56 ++++++ syscalls.c | 196 ++++++++++++++++++++ 32 files changed, 2312 insertions(+), 2029 deletions(-) create mode 100644 gettimeofday.c delete mode 100644 include/stm-fmc.h delete mode 100644 include/stm-init.h delete mode 100644 include/stm-led.h delete mode 100644 include/stm-uart.h delete mode 100644 include/stm32f4xx_hal_conf.h delete mode 100644 include/stm32f4xx_it.h delete mode 100644 libc/gettimeofday.c delete mode 100644 libc/printf.c delete mode 100644 libc/syscalls.c create mode 100644 printf.c delete mode 100644 src/stm-fmc.c delete mode 100644 src/stm-init.c delete mode 100644 src/stm-uart.c delete mode 100644 src/stm32f4xx_hal_msp.c delete mode 100644 src/stm32f4xx_it.c create mode 100644 stm-fmc.c create mode 100644 stm-fmc.h create mode 100644 stm-init.c create mode 100644 stm-init.h create mode 100644 stm-led.h create mode 100644 stm-uart.c create mode 100644 stm-uart.h create mode 100644 stm32f4xx_hal_conf.h create mode 100644 stm32f4xx_hal_msp.c create mode 100644 stm32f4xx_it.c create mode 100644 stm32f4xx_it.h create mode 100644 syscalls.c diff --git a/.gitignore b/.gitignore index 890e4fe..e3b4b63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o +*.mo *.bin *.elf *.hex diff --git a/Drivers/Makefile b/Drivers/Makefile index 376eac0..29aae70 100644 --- a/Drivers/Makefile +++ b/Drivers/Makefile @@ -6,20 +6,20 @@ AR=arm-none-eabi-ar vpath %.c STM32F4xx_HAL_Driver/Src # Default STDPERIPH_SETTINGS to settings suitable for STM32F429BIT6 (dev-bridge rev01) -STDPERIPH_SETTINGS ?= -DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F429xx +#STDPERIPH_SETTINGS ?= -DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F429xx -CFLAGS = -ggdb -O2 -Wall -Wextra -Warray-bounds -CFLAGS += -mcpu=cortex-m4 -mthumb -mlittle-endian -mthumb-interwork -CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 -CFLAGS += $(STDPERIPH_SETTINGS) -CFLAGS += -ICMSIS/Include -ICMSIS/Device/ST/STM32F4xx/Include -ISTM32F4xx_HAL_Driver/Inc +#CFLAGS += -ggdb -O2 -Wall -Wextra -Warray-bounds +#CFLAGS += -mcpu=cortex-m4 -mthumb -mlittle-endian -mthumb-interwork +#CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 +#CFLAGS += -ICMSIS/Include -ICMSIS/Device/ST/STM32F4xx/Include -ISTM32F4xx_HAL_Driver/Inc +#CFLAGS += $(STDPERIPH_SETTINGS) -SRCS = stm32f4xx_hal.c stm32f4xx_hal_msp_template.c \ +SRCS = stm32f4xx_hal.c stm32f4xx_hal_msp_template.c \ stm32f4xx_hal_adc.c stm32f4xx_hal_nand.c \ stm32f4xx_hal_adc_ex.c stm32f4xx_hal_nor.c \ stm32f4xx_hal_can.c stm32f4xx_hal_pccard.c \ stm32f4xx_hal_cortex.c stm32f4xx_hal_pcd.c \ - stm32f4xx_hal_crc.c stm32f4xx_hal_pwr.c \ + stm32f4xx_hal_crc.c stm32f4xx_hal_pwr.c \ stm32f4xx_hal_cryp.c stm32f4xx_hal_pwr_ex.c \ stm32f4xx_hal_cryp_ex.c stm32f4xx_hal_rcc.c \ stm32f4xx_hal_dac.c stm32f4xx_hal_rcc_ex.c \ diff --git a/Makefile b/Makefile index e98134a..4fd6c98 100644 --- a/Makefile +++ b/Makefile @@ -1,35 +1,57 @@ +# Copyright (c) 2015, SUNET +# +# 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 COPYRIGHT HOLDERS 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 +# COPYRIGHT OWNER 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. + +# "stm32-native" projects SELF-TESTS = fmc-test led-test short-test uart-test fmc-perf +vpath %.c self-test -LIBHAL-TESTS = cores test-bus test-hash test-aes-key-wrap test-pbkdf2 test-ecdsa #test-rsa +# apps originally written for unix-like environment +LIBHAL-TESTS = cores test-bus test-hash test-aes-key-wrap test-pbkdf2 #test-ecdsa #test-rsa +vpath %.c libhal/tests libhal/utils -# put your *.o targets here, make should handle the rest! -SRCS = stm32f4xx_hal_msp.c stm32f4xx_it.c stm-fmc.c stm-init.c stm-uart.c - -TOPLEVEL=. +# absolute path, because we're going to be passing -I cflags to sub-makes +TOPLEVEL = $(shell pwd) # Location of the Libraries folder from the STM32F0xx Standard Peripheral Library -STD_PERIPH_LIB ?= $(TOPLEVEL)/Drivers +STD_PERIPH_LIB = $(TOPLEVEL)/Drivers -# Location of the linker scripts -LDSCRIPT_INC ?= $(TOPLEVEL)/Device/ldscripts +# linker script +LDSCRIPT = $(TOPLEVEL)/Device/ldscripts/stm32f429bitx.ld -# MCU selection parameters -# -STDPERIPH_SETTINGS ?= -DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F429xx -# -# For the dev-bridge rev01 board, use stm32f429bitx.ld. -MCU_LINKSCRIPT ?= stm32f429bitx.ld +# board-specific objects, to link into every project +BOARD_OBJS = stm32f4xx_hal_msp.o stm32f4xx_it.o stm-fmc.o stm-init.o stm-uart.o \ + Device/startup_stm32f429xx.o Device/system_stm32f4xx.o -# add startup file to build -# -# For the dev-bridge rev01 board, use startup_stm32f429xx.s. -SRCS += $(TOPLEVEL)/Device/startup_stm32f429xx.s -SRCS += $(TOPLEVEL)/Device/system_stm32f4xx.c - -# that's it, no need to change anything below this line! +# a few objects for libhal/test projects +LIBC_OBJS = syscalls.o printf.o gettimeofday.o -################################################### +LIBS = $(STD_PERIPH_LIB)/libstmf4.a libhal/libhal.a thirdparty/libtfm/libtfm.a +# cross-building tools PREFIX=arm-none-eabi- export CC=$(PREFIX)gcc export AS=$(PREFIX)as @@ -38,33 +60,20 @@ export OBJCOPY=$(PREFIX)objcopy export OBJDUMP=$(PREFIX)objdump export SIZE=$(PREFIX)size -#CFLAGS = -ggdb -O2 -Wall -Wextra -Warray-bounds -CFLAGS = -ggdb -O2 -Wall -Warray-bounds +# whew, that's a lot of cflags +CFLAGS = -ggdb -O2 -Wall -Warray-bounds #-Wextra CFLAGS += -mcpu=cortex-m4 -mthumb -mlittle-endian -mthumb-interwork CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 -CFLAGS += $(STDPERIPH_SETTINGS) +CFLAGS += -DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F429xx CFLAGS += -ffunction-sections -fdata-sections CFLAGS += -Wl,--gc-sections CFLAGS += -std=c99 - -################################################### - -vpath %.c src self-test -vpath %.a $(STD_PERIPH_LIB) - -IFLAGS += -I include -I $(STD_PERIPH_LIB) -I $(STD_PERIPH_LIB)/CMSIS/Device/ST/STM32F4xx/Include -IFLAGS += -I $(STD_PERIPH_LIB)/CMSIS/Include -I $(STD_PERIPH_LIB)/STM32F4xx_HAL_Driver/Inc - -%.o: %.c - $(CC) -c $(CFLAGS) $(IFLAGS) -o $@ $< - -OBJS = $(patsubst %.s,%.o, $(patsubst %.c,%.o, $(SRCS))) - -################################################### - -.PHONY: lib self-test - -LIBS = $(STD_PERIPH_LIB)/libstmf4.a libhal/libhal.a thirdparty/libtfm/libtfm.a +CFLAGS += -I $(TOPLEVEL) -I $(STD_PERIPH_LIB) +CFLAGS += -I $(STD_PERIPH_LIB)/CMSIS/Device/ST/STM32F4xx/Include +CFLAGS += -I $(STD_PERIPH_LIB)/CMSIS/Include +CFLAGS += -I $(STD_PERIPH_LIB)/STM32F4xx_HAL_Driver/Inc +CFLAGS += -I libhal +export CFLAGS all: lib self-test libhal-tests @@ -73,10 +82,8 @@ init: lib: $(LIBS) -export CFLAGS - $(STD_PERIPH_LIB)/libstmf4.a: - $(MAKE) -C $(STD_PERIPH_LIB) STDPERIPH_SETTINGS="$(STDPERIPH_SETTINGS) -I $(PWD)/include" + $(MAKE) -C $(STD_PERIPH_LIB) thirdparty/libtfm/libtfm.a: $(MAKE) -C thirdparty/libtfm PREFIX=$(PREFIX) @@ -86,8 +93,8 @@ libhal/libhal.a: hal_io_fmc.o thirdparty/libtfm/libtfm.a self-test: $(SELF-TESTS:=.elf) -%.elf: %.o $(OBJS) $(STD_PERIPH_LIB)/libstmf4.a - $(CC) $(CFLAGS) $^ -o $@ -L$(LDSCRIPT_INC) -T$(MCU_LINKSCRIPT) -g -Wl,-Map=$*.map +%.elf: %.o $(BOARD_OBJS) $(STD_PERIPH_LIB)/libstmf4.a + $(CC) $(CFLAGS) $^ -o $@ -T$(LDSCRIPT) -g -Wl,-Map=$*.map $(OBJCOPY) -O ihex $*.elf $*.hex $(OBJCOPY) -O binary $*.elf $*.bin $(OBJDUMP) -St $*.elf >$*.lst @@ -95,26 +102,23 @@ self-test: $(SELF-TESTS:=.elf) libhal-tests: $(LIBHAL-TESTS:=.bin) -vpath %.c libhal/tests -CFLAGS += -I libhal - # .mo extension for files with main() that need to be wrapped as __main() %.mo: %.c - $(CC) -c $(CFLAGS) $(IFLAGS) -Dmain=__main -o $@ $< + $(CC) -c $(CFLAGS) -Dmain=__main -o $@ $< -vpath %.c libc libhal/utils -%.bin: %.mo main.o syscalls.o printf.o gettimeofday.o $(OBJS) $(LIBS) - $(CC) $(CFLAGS) $^ -o $*.elf -L$(LDSCRIPT_INC) -T$(MCU_LINKSCRIPT) -g -Wl,-Map=$*.map +%.bin: %.mo main.o $(BOARD_OBJS) $(LIBC_OBJS) $(LIBS) + $(CC) $(CFLAGS) $^ -o $*.elf -T$(LDSCRIPT) -g -Wl,-Map=$*.map $(OBJCOPY) -O ihex $*.elf $*.hex $(OBJCOPY) -O binary $*.elf $*.bin $(OBJDUMP) -St $*.elf >$*.lst $(SIZE) $*.elf -.SECONDARY: $(OBJS) *.mo main.o syscalls.o printf.o gettimeofday.o +# don't automatically delete objects, to avoid a lot of unnecessary rebuilding +.SECONDARY: $(BOARD_OBJS) $(LIBC_OBJS) clean: find ./ -name '*~' | xargs rm -f - rm -f $(OBJS) *.o *.mo + rm -f $(BOARD_OBJS) $(LIBC_OBJS) *.o *.mo rm -f *.elf rm -f *.hex rm -f *.bin @@ -125,4 +129,3 @@ distclean: clean $(MAKE) -C $(STD_PERIPH_LIB) clean $(MAKE) -C thirdparty/libtfm clean $(MAKE) -C libhal clean - $(MAKE) -C libc clean diff --git a/gettimeofday.c b/gettimeofday.c new file mode 100644 index 0000000..b13485d --- /dev/null +++ b/gettimeofday.c @@ -0,0 +1,63 @@ +/* + * gettimeofday.c + * -------------- + * A simple implementation of gettimeofday() for CMSIS. + * This assumes a 1ms SysTick. It obviously does not return the absolute time, + * just the time since boot, but it's only used to calculate elapsed time in + * code we're porting from unix. + * + * Copyright (c) 2015, NORDUnet A/S All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - 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. + * + * - Neither the name of the NORDUnet nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT + * HOLDER 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 "stm32f4xx_hal.h" + +/* Don't #include because of conflicting prototype in newlib. */ + +/* from the manpage */ +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* microseconds */ +}; + +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of DST correction */ +}; + +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + uint32_t tick = HAL_GetTick(); /* uptime in ms */ + + tv->tv_sec = tick / 1000; + tv->tv_usec = (tick % 1000) * 1000; + + return 0; +} diff --git a/include/stm-fmc.h b/include/stm-fmc.h deleted file mode 100644 index cf9b77e..0000000 --- a/include/stm-fmc.h +++ /dev/null @@ -1,18 +0,0 @@ -//------------------------------------------------------------------------------ -// stm-fmc.h -//------------------------------------------------------------------------------ - -#include - -//------------------------------------------------------------------------------ -// Prototypes -//------------------------------------------------------------------------------ -void fmc_init(void); - -int fmc_write_32(uint32_t addr, uint32_t *data); -int fmc_read_32(uint32_t addr, uint32_t *data); - - -//------------------------------------------------------------------------------ -// EOF -//------------------------------------------------------------------------------ diff --git a/include/stm-init.h b/include/stm-init.h deleted file mode 100644 index fdf7dd0..0000000 --- a/include/stm-init.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __STM_INIT_H -#define __STM_INIT_H - -#include "stm32f4xx_hal.h" - -extern void stm_init(void); -extern void Error_Handler(void); - -#endif /* __STM_INIT_H */ diff --git a/include/stm-led.h b/include/stm-led.h deleted file mode 100644 index bd2a1e3..0000000 --- a/include/stm-led.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __STM_LED_H -#define __STM_LED_H - -#include "stm32f4xx_hal.h" - -#define LED_PORT GPIOJ -#define LED_RED GPIO_PIN_1 -#define LED_YELLOW GPIO_PIN_2 -#define LED_GREEN GPIO_PIN_3 -#define LED_BLUE GPIO_PIN_4 - -#define led_on(pin) HAL_GPIO_WritePin(LED_PORT,pin,SET) -#define led_off(pin) HAL_GPIO_WritePin(LED_PORT,pin,RESET) -#define led_toggle(pin) HAL_GPIO_TogglePin(LED_PORT,pin) - -#endif /* __STM_LED_H */ diff --git a/include/stm-uart.h b/include/stm-uart.h deleted file mode 100644 index c57afd5..0000000 --- a/include/stm-uart.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __STM32_DEV_BRIDGE_UART_H -#define __STM32_DEV_BRIDGE_UART_H - -#include "stm32f4xx_hal.h" - -#define USART2_BAUD_RATE 115200 - -extern void MX_USART2_UART_Init(void); - -extern void uart_send_char(uint8_t ch); -extern void uart_send_string(char *s); -extern void uart_send_number(uint32_t num, uint8_t digits, uint8_t radix); -#define uart_send_binary(num, bits) uart_send_number(num, bits, 2) -#define uart_send_integer(num, digits) uart_send_number(num, digits, 10) -#define uart_send_hex(num, digits) uart_send_number(num, digits, 16) - -#endif /* __STM32_DEV_BRIDGE_UART_H */ diff --git a/include/stm32f4xx_hal_conf.h b/include/stm32f4xx_hal_conf.h deleted file mode 100644 index fd13d9e..0000000 --- a/include/stm32f4xx_hal_conf.h +++ /dev/null @@ -1,423 +0,0 @@ -/** - ****************************************************************************** - * @file stm32f4xx_hal_conf.h - * @brief HAL configuration file. - ****************************************************************************** - * @attention - * - *

© COPYRIGHT(c) 2015 STMicroelectronics

- * - * 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. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F4xx_HAL_CONF_H -#define __STM32F4xx_HAL_CONF_H - -#ifdef __cplusplus - extern "C" { -#endif - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ - -/* ########################## Module Selection ############################## */ -/** - * @brief This is the list of modules to be used in the HAL driver - */ -#define HAL_MODULE_ENABLED - -//#define HAL_ADC_MODULE_ENABLED -//#define HAL_CAN_MODULE_ENABLED -//#define HAL_CRC_MODULE_ENABLED -//#define HAL_CRYP_MODULE_ENABLED -//#define HAL_DAC_MODULE_ENABLED -//#define HAL_DCMI_MODULE_ENABLED -//#define HAL_DMA2D_MODULE_ENABLED -//#define HAL_ETH_MODULE_ENABLED -//#define HAL_NAND_MODULE_ENABLED -//#define HAL_NOR_MODULE_ENABLED -//#define HAL_PCCARD_MODULE_ENABLED -#define HAL_SRAM_MODULE_ENABLED -//#define HAL_SDRAM_MODULE_ENABLED -//#define HAL_HASH_MODULE_ENABLED -//#define HAL_I2C_MODULE_ENABLED -//#define HAL_I2S_MODULE_ENABLED -//#define HAL_IWDG_MODULE_ENABLED -//#define HAL_LTDC_MODULE_ENABLED -#define HAL_RNG_MODULE_ENABLED -//#define HAL_RTC_MODULE_ENABLED -//#define HAL_SAI_MODULE_ENABLED -//#define HAL_SD_MODULE_ENABLED -//#define HAL_SPI_MODULE_ENABLED -//#define HAL_TIM_MODULE_ENABLED -#define HAL_UART_MODULE_ENABLED -//#define HAL_USART_MODULE_ENABLED -//#define HAL_IRDA_MODULE_ENABLED -//#define HAL_SMARTCARD_MODULE_ENABLED -//#define HAL_WWDG_MODULE_ENABLED -//#define HAL_PCD_MODULE_ENABLED -//#define HAL_HCD_MODULE_ENABLED -//#define HAL_QSPI_MODULE_ENABLED -//#define HAL_QSPI_MODULE_ENABLED -//#define HAL_CEC_MODULE_ENABLED -//#define HAL_FMPI2C_MODULE_ENABLED -//#define HAL_SPDIFRX_MODULE_ENABLED -#define HAL_GPIO_MODULE_ENABLED -#define HAL_DMA_MODULE_ENABLED -#define HAL_RCC_MODULE_ENABLED -#define HAL_FLASH_MODULE_ENABLED -#define HAL_PWR_MODULE_ENABLED -#define HAL_CORTEX_MODULE_ENABLED - -/* ########################## HSE/HSI Values adaptation ##################### */ -/** - * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. - * This value is used by the RCC HAL module to compute the system frequency - * (when HSE is used as system clock source, directly or through the PLL). - */ -#if !defined (HSE_VALUE) - #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ - -/** - * @brief Internal High Speed oscillator (HSI) value. - * This value is used by the RCC HAL module to compute the system frequency - * (when HSI is used as system clock source, directly or through the PLL). - */ -#if !defined (HSI_VALUE) - #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ - -/** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) - #define LSI_VALUE ((uint32_t)32000) -#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz - The real value may vary depending on the variations - in voltage and temperature. */ -/** - * @brief External Low Speed oscillator (LSE) value. - */ -#if !defined (LSE_VALUE) - #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ - -/** - * @brief External clock source for I2S peripheral - * This value is used by the I2S HAL module to compute the I2S clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined (EXTERNAL_CLOCK_VALUE) - #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000) /*!< Value of the External audio frequency in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ - -/* Tip: To avoid modifying this file each time you need to use different HSE, - === you can define the HSE value in your toolchain compiler preprocessor. */ - -/* ########################### System Configuration ######################### */ -/** - * @brief This is the HAL system configuration section - */ - -#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY ((uint32_t)0) /*!< tick interrupt priority */ -#define USE_RTOS 0 -#define PREFETCH_ENABLE 1 -#define INSTRUCTION_CACHE_ENABLE 1 -#define DATA_CACHE_ENABLE 1 - -/* ########################## Assert Selection ############################## */ -/** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -/* #define USE_FULL_ASSERT 1 */ - -/* ################## Ethernet peripheral configuration ##################### */ - -/* Section 1 : Ethernet peripheral configuration */ - -/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ -#define MAC_ADDR0 2 -#define MAC_ADDR1 0 -#define MAC_ADDR2 0 -#define MAC_ADDR3 0 -#define MAC_ADDR4 0 -#define MAC_ADDR5 0 - -/* Definition of the Ethernet driver buffers size and count */ -#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ -#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ -#define ETH_RXBUFNB ((uint32_t)4) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ -#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ - -/* Section 2: PHY configuration section */ - -/* DP83848 PHY Address*/ -#define DP83848_PHY_ADDRESS 0x01 -/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ -#define PHY_RESET_DELAY ((uint32_t)0x000000FF) -/* PHY Configuration delay */ -#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF) - -#define PHY_READ_TO ((uint32_t)0x0000FFFF) -#define PHY_WRITE_TO ((uint32_t)0x0000FFFF) - -/* Section 3: Common PHY Registers */ - -#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */ -#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */ - -#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */ -#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */ -#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */ -#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */ -#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */ -#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */ -#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */ -#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */ -#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */ -#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */ - -#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */ -#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */ -#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */ - -/* Section 4: Extended PHY Registers */ - -#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */ -#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */ -#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */ - -#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */ -#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */ -#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */ - -#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */ -#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */ - -#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */ -#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */ - -/* Includes ------------------------------------------------------------------*/ -/** - * @brief Include module's header file - */ - -#ifdef HAL_RCC_MODULE_ENABLED - #include "stm32f4xx_hal_rcc.h" -#endif /* HAL_RCC_MODULE_ENABLED */ - -#ifdef HAL_GPIO_MODULE_ENABLED - #include "stm32f4xx_hal_gpio.h" -#endif /* HAL_GPIO_MODULE_ENABLED */ - -#ifdef HAL_DMA_MODULE_ENABLED - #include "stm32f4xx_hal_dma.h" -#endif /* HAL_DMA_MODULE_ENABLED */ - -#ifdef HAL_CORTEX_MODULE_ENABLED - #include "stm32f4xx_hal_cortex.h" -#endif /* HAL_CORTEX_MODULE_ENABLED */ - -#ifdef HAL_ADC_MODULE_ENABLED - #include "stm32f4xx_hal_adc.h" -#endif /* HAL_ADC_MODULE_ENABLED */ - -#ifdef HAL_CAN_MODULE_ENABLED - #include "stm32f4xx_hal_can.h" -#endif /* HAL_CAN_MODULE_ENABLED */ - -#ifdef HAL_CRC_MODULE_ENABLED - #include "stm32f4xx_hal_crc.h" -#endif /* HAL_CRC_MODULE_ENABLED */ - -#ifdef HAL_CRYP_MODULE_ENABLED - #include "stm32f4xx_hal_cryp.h" -#endif /* HAL_CRYP_MODULE_ENABLED */ - -#ifdef HAL_DMA2D_MODULE_ENABLED - #include "stm32f4xx_hal_dma2d.h" -#endif /* HAL_DMA2D_MODULE_ENABLED */ - -#ifdef HAL_DAC_MODULE_ENABLED - #include "stm32f4xx_hal_dac.h" -#endif /* HAL_DAC_MODULE_ENABLED */ - -#ifdef HAL_DCMI_MODULE_ENABLED - #include "stm32f4xx_hal_dcmi.h" -#endif /* HAL_DCMI_MODULE_ENABLED */ - -#ifdef HAL_ETH_MODULE_ENABLED - #include "stm32f4xx_hal_eth.h" -#endif /* HAL_ETH_MODULE_ENABLED */ - -#ifdef HAL_FLASH_MODULE_ENABLED - #include "stm32f4xx_hal_flash.h" -#endif /* HAL_FLASH_MODULE_ENABLED */ - -#ifdef HAL_SRAM_MODULE_ENABLED - #include "stm32f4xx_hal_sram.h" -#endif /* HAL_SRAM_MODULE_ENABLED */ - -#ifdef HAL_NOR_MODULE_ENABLED - #include "stm32f4xx_hal_nor.h" -#endif /* HAL_NOR_MODULE_ENABLED */ - -#ifdef HAL_NAND_MODULE_ENABLED - #include "stm32f4xx_hal_nand.h" -#endif /* HAL_NAND_MODULE_ENABLED */ - -#ifdef HAL_PCCARD_MODULE_ENABLED - #include "stm32f4xx_hal_pccard.h" -#endif /* HAL_PCCARD_MODULE_ENABLED */ - -#ifdef HAL_SDRAM_MODULE_ENABLED - #include "stm32f4xx_hal_sdram.h" -#endif /* HAL_SDRAM_MODULE_ENABLED */ - -#ifdef HAL_HASH_MODULE_ENABLED - #include "stm32f4xx_hal_hash.h" -#endif /* HAL_HASH_MODULE_ENABLED */ - -#ifdef HAL_I2C_MODULE_ENABLED - #include "stm32f4xx_hal_i2c.h" -#endif /* HAL_I2C_MODULE_ENABLED */ - -#ifdef HAL_I2S_MODULE_ENABLED - #include "stm32f4xx_hal_i2s.h" -#endif /* HAL_I2S_MODULE_ENABLED */ - -#ifdef HAL_IWDG_MODULE_ENABLED - #include "stm32f4xx_hal_iwdg.h" -#endif /* HAL_IWDG_MODULE_ENABLED */ - -#ifdef HAL_LTDC_MODULE_ENABLED - #include "stm32f4xx_hal_ltdc.h" -#endif /* HAL_LTDC_MODULE_ENABLED */ - -#ifdef HAL_PWR_MODULE_ENABLED - #include "stm32f4xx_hal_pwr.h" -#endif /* HAL_PWR_MODULE_ENABLED */ - -#ifdef HAL_RNG_MODULE_ENABLED - #include "stm32f4xx_hal_rng.h" -#endif /* HAL_RNG_MODULE_ENABLED */ - -#ifdef HAL_RTC_MODULE_ENABLED - #include "stm32f4xx_hal_rtc.h" -#endif /* HAL_RTC_MODULE_ENABLED */ - -#ifdef HAL_SAI_MODULE_ENABLED - #include "stm32f4xx_hal_sai.h" -#endif /* HAL_SAI_MODULE_ENABLED */ - -#ifdef HAL_SD_MODULE_ENABLED - #include "stm32f4xx_hal_sd.h" -#endif /* HAL_SD_MODULE_ENABLED */ - -#ifdef HAL_SPI_MODULE_ENABLED - #include "stm32f4xx_hal_spi.h" -#endif /* HAL_SPI_MODULE_ENABLED */ - -#ifdef HAL_TIM_MODULE_ENABLED - #include "stm32f4xx_hal_tim.h" -#endif /* HAL_TIM_MODULE_ENABLED */ - -#ifdef HAL_UART_MODULE_ENABLED - #include "stm32f4xx_hal_uart.h" -#endif /* HAL_UART_MODULE_ENABLED */ - -#ifdef HAL_USART_MODULE_ENABLED - #include "stm32f4xx_hal_usart.h" -#endif /* HAL_USART_MODULE_ENABLED */ - -#ifdef HAL_IRDA_MODULE_ENABLED - #include "stm32f4xx_hal_irda.h" -#endif /* HAL_IRDA_MODULE_ENABLED */ - -#ifdef HAL_SMARTCARD_MODULE_ENABLED - #include "stm32f4xx_hal_smartcard.h" -#endif /* HAL_SMARTCARD_MODULE_ENABLED */ - -#ifdef HAL_WWDG_MODULE_ENABLED - #include "stm32f4xx_hal_wwdg.h" -#endif /* HAL_WWDG_MODULE_ENABLED */ - -#ifdef HAL_PCD_MODULE_ENABLED - #include "stm32f4xx_hal_pcd.h" -#endif /* HAL_PCD_MODULE_ENABLED */ - -#ifdef HAL_HCD_MODULE_ENABLED - #include "stm32f4xx_hal_hcd.h" -#endif /* HAL_HCD_MODULE_ENABLED */ - -#ifdef HAL_QSPI_MODULE_ENABLED - #include "stm32f4xx_hal_qspi.h" -#endif /* HAL_QSPI_MODULE_ENABLED */ - -#ifdef HAL_CEC_MODULE_ENABLED - #include "stm32f4xx_hal_cec.h" -#endif /* HAL_CEC_MODULE_ENABLED */ - -#ifdef HAL_FMPI2C_MODULE_ENABLED - #include "stm32f4xx_hal_fmpi2c.h" -#endif /* HAL_FMPI2C_MODULE_ENABLED */ - -#ifdef HAL_SPDIFRX_MODULE_ENABLED - #include "stm32f4xx_hal_spdifrx.h" -#endif /* HAL_SPDIFRX_MODULE_ENABLED */ - -/* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT -/** - * @brief The assert_param macro is used for function's parameters check. - * @param expr: If expr is false, it calls assert_failed function - * which reports the name of the source file and the source - * line number of the call that failed. - * If expr is true, it returns no value. - * @retval None - */ - #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) -/* Exported functions ------------------------------------------------------- */ - void assert_failed(uint8_t* file, uint32_t line); -#else - #define assert_param(expr) ((void)0) -#endif /* USE_FULL_ASSERT */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32F4xx_HAL_CONF_H */ - - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/include/stm32f4xx_it.h b/include/stm32f4xx_it.h deleted file mode 100644 index 546d79c..0000000 --- a/include/stm32f4xx_it.h +++ /dev/null @@ -1,56 +0,0 @@ -/** - ****************************************************************************** - * @file stm32f4xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * - * COPYRIGHT(c) 2015 STMicroelectronics - * - * 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. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F4xx_IT_H -#define __STM32F4xx_IT_H - -#ifdef __cplusplus - extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ - -void SysTick_Handler(void); - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32F4xx_IT_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/libc/gettimeofday.c b/libc/gettimeofday.c deleted file mode 100644 index b0561c3..0000000 --- a/libc/gettimeofday.c +++ /dev/null @@ -1,26 +0,0 @@ -#include - -#include "stm32f4xx_hal.h" - -/* Don't #include because of conflicting prototype in newlib. */ - -/* from the manpage: */ -struct timeval { - time_t tv_sec; /* seconds */ - suseconds_t tv_usec; /* microseconds */ -}; - -struct timezone { - int tz_minuteswest; /* minutes west of Greenwich */ - int tz_dsttime; /* type of DST correction */ -}; - -int gettimeofday(struct timeval *tv, struct timezone *tz) -{ - uint32_t tick = HAL_GetTick(); /* uptime in ms */ - - tv->tv_sec = tick / 1000; - tv->tv_usec = (tick % 1000) * 1000; - - return 0; -} diff --git a/libc/printf.c b/libc/printf.c deleted file mode 100644 index a6153d8..0000000 --- a/libc/printf.c +++ /dev/null @@ -1,395 +0,0 @@ -/***************************************************************************** -Stripped-down printf() -Chris Giese http://my.execpc.com/~geezer -Release date: Dec 12, 2003 -This code is public domain (no copyright). -You can do whatever you want with it. - -Revised Dec 12, 2003 -- fixed vsprintf() and sprintf() in test code - -Revised Jan 28, 2002 -- changes to make characters 0x80-0xFF display properly - -Revised June 10, 2001 -- changes to make vsprintf() terminate string with '\0' - -Revised May 12, 2000 -- math in DO_NUM is now unsigned, as it should be -- %0 flag (pad left with zeroes) now works -- actually did some TESTING, maybe fixed some other bugs - -%[flag][width][.prec][mod][conv] -flag: - left justify, pad right w/ blanks DONE - 0 pad left w/ 0 for numerics DONE - + always print sign, + or - no - ' ' (blank) no - # (???) no - -width: (field width) DONE - -prec: (precision) no - -conv: d,i decimal int DONE - u decimal unsigned DONE - o octal DONE - x,X hex DONE - f,e,g,E,G float no - c char DONE - s string DONE - p ptr DONE - -mod: N near ptr DONE - F far ptr no - h short (16-bit) int DONE - l long (32-bit) int DONE - L long long (64-bit) int no -*****************************************************************************/ -#include /* strlen() */ -#include /* stdout, putchar(), fputs() (but not printf() :) */ -#undef putchar - -#include /* va_list, va_start(), va_arg(), va_end() */ - -/* flags used in processing format string */ -#define PR_LJ 0x01 /* left justify */ -#define PR_CA 0x02 /* use A-F instead of a-f for hex */ -#define PR_SG 0x04 /* signed numeric conversion (%d vs. %u) */ -#define PR_32 0x08 /* long (32-bit) numeric conversion */ -#define PR_16 0x10 /* short (16-bit) numeric conversion */ -#define PR_WS 0x20 /* PR_SG set and num was < 0 */ -#define PR_LZ 0x40 /* pad left with '0' instead of ' ' */ -#define PR_FP 0x80 /* pointers are far */ -/* largest number handled is 2^64-1, lowest radix handled is 8. -2^64-1 in base 8 has 22 digits (add 2 for trailing NUL and for slop) */ -#define PR_BUFLEN 24 - -typedef int (*fnptr_t)(unsigned c, void **helper); -/***************************************************************************** -name: do_printf -action: minimal subfunction for ?printf, calls function - 'fn' with arg 'ptr' for each character to be output -returns:total number of characters output -*****************************************************************************/ -int do_printf(const char *fmt, va_list args, fnptr_t fn, void *ptr) -{ - unsigned flags, actual_wd, count, given_wd; - unsigned char *where, buf[PR_BUFLEN]; - unsigned char state, radix; - long num; - - state = flags = count = given_wd = 0; -/* begin scanning format specifier list */ - for(; *fmt; fmt++) - { - switch(state) - { -/* STATE 0: AWAITING % */ - case 0: - if(*fmt != '%') /* not %... */ - { - fn(*fmt, &ptr); /* ...just echo it */ - count++; - break; - } -/* found %, get next char and advance state to check if next char is a flag */ - state++; - fmt++; - /* FALL THROUGH */ -/* STATE 1: AWAITING FLAGS (%-0) */ - case 1: - if(*fmt == '%') /* %% */ - { - fn(*fmt, &ptr); - count++; - state = flags = given_wd = 0; - break; - } - if(*fmt == '-') - { - if(flags & PR_LJ)/* %-- is illegal */ - state = flags = given_wd = 0; - else - flags |= PR_LJ; - break; - } -/* not a flag char: advance state to check if it's field width */ - state++; -/* check now for '%0...' */ - if(*fmt == '0') - { - flags |= PR_LZ; - fmt++; - } - /* FALL THROUGH */ -/* STATE 2: AWAITING (NUMERIC) FIELD WIDTH */ - case 2: - if(*fmt >= '0' && *fmt <= '9') - { - given_wd = 10 * given_wd + - (*fmt - '0'); - break; - } -/* not field width: advance state to check if it's a modifier */ - state++; - /* FALL THROUGH */ -/* STATE 3: AWAITING MODIFIER CHARS (FNlh) */ - case 3: - if(*fmt == 'F') - { - flags |= PR_FP; - break; - } - if(*fmt == 'N') - break; - if(*fmt == 'l') - { - flags |= PR_32; - break; - } - if(*fmt == 'h') - { - flags |= PR_16; - break; - } -/* not modifier: advance state to check if it's a conversion char */ - state++; - /* FALL THROUGH */ -/* STATE 4: AWAITING CONVERSION CHARS (Xxpndiuocs) */ - case 4: - where = buf + PR_BUFLEN - 1; - *where = '\0'; - switch(*fmt) - { - case 'X': - flags |= PR_CA; - /* FALL THROUGH */ -/* xxx - far pointers (%Fp, %Fn) not yet supported */ - case 'x': - case 'p': - case 'n': - radix = 16; - goto DO_NUM; - case 'd': - case 'i': - flags |= PR_SG; - /* FALL THROUGH */ - case 'u': - radix = 10; - goto DO_NUM; - case 'o': - radix = 8; -/* load the value to be printed. l=long=32 bits: */ -DO_NUM: if(flags & PR_32) - num = va_arg(args, unsigned long); -/* h=short=16 bits (signed or unsigned) */ - else if(flags & PR_16) - { - num = va_arg(args, int); - if(flags & PR_SG) - num = (short) num; - else - num = (unsigned short) num; - } -/* no h nor l: sizeof(int) bits (signed or unsigned) */ - else - { - if(flags & PR_SG) - num = va_arg(args, int); - else - num = va_arg(args, unsigned int); - } -/* take care of sign */ - if(flags & PR_SG) - { - if(num < 0) - { - flags |= PR_WS; - num = -num; - } - } -/* convert binary to octal/decimal/hex ASCII -OK, I found my mistake. The math here is _always_ unsigned */ - do - { - unsigned long temp; - - temp = (unsigned long)num % radix; - where--; - if(temp < 10) - *where = temp + '0'; - else if(flags & PR_CA) - *where = temp - 10 + 'A'; - else - *where = temp - 10 + 'a'; - num = (unsigned long)num / radix; - } - while(num != 0); - goto EMIT; - case 'c': -/* disallow pad-left-with-zeroes for %c */ - flags &= ~PR_LZ; - where--; - *where = (unsigned char)va_arg(args, int); - actual_wd = 1; - goto EMIT2; - case 's': -/* disallow pad-left-with-zeroes for %s */ - flags &= ~PR_LZ; - where = va_arg(args, unsigned char *); -EMIT: - actual_wd = strlen((const char *)where); - if(flags & PR_WS) - actual_wd++; -/* if we pad left with ZEROES, do the sign now */ - if((flags & (PR_WS | PR_LZ)) == - (PR_WS | PR_LZ)) - { - fn('-', &ptr); - count++; - } -/* pad on left with spaces or zeroes (for right justify) */ -EMIT2: if((flags & PR_LJ) == 0) - { - while(given_wd > actual_wd) - { - fn(flags & PR_LZ ? - '0' : ' ', &ptr); - count++; - given_wd--; - } - } -/* if we pad left with SPACES, do the sign now */ - if((flags & (PR_WS | PR_LZ)) == PR_WS) - { - fn('-', &ptr); - count++; - } -/* emit string/char/converted number */ - while(*where != '\0') - { - fn(*where++, &ptr); - count++; - } -/* pad on right with spaces (for left justify) */ - if(given_wd < actual_wd) - given_wd = 0; - else given_wd -= actual_wd; - for(; given_wd; given_wd--) - { - fn(' ', &ptr); - count++; - } - break; - default: - break; - } - default: - state = flags = given_wd = 0; - break; - } - } - return count; -} - -/***************************************************************************** -SPRINTF -*****************************************************************************/ -static int vsprintf_help(unsigned c, void **ptr) -{ - char *dst; - - dst = *ptr; - *dst++ = (char)c; - *ptr = dst; - return 0 ; -} -/***************************************************************************** -*****************************************************************************/ -int vsprintf(char *buf, const char *fmt, va_list args) -{ - int rv; - - rv = do_printf(fmt, args, vsprintf_help, (void *)buf); - buf[rv] = '\0'; - return rv; -} -/***************************************************************************** -*****************************************************************************/ -int sprintf(char *buf, const char *fmt, ...) -{ - va_list args; - int rv; - - va_start(args, fmt); - rv = vsprintf(buf, fmt, args); - va_end(args); - return rv; -} -/***************************************************************************** -PRINTF -You must write your own putchar() -*****************************************************************************/ -int vprintf_help(unsigned c, void **ptr) -{ - putchar(c); - return 0 ; -} -/***************************************************************************** -*****************************************************************************/ -int vprintf(const char *fmt, va_list args) -{ - return do_printf(fmt, args, vprintf_help, NULL); -} -/***************************************************************************** -*****************************************************************************/ -int printf(const char *fmt, ...) -{ - va_list args; - int rv; - - va_start(args, fmt); - rv = vprintf(fmt, args); - va_end(args); - return rv; -} - -#if 0 /* testing */ -/***************************************************************************** -*****************************************************************************/ -int main(void) -{ - char buf[64]; - - sprintf(buf, "%lu score and %i years ago...\n", 4L, -7); - fputs(buf, stdout); /* puts() adds newline */ - - sprintf(buf, "-1L == 0x%lX == octal %lo\n", -1L, -1L); - fputs(buf, stdout); /* puts() adds newline */ - - printf("<%-8s> and <%8s> justified strings\n", "left", "right"); - - printf("short signed: %hd, short unsigned: %hu\n", -1, -1); - return 0; -} -#else - -/***************************************************************************** -2015-10-29 pselkirk for cryptech -*****************************************************************************/ -/* gcc decides that a plain string with no formatting is best handled by puts() */ -int puts(const char *s) -{ - return printf("%s\n", s); -} - -/* transmit characters to the uart */ -#include "stm-uart.h" -int putchar(int c) -{ - if (c == '\n') - uart_send_char('\r'); - uart_send_char((uint8_t) c); - return c; -} -#endif diff --git a/libc/syscalls.c b/libc/syscalls.c deleted file mode 100644 index 9212763..0000000 --- a/libc/syscalls.c +++ /dev/null @@ -1,195 +0,0 @@ -/**************************************************************************** -* Copyright (c) 2009 by Michael Fischer. All rights reserved. -* -* 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. -* 3. Neither the name of the author nor the names of its contributors may -* be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. -* -**************************************************************************** -* History: -* -* 28.03.09 mifi First Version, based on the original syscall.c from -* newlib version 1.17.0 -****************************************************************************/ - -/* 2015-10-29 pselkirk for cryptech: - * Changed asm to __asm for c99 compatibility. - * Added _exit, _kill, and _getpid from mifi's 2013 revision. - */ - -#include -#include -#include -#include -#include - -/***************************************************************************/ - -int _read_r (struct _reent *r, int file, char * ptr, int len) -{ - r = r; - file = file; - ptr = ptr; - len = len; - - errno = EINVAL; - return -1; -} - -/***************************************************************************/ - -int _lseek_r (struct _reent *r, int file, int ptr, int dir) -{ - r = r; - file = file; - ptr = ptr; - dir = dir; - - return 0; -} - -/***************************************************************************/ - -int _write_r (struct _reent *r, int file, char * ptr, int len) -{ - r = r; - file = file; - ptr = ptr; - -#if 0 - int index; - - /* For example, output string by UART */ - for(index=0; index stack_ptr) - { - /* Some of the libstdc++-v3 tests rely upon detecting - out of memory errors, so do not abort here. */ -#if 0 - extern void abort (void); - - _write (1, "_sbrk: Heap and stack collision\n", 32); - - abort (); -#else - errno = ENOMEM; - return (caddr_t) -1; -#endif - } - - heap_end += incr; - - return (caddr_t) prev_heap_end; -} - -/***************************************************************************/ - -int _fstat_r (struct _reent *r, int file, struct stat * st) -{ - r = r; - file = file; - - memset (st, 0, sizeof (* st)); - st->st_mode = S_IFCHR; - return 0; -} - -/***************************************************************************/ - -int _isatty_r(struct _reent *r, int fd) -{ - r = r; - fd = fd; - - return 1; -} - -/***************************************************************************/ - -void _exit (int a) -{ - a = a; - - while(1) {}; -} - -/***************************************************************************/ - -int _kill (int a, int b) -{ - a = a; - b = b; - - return 0; -} - -/***************************************************************************/ - -int _getpid(int a) -{ - a = a; - - return 0; -} - -/*** EOF ***/ - - diff --git a/main.c b/main.c index 6d19a7e..dc72898 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,36 @@ -/* A wrapper for test programs that contain main() (currently libhal/tests). +/* + * main.c + * ------ + * A wrapper for test programs that contain main() (currently libhal/tests). * We compile them with -Dmain=__main, so we can do stm setup first. + * + * Copyright (c) 2015, NORDUnet A/S All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - 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. + * + * - Neither the name of the NORDUnet nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT + * HOLDER 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 "stm-init.h" diff --git a/printf.c b/printf.c new file mode 100644 index 0000000..a6153d8 --- /dev/null +++ b/printf.c @@ -0,0 +1,395 @@ +/***************************************************************************** +Stripped-down printf() +Chris Giese http://my.execpc.com/~geezer +Release date: Dec 12, 2003 +This code is public domain (no copyright). +You can do whatever you want with it. + +Revised Dec 12, 2003 +- fixed vsprintf() and sprintf() in test code + +Revised Jan 28, 2002 +- changes to make characters 0x80-0xFF display properly + +Revised June 10, 2001 +- changes to make vsprintf() terminate string with '\0' + +Revised May 12, 2000 +- math in DO_NUM is now unsigned, as it should be +- %0 flag (pad left with zeroes) now works +- actually did some TESTING, maybe fixed some other bugs + +%[flag][width][.prec][mod][conv] +flag: - left justify, pad right w/ blanks DONE + 0 pad left w/ 0 for numerics DONE + + always print sign, + or - no + ' ' (blank) no + # (???) no + +width: (field width) DONE + +prec: (precision) no + +conv: d,i decimal int DONE + u decimal unsigned DONE + o octal DONE + x,X hex DONE + f,e,g,E,G float no + c char DONE + s string DONE + p ptr DONE + +mod: N near ptr DONE + F far ptr no + h short (16-bit) int DONE + l long (32-bit) int DONE + L long long (64-bit) int no +*****************************************************************************/ +#include /* strlen() */ +#include /* stdout, putchar(), fputs() (but not printf() :) */ +#undef putchar + +#include /* va_list, va_start(), va_arg(), va_end() */ + +/* flags used in processing format string */ +#define PR_LJ 0x01 /* left justify */ +#define PR_CA 0x02 /* use A-F instead of a-f for hex */ +#define PR_SG 0x04 /* signed numeric conversion (%d vs. %u) */ +#define PR_32 0x08 /* long (32-bit) numeric conversion */ +#define PR_16 0x10 /* short (16-bit) numeric conversion */ +#define PR_WS 0x20 /* PR_SG set and num was < 0 */ +#define PR_LZ 0x40 /* pad left with '0' instead of ' ' */ +#define PR_FP 0x80 /* pointers are far */ +/* largest number handled is 2^64-1, lowest radix handled is 8. +2^64-1 in base 8 has 22 digits (add 2 for trailing NUL and for slop) */ +#define PR_BUFLEN 24 + +typedef int (*fnptr_t)(unsigned c, void **helper); +/***************************************************************************** +name: do_printf +action: minimal subfunction for ?printf, calls function + 'fn' with arg 'ptr' for each character to be output +returns:total number of characters output +*****************************************************************************/ +int do_printf(const char *fmt, va_list args, fnptr_t fn, void *ptr) +{ + unsigned flags, actual_wd, count, given_wd; + unsigned char *where, buf[PR_BUFLEN]; + unsigned char state, radix; + long num; + + state = flags = count = given_wd = 0; +/* begin scanning format specifier list */ + for(; *fmt; fmt++) + { + switch(state) + { +/* STATE 0: AWAITING % */ + case 0: + if(*fmt != '%') /* not %... */ + { + fn(*fmt, &ptr); /* ...just echo it */ + count++; + break; + } +/* found %, get next char and advance state to check if next char is a flag */ + state++; + fmt++; + /* FALL THROUGH */ +/* STATE 1: AWAITING FLAGS (%-0) */ + case 1: + if(*fmt == '%') /* %% */ + { + fn(*fmt, &ptr); + count++; + state = flags = given_wd = 0; + break; + } + if(*fmt == '-') + { + if(flags & PR_LJ)/* %-- is illegal */ + state = flags = given_wd = 0; + else + flags |= PR_LJ; + break; + } +/* not a flag char: advance state to check if it's field width */ + state++; +/* check now for '%0...' */ + if(*fmt == '0') + { + flags |= PR_LZ; + fmt++; + } + /* FALL THROUGH */ +/* STATE 2: AWAITING (NUMERIC) FIELD WIDTH */ + case 2: + if(*fmt >= '0' && *fmt <= '9') + { + given_wd = 10 * given_wd + + (*fmt - '0'); + break; + } +/* not field width: advance state to check if it's a modifier */ + state++; + /* FALL THROUGH */ +/* STATE 3: AWAITING MODIFIER CHARS (FNlh) */ + case 3: + if(*fmt == 'F') + { + flags |= PR_FP; + break; + } + if(*fmt == 'N') + break; + if(*fmt == 'l') + { + flags |= PR_32; + break; + } + if(*fmt == 'h') + { + flags |= PR_16; + break; + } +/* not modifier: advance state to check if it's a conversion char */ + state++; + /* FALL THROUGH */ +/* STATE 4: AWAITING CONVERSION CHARS (Xxpndiuocs) */ + case 4: + where = buf + PR_BUFLEN - 1; + *where = '\0'; + switch(*fmt) + { + case 'X': + flags |= PR_CA; + /* FALL THROUGH */ +/* xxx - far pointers (%Fp, %Fn) not yet supported */ + case 'x': + case 'p': + case 'n': + radix = 16; + goto DO_NUM; + case 'd': + case 'i': + flags |= PR_SG; + /* FALL THROUGH */ + case 'u': + radix = 10; + goto DO_NUM; + case 'o': + radix = 8; +/* load the value to be printed. l=long=32 bits: */ +DO_NUM: if(flags & PR_32) + num = va_arg(args, unsigned long); +/* h=short=16 bits (signed or unsigned) */ + else if(flags & PR_16) + { + num = va_arg(args, int); + if(flags & PR_SG) + num = (short) num; + else + num = (unsigned short) num; + } +/* no h nor l: sizeof(int) bits (signed or unsigned) */ + else + { + if(flags & PR_SG) + num = va_arg(args, int); + else + num = va_arg(args, unsigned int); + } +/* take care of sign */ + if(flags & PR_SG) + { + if(num < 0) + { + flags |= PR_WS; + num = -num; + } + } +/* convert binary to octal/decimal/hex ASCII +OK, I found my mistake. The math here is _always_ unsigned */ + do + { + unsigned long temp; + + temp = (unsigned long)num % radix; + where--; + if(temp < 10) + *where = temp + '0'; + else if(flags & PR_CA) + *where = temp - 10 + 'A'; + else + *where = temp - 10 + 'a'; + num = (unsigned long)num / radix; + } + while(num != 0); + goto EMIT; + case 'c': +/* disallow pad-left-with-zeroes for %c */ + flags &= ~PR_LZ; + where--; + *where = (unsigned char)va_arg(args, int); + actual_wd = 1; + goto EMIT2; + case 's': +/* disallow pad-left-with-zeroes for %s */ + flags &= ~PR_LZ; + where = va_arg(args, unsigned char *); +EMIT: + actual_wd = strlen((const char *)where); + if(flags & PR_WS) + actual_wd++; +/* if we pad left with ZEROES, do the sign now */ + if((flags & (PR_WS | PR_LZ)) == + (PR_WS | PR_LZ)) + { + fn('-', &ptr); + count++; + } +/* pad on left with spaces or zeroes (for right justify) */ +EMIT2: if((flags & PR_LJ) == 0) + { + while(given_wd > actual_wd) + { + fn(flags & PR_LZ ? + '0' : ' ', &ptr); + count++; + given_wd--; + } + } +/* if we pad left with SPACES, do the sign now */ + if((flags & (PR_WS | PR_LZ)) == PR_WS) + { + fn('-', &ptr); + count++; + } +/* emit string/char/converted number */ + while(*where != '\0') + { + fn(*where++, &ptr); + count++; + } +/* pad on right with spaces (for left justify) */ + if(given_wd < actual_wd) + given_wd = 0; + else given_wd -= actual_wd; + for(; given_wd; given_wd--) + { + fn(' ', &ptr); + count++; + } + break; + default: + break; + } + default: + state = flags = given_wd = 0; + break; + } + } + return count; +} + +/***************************************************************************** +SPRINTF +*****************************************************************************/ +static int vsprintf_help(unsigned c, void **ptr) +{ + char *dst; + + dst = *ptr; + *dst++ = (char)c; + *ptr = dst; + return 0 ; +} +/***************************************************************************** +*****************************************************************************/ +int vsprintf(char *buf, const char *fmt, va_list args) +{ + int rv; + + rv = do_printf(fmt, args, vsprintf_help, (void *)buf); + buf[rv] = '\0'; + return rv; +} +/***************************************************************************** +*****************************************************************************/ +int sprintf(char *buf, const char *fmt, ...) +{ + va_list args; + int rv; + + va_start(args, fmt); + rv = vsprintf(buf, fmt, args); + va_end(args); + return rv; +} +/***************************************************************************** +PRINTF +You must write your own putchar() +*****************************************************************************/ +int vprintf_help(unsigned c, void **ptr) +{ + putchar(c); + return 0 ; +} +/***************************************************************************** +*****************************************************************************/ +int vprintf(const char *fmt, va_list args) +{ + return do_printf(fmt, args, vprintf_help, NULL); +} +/***************************************************************************** +*****************************************************************************/ +int printf(const char *fmt, ...) +{ + va_list args; + int rv; + + va_start(args, fmt); + rv = vprintf(fmt, args); + va_end(args); + return rv; +} + +#if 0 /* testing */ +/***************************************************************************** +*****************************************************************************/ +int main(void) +{ + char buf[64]; + + sprintf(buf, "%lu score and %i years ago...\n", 4L, -7); + fputs(buf, stdout); /* puts() adds newline */ + + sprintf(buf, "-1L == 0x%lX == octal %lo\n", -1L, -1L); + fputs(buf, stdout); /* puts() adds newline */ + + printf("<%-8s> and <%8s> justified strings\n", "left", "right"); + + printf("short signed: %hd, short unsigned: %hu\n", -1, -1); + return 0; +} +#else + +/***************************************************************************** +2015-10-29 pselkirk for cryptech +*****************************************************************************/ +/* gcc decides that a plain string with no formatting is best handled by puts() */ +int puts(const char *s) +{ + return printf("%s\n", s); +} + +/* transmit characters to the uart */ +#include "stm-uart.h" +int putchar(int c) +{ + if (c == '\n') + uart_send_char('\r'); + uart_send_char((uint8_t) c); + return c; +} +#endif diff --git a/src/stm-fmc.c b/src/stm-fmc.c deleted file mode 100644 index 19b7fdc..0000000 --- a/src/stm-fmc.c +++ /dev/null @@ -1,325 +0,0 @@ -//------------------------------------------------------------------------------ -// stm-fmc.c -//------------------------------------------------------------------------------ - - -//------------------------------------------------------------------------------ -// Headers -//------------------------------------------------------------------------------ -#include "stm-fmc.h" -#include "stm32f4xx_hal.h" - - -//------------------------------------------------------------------------------ -// Defined Values -//------------------------------------------------------------------------------ -#define FMC_FPGA_BASE_ADDR 0x60000000 -#define FMC_FPGA_ADDR_MASK 0x00FFFFFC -#define FMC_FPGA_NWAIT_MAX_POLL_TICKS 10 - -#define FMC_GPIO_PORT_NWAIT GPIOD -#define FMC_GPIO_PIN_NWAIT GPIO_PIN_6 - -#define FMC_NWAIT_IDLE GPIO_PIN_SET - - -//------------------------------------------------------------------------------ -// Variables -//------------------------------------------------------------------------------ -static SRAM_HandleTypeDef _fmc_fpga_inst; - - -//------------------------------------------------------------------------------ -// Prototypes -//------------------------------------------------------------------------------ -static void _fmc_init_gpio(void); -static void _fmc_init_params(void); -static int _fmc_nwait_idle(void); - - -//------------------------------------------------------------------------------ -void fmc_init(void) -//------------------------------------------------------------------------------ -{ - // configure fmc pins - _fmc_init_gpio(); - - // configure fmc registers - _fmc_init_params(); -} - - -//------------------------------------------------------------------------------ -int fmc_write_32(uint32_t addr, uint32_t *data) -//------------------------------------------------------------------------------ -{ - // calculate target fpga address - uint32_t ptr = FMC_FPGA_BASE_ADDR + (addr & FMC_FPGA_ADDR_MASK); - - // write data to fpga - HAL_StatusTypeDef ok = HAL_SRAM_Write_32b(&_fmc_fpga_inst, (uint32_t *)ptr, data, 1); - - // check for error - if (ok != HAL_OK) return -1; - - // wait for transaction to complete - int wait = _fmc_nwait_idle(); - - // check for timeout - if (wait != 0) return -1; - - // everything went ok - return 0; -} - - -//------------------------------------------------------------------------------ -int fmc_read_32(uint32_t addr, uint32_t *data) -//------------------------------------------------------------------------------ -{ - // calculate target fpga address - uint32_t ptr = FMC_FPGA_BASE_ADDR + (addr & FMC_FPGA_ADDR_MASK); - - // perform dummy read transaction - HAL_StatusTypeDef ok = HAL_SRAM_Read_32b(&_fmc_fpga_inst, (uint32_t *)ptr, data, 1); - - // check for error - if (ok != HAL_OK) return -1; - - // wait for dummy transaction to complete - int wait = _fmc_nwait_idle(); - - // check for timeout - if (wait != 0) return -1; - - // read data from fpga - ok = HAL_SRAM_Read_32b(&_fmc_fpga_inst, (uint32_t *)ptr, data, 1); - - // check for error - if (ok != HAL_OK) return -1; - - // wait for read transaction to complete - wait = _fmc_nwait_idle(); - - // check for timeout - if (wait != 0) return -1; - - // everything went ok - return 0; -} - - -//------------------------------------------------------------------------------ -static int _fmc_nwait_idle() -//------------------------------------------------------------------------------ -{ - int cnt; // counter - - // poll NWAIT (number of iterations is limited) - for (cnt=0; cnt= FMC_FPGA_NWAIT_MAX_POLL_TICKS) return -1; - - // ok - return 0; -} - -//------------------------------------------------------------------------------ -static void _fmc_init_gpio(void) -//------------------------------------------------------------------------------ -{ - // enable gpio clocks - __GPIOA_CLK_ENABLE(); - __GPIOB_CLK_ENABLE(); - __GPIOD_CLK_ENABLE(); - __GPIOE_CLK_ENABLE(); - __GPIOF_CLK_ENABLE(); - __GPIOG_CLK_ENABLE(); - __GPIOH_CLK_ENABLE(); - __GPIOI_CLK_ENABLE(); - - // enable fmc clock - __FMC_CLK_ENABLE(); - - // structure - GPIO_InitTypeDef GPIO_InitStruct; - - // Port B - GPIO_InitStruct.Pin = GPIO_PIN_7; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF12_FMC; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - // Port D - GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 - |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15 - |GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_3|GPIO_PIN_4 - |GPIO_PIN_5|GPIO_PIN_7; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF12_FMC; - HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /* - * When FMC is working with fixed latency, NWAIT pin must not be - * configured in AF mode, according to STM32F429 errata. - */ - - // Port D (GPIO!) - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - // Port E - GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_7 - |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 - |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF12_FMC; - HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - - // Port F - GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 - |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_12|GPIO_PIN_13 - |GPIO_PIN_14|GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF12_FMC; - HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - // Port G - GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 - |GPIO_PIN_4|GPIO_PIN_5; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF12_FMC; - HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - // Port H - GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 - |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF12_FMC; - HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); - - // Port I - GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_0|GPIO_PIN_1 - |GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_6|GPIO_PIN_7; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF12_FMC; - HAL_GPIO_Init(GPIOI, &GPIO_InitStruct); -} - - -//------------------------------------------------------------------------------ -static void _fmc_init_params(void) -//------------------------------------------------------------------------------ -{ - /* - * fill internal fields - */ - _fmc_fpga_inst.Instance = FMC_NORSRAM_DEVICE; - _fmc_fpga_inst.Extended = FMC_NORSRAM_EXTENDED_DEVICE; - - - /* - * configure fmc interface settings - */ - - // use the first bank and corresponding chip select - _fmc_fpga_inst.Init.NSBank = FMC_NORSRAM_BANK1; - - // data and address buses are separate - _fmc_fpga_inst.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE; - - // fpga mimics psram-type memory - _fmc_fpga_inst.Init.MemoryType = FMC_MEMORY_TYPE_PSRAM; - - // data bus is 32-bit - _fmc_fpga_inst.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_32; - - // read transaction is sync - _fmc_fpga_inst.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_ENABLE; - - // this _must_ be configured to high, according to errata, otherwise - // the processor may hang after trying to access fpga via fmc - _fmc_fpga_inst.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_HIGH; - - // wrap mode is not supported - _fmc_fpga_inst.Init.WrapMode = FMC_WRAP_MODE_DISABLE; - - // don't care in fixed latency mode - _fmc_fpga_inst.Init.WaitSignalActive = FMC_WAIT_TIMING_DURING_WS; - - // allow write access to fpga - _fmc_fpga_inst.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE; - - // use fixed latency mode (ignore wait signal) - _fmc_fpga_inst.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE; - - // write and read have same timing - _fmc_fpga_inst.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE; - - // don't care in sync mode - _fmc_fpga_inst.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE; - - // write transaction is sync - _fmc_fpga_inst.Init.WriteBurst = FMC_WRITE_BURST_ENABLE; - - // keep clock always active - _fmc_fpga_inst.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ASYNC; - - /* - * configure fmc timing parameters - */ - FMC_NORSRAM_TimingTypeDef fmc_timing; - - // don't care in sync mode - fmc_timing.AddressSetupTime = 15; - - // don't care in sync mode - fmc_timing.AddressHoldTime = 15; - - // don't care in sync mode - fmc_timing.DataSetupTime = 255; - - // not needed, since nwait will be polled manually - fmc_timing.BusTurnAroundDuration = 0; - - // use smallest allowed divisor for best performance - fmc_timing.CLKDivision = 2; - - // stm is too slow to work with min allowed 2-cycle latency - fmc_timing.DataLatency = 3; - - // don't care in sync mode - fmc_timing.AccessMode = FMC_ACCESS_MODE_A; - - // initialize fmc - HAL_SRAM_Init(&_fmc_fpga_inst, &fmc_timing, NULL); -} - - -//------------------------------------------------------------------------------ -// EOF -//------------------------------------------------------------------------------ diff --git a/src/stm-init.c b/src/stm-init.c deleted file mode 100644 index f8610cd..0000000 --- a/src/stm-init.c +++ /dev/null @@ -1,189 +0,0 @@ -/** - ****************************************************************************** - * File Name : main.c - * Date : 08/07/2015 17:46:00 - * Description : Main program body - ****************************************************************************** - * - * COPYRIGHT(c) 2015 STMicroelectronics - * - * 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. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx_hal.h" -#include "stm-init.h" -#include "stm-led.h" -#include "stm-fmc.h" -#include "stm-uart.h" - -/* Private variables ---------------------------------------------------------*/ -static GPIO_InitTypeDef GPIO_InitStruct; - -/* Private function prototypes -----------------------------------------------*/ -static void SystemClock_Config(void); -static void MX_GPIO_Init(void); - -void stm_init(void) -{ - - /* MCU Configuration----------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); - - /* Configure the system clock */ - SystemClock_Config(); - - /* System interrupt init*/ - /* Sets the priority grouping field */ - HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0); - HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_USART2_UART_Init(); -} - -/** System Clock Configuration - * - * HSE crystal at 25 MHz, end result is 180 MHz clock. - */ -static void SystemClock_Config(void) -{ - RCC_ClkInitTypeDef RCC_ClkInitStruct; - RCC_OscInitTypeDef RCC_OscInitStruct; - - __PWR_CLK_ENABLE(); - - __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); - - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLM = 25; - RCC_OscInitStruct.PLL.PLLN = 360; - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; - RCC_OscInitStruct.PLL.PLLQ = 4; - HAL_RCC_OscConfig(&RCC_OscInitStruct); - - HAL_PWREx_ActivateOverDrive(); - - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5); -} - -#if 0 -/** System Clock Configuration - * - * HSI source, end result is 16 MHz SYSCLK - * -*/ -static void old_SystemClock_Config(void) -{ - - RCC_OscInitTypeDef RCC_OscInitStruct; - - __PWR_CLK_ENABLE(); - - __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3); - - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.HSICalibrationValue = 6; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; - HAL_RCC_OscConfig(&RCC_OscInitStruct); - - /* XXX Does this need HAL_PWREx_ActivateOverDrive() and - * HAL_RCC_ClockConfig() to function properly?? - */ -} -#endif - -/** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI -*/ -static void MX_GPIO_Init(void) -{ - /* GPIO Ports Clock Enable */ - __GPIOJ_CLK_ENABLE(); - - /* Configure LED GPIO pins PJ1==red, PJ2==yellow, PJ3==green, PJ4==blue */ - GPIO_InitStruct.Pin = LED_RED | LED_YELLOW | LED_GREEN | LED_BLUE; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_LOW; - HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct); -} - -/** - * @brief This function is executed in case of error occurrence. - * @param None - * @retval None - */ -void Error_Handler(void) -{ - HAL_GPIO_WritePin(LED_PORT, LED_RED, GPIO_PIN_SET); - while (1) { ; } -} - -#ifdef USE_FULL_ASSERT - -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t* file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line number, - ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* USER CODE END 6 */ - -} - -#endif - -/** - * @} - */ - -/** - * @} -*/ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/stm-uart.c b/src/stm-uart.c deleted file mode 100644 index 7676645..0000000 --- a/src/stm-uart.c +++ /dev/null @@ -1,76 +0,0 @@ -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx_hal.h" -#include "stm-uart.h" - -#include - -static UART_HandleTypeDef huart2; - -extern void Error_Handler(); - - -/* Private variables ---------------------------------------------------------*/ - -/* Private function prototypes -----------------------------------------------*/ - -/* USART2 init function */ -void MX_USART2_UART_Init(void) -{ - huart2.Instance = USART2; - huart2.Init.BaudRate = USART2_BAUD_RATE; - huart2.Init.WordLength = UART_WORDLENGTH_8B; - huart2.Init.StopBits = UART_STOPBITS_1; - huart2.Init.Parity = UART_PARITY_NONE; - huart2.Init.Mode = UART_MODE_TX_RX; - huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; - huart2.Init.OverSampling = UART_OVERSAMPLING_16; - - if (HAL_UART_Init(&huart2) != HAL_OK) { - /* Initialization Error */ - Error_Handler(); - } -} - -void uart_send_char(uint8_t ch) -{ - HAL_UART_Transmit(&huart2, &ch, 1, 0x1); -} - -void uart_send_string(char *s) -{ - HAL_UART_Transmit(&huart2, (uint8_t *) s, strlen(s), 0x1); -} - -/* Generalized routine to send binary, decimal, and hex integers. - * This code is adapted from Chris Giese's printf.c - */ -void uart_send_number(uint32_t num, uint8_t digits, uint8_t radix) -{ - #define BUFSIZE 32 - char buf[BUFSIZE]; - char *where = buf + BUFSIZE; - - /* initialize buf so we can add leading 0 by adjusting the pointer */ - memset(buf, '0', BUFSIZE); - - /* build the string backwards, starting with the least significant digit */ - do { - uint32_t temp; - temp = num % radix; - where--; - if (temp < 10) - *where = temp + '0'; - else - *where = temp - 10 + 'A'; - num = num / radix; - } while (num != 0); - - if (where > buf + BUFSIZE - digits) - /* pad with leading 0 */ - where = buf + BUFSIZE - digits; - else - /* number is larger than the specified number of digits */ - digits = buf + BUFSIZE - where; - - HAL_UART_Transmit(&huart2, (uint8_t *) where, digits, 0x1); -} diff --git a/src/stm32f4xx_hal_msp.c b/src/stm32f4xx_hal_msp.c deleted file mode 100644 index ee2cb7e..0000000 --- a/src/stm32f4xx_hal_msp.c +++ /dev/null @@ -1,143 +0,0 @@ -/** -****************************************************************************** -* File Name : stm32f4xx_hal_msp.c -* Description : This file provides code for the MSP Initialization -* and de-Initialization codes. -****************************************************************************** -* -* COPYRIGHT(c) 2015 STMicroelectronics -* -* 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. -* 3. Neither the name of STMicroelectronics nor the names of its contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. -* -****************************************************************************** -*/ -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx_hal.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/** - * Initializes the Global MSP. - */ -void HAL_MspInit(void) -{ - /* USER CODE BEGIN MspInit 0 */ - - /* USER CODE END MspInit 0 */ - - HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); - - /* System interrupt init*/ - /* SysTick_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -void HAL_RNG_MspInit(RNG_HandleTypeDef* hrng) -{ - - if(hrng->Instance==RNG) - { - /* USER CODE BEGIN RNG_MspInit 0 */ - - /* USER CODE END RNG_MspInit 0 */ - /* Peripheral clock enable */ - __RNG_CLK_ENABLE(); - /* USER CODE BEGIN RNG_MspInit 1 */ - - /* USER CODE END RNG_MspInit 1 */ - } - -} - -void HAL_RNG_MspDeInit(RNG_HandleTypeDef* hrng) -{ - - if(hrng->Instance==RNG) - { - /* USER CODE BEGIN RNG_MspDeInit 0 */ - - /* USER CODE END RNG_MspDeInit 0 */ - /* Peripheral clock disable */ - __RNG_CLK_DISABLE(); - } - /* USER CODE BEGIN RNG_MspDeInit 1 */ - - /* USER CODE END RNG_MspDeInit 1 */ - -} - - - -void HAL_SRAM_MspInit(SRAM_HandleTypeDef* hsram) -{ -} - - -void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef* hsram) -{ -} - -void HAL_UART_MspInit(UART_HandleTypeDef* huart) -{ - GPIO_InitTypeDef GPIO_InitStruct; - - if (huart->Instance == USART2) { - /* Peripheral clock enable */ - __USART2_CLK_ENABLE(); - __GPIOA_CLK_ENABLE(); - - /**USART2 GPIO Configuration - PA2 ------> USART2_TX - PA3 ------> USART2_RX - */ - GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_LOW; - GPIO_InitStruct.Alternate = GPIO_AF7_USART2; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - } - -} - -void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) -{ - if (huart->Instance == USART2) { - /* Peripheral clock disable */ - __USART2_CLK_DISABLE(); - - /**USART2 GPIO Configuration - PA2 ------> USART2_TX - PA3 ------> USART2_RX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2 | GPIO_PIN_3); - } -} - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/stm32f4xx_it.c b/src/stm32f4xx_it.c deleted file mode 100644 index b2b64bf..0000000 --- a/src/stm32f4xx_it.c +++ /dev/null @@ -1,73 +0,0 @@ -/** -****************************************************************************** -* @file stm32f4xx_it.c -* @brief Interrupt Service Routines. -****************************************************************************** -* -* COPYRIGHT(c) 2015 STMicroelectronics -* -* 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. -* 3. Neither the name of STMicroelectronics nor the names of its contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. -* -****************************************************************************** -*/ -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx_hal.h" -#include "stm32f4xx.h" -#include "stm32f4xx_it.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* External variables --------------------------------------------------------*/ - -/******************************************************************************/ -/* Cortex-M4 Processor Interruption and Exception Handlers */ -/******************************************************************************/ - -/** - * @brief This function handles System tick timer. - */ -void SysTick_Handler(void) -{ - /* USER CODE BEGIN SysTick_IRQn 0 */ - - /* USER CODE END SysTick_IRQn 0 */ - HAL_IncTick(); - HAL_SYSTICK_IRQHandler(); - /* USER CODE BEGIN SysTick_IRQn 1 */ - - /* USER CODE END SysTick_IRQn 1 */ -} - -/******************************************************************************/ -/* STM32F4xx Peripheral Interrupt Handlers */ -/* Add here the Interrupt Handlers for the used peripherals. */ -/* For the available peripheral interrupt handler names, */ -/* please refer to the startup file (startup_stm32f4xx.s). */ -/******************************************************************************/ - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/stm-fmc.c b/stm-fmc.c new file mode 100644 index 0000000..3b36cbf --- /dev/null +++ b/stm-fmc.c @@ -0,0 +1,355 @@ +/* + * stm-fmc.c + * --------- + * Functions to set up and use the FMC bus. + * + * Copyright (c) 2015, NORDUnet A/S All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - 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. + * + * - Neither the name of the NORDUnet nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT + * HOLDER 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. + */ + + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ +#include "stm-fmc.h" +#include "stm32f4xx_hal.h" + + +//------------------------------------------------------------------------------ +// Defined Values +//------------------------------------------------------------------------------ +#define FMC_FPGA_BASE_ADDR 0x60000000 +#define FMC_FPGA_ADDR_MASK 0x00FFFFFC +#define FMC_FPGA_NWAIT_MAX_POLL_TICKS 10 + +#define FMC_GPIO_PORT_NWAIT GPIOD +#define FMC_GPIO_PIN_NWAIT GPIO_PIN_6 + +#define FMC_NWAIT_IDLE GPIO_PIN_SET + + +//------------------------------------------------------------------------------ +// Variables +//------------------------------------------------------------------------------ +static SRAM_HandleTypeDef _fmc_fpga_inst; + + +//------------------------------------------------------------------------------ +// Prototypes +//------------------------------------------------------------------------------ +static void _fmc_init_gpio(void); +static void _fmc_init_params(void); +static int _fmc_nwait_idle(void); + + +//------------------------------------------------------------------------------ +void fmc_init(void) +//------------------------------------------------------------------------------ +{ + // configure fmc pins + _fmc_init_gpio(); + + // configure fmc registers + _fmc_init_params(); +} + + +//------------------------------------------------------------------------------ +int fmc_write_32(uint32_t addr, uint32_t *data) +//------------------------------------------------------------------------------ +{ + // calculate target fpga address + uint32_t ptr = FMC_FPGA_BASE_ADDR + (addr & FMC_FPGA_ADDR_MASK); + + // write data to fpga + HAL_StatusTypeDef ok = HAL_SRAM_Write_32b(&_fmc_fpga_inst, (uint32_t *)ptr, data, 1); + + // check for error + if (ok != HAL_OK) return -1; + + // wait for transaction to complete + int wait = _fmc_nwait_idle(); + + // check for timeout + if (wait != 0) return -1; + + // everything went ok + return 0; +} + + +//------------------------------------------------------------------------------ +int fmc_read_32(uint32_t addr, uint32_t *data) +//------------------------------------------------------------------------------ +{ + // calculate target fpga address + uint32_t ptr = FMC_FPGA_BASE_ADDR + (addr & FMC_FPGA_ADDR_MASK); + + // perform dummy read transaction + HAL_StatusTypeDef ok = HAL_SRAM_Read_32b(&_fmc_fpga_inst, (uint32_t *)ptr, data, 1); + + // check for error + if (ok != HAL_OK) return -1; + + // wait for dummy transaction to complete + int wait = _fmc_nwait_idle(); + + // check for timeout + if (wait != 0) return -1; + + // read data from fpga + ok = HAL_SRAM_Read_32b(&_fmc_fpga_inst, (uint32_t *)ptr, data, 1); + + // check for error + if (ok != HAL_OK) return -1; + + // wait for read transaction to complete + wait = _fmc_nwait_idle(); + + // check for timeout + if (wait != 0) return -1; + + // everything went ok + return 0; +} + + +//------------------------------------------------------------------------------ +static int _fmc_nwait_idle() +//------------------------------------------------------------------------------ +{ + int cnt; // counter + + // poll NWAIT (number of iterations is limited) + for (cnt=0; cnt= FMC_FPGA_NWAIT_MAX_POLL_TICKS) return -1; + + // ok + return 0; +} + +//------------------------------------------------------------------------------ +static void _fmc_init_gpio(void) +//------------------------------------------------------------------------------ +{ + // enable gpio clocks + __GPIOA_CLK_ENABLE(); + __GPIOB_CLK_ENABLE(); + __GPIOD_CLK_ENABLE(); + __GPIOE_CLK_ENABLE(); + __GPIOF_CLK_ENABLE(); + __GPIOG_CLK_ENABLE(); + __GPIOH_CLK_ENABLE(); + __GPIOI_CLK_ENABLE(); + + // enable fmc clock + __FMC_CLK_ENABLE(); + + // structure + GPIO_InitTypeDef GPIO_InitStruct; + + // Port B + GPIO_InitStruct.Pin = GPIO_PIN_7; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF12_FMC; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + // Port D + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 + |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15 + |GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_3|GPIO_PIN_4 + |GPIO_PIN_5|GPIO_PIN_7; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF12_FMC; + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /* + * When FMC is working with fixed latency, NWAIT pin must not be + * configured in AF mode, according to STM32F429 errata. + */ + + // Port D (GPIO!) + GPIO_InitStruct.Pin = GPIO_PIN_6; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_PULLUP; + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + // Port E + GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_7 + |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 + |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF12_FMC; + HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); + + // Port F + GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 + |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_12|GPIO_PIN_13 + |GPIO_PIN_14|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF12_FMC; + HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + // Port G + GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 + |GPIO_PIN_4|GPIO_PIN_5; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF12_FMC; + HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + // Port H + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 + |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF12_FMC; + HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); + + // Port I + GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_0|GPIO_PIN_1 + |GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_6|GPIO_PIN_7; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF12_FMC; + HAL_GPIO_Init(GPIOI, &GPIO_InitStruct); +} + + +//------------------------------------------------------------------------------ +static void _fmc_init_params(void) +//------------------------------------------------------------------------------ +{ + /* + * fill internal fields + */ + _fmc_fpga_inst.Instance = FMC_NORSRAM_DEVICE; + _fmc_fpga_inst.Extended = FMC_NORSRAM_EXTENDED_DEVICE; + + + /* + * configure fmc interface settings + */ + + // use the first bank and corresponding chip select + _fmc_fpga_inst.Init.NSBank = FMC_NORSRAM_BANK1; + + // data and address buses are separate + _fmc_fpga_inst.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE; + + // fpga mimics psram-type memory + _fmc_fpga_inst.Init.MemoryType = FMC_MEMORY_TYPE_PSRAM; + + // data bus is 32-bit + _fmc_fpga_inst.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_32; + + // read transaction is sync + _fmc_fpga_inst.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_ENABLE; + + // this _must_ be configured to high, according to errata, otherwise + // the processor may hang after trying to access fpga via fmc + _fmc_fpga_inst.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_HIGH; + + // wrap mode is not supported + _fmc_fpga_inst.Init.WrapMode = FMC_WRAP_MODE_DISABLE; + + // don't care in fixed latency mode + _fmc_fpga_inst.Init.WaitSignalActive = FMC_WAIT_TIMING_DURING_WS; + + // allow write access to fpga + _fmc_fpga_inst.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE; + + // use fixed latency mode (ignore wait signal) + _fmc_fpga_inst.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE; + + // write and read have same timing + _fmc_fpga_inst.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE; + + // don't care in sync mode + _fmc_fpga_inst.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE; + + // write transaction is sync + _fmc_fpga_inst.Init.WriteBurst = FMC_WRITE_BURST_ENABLE; + + // keep clock always active + _fmc_fpga_inst.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ASYNC; + + /* + * configure fmc timing parameters + */ + FMC_NORSRAM_TimingTypeDef fmc_timing; + + // don't care in sync mode + fmc_timing.AddressSetupTime = 15; + + // don't care in sync mode + fmc_timing.AddressHoldTime = 15; + + // don't care in sync mode + fmc_timing.DataSetupTime = 255; + + // not needed, since nwait will be polled manually + fmc_timing.BusTurnAroundDuration = 0; + + // use smallest allowed divisor for best performance + fmc_timing.CLKDivision = 2; + + // stm is too slow to work with min allowed 2-cycle latency + fmc_timing.DataLatency = 3; + + // don't care in sync mode + fmc_timing.AccessMode = FMC_ACCESS_MODE_A; + + // initialize fmc + HAL_SRAM_Init(&_fmc_fpga_inst, &fmc_timing, NULL); +} + + +//------------------------------------------------------------------------------ +// EOF +//------------------------------------------------------------------------------ diff --git a/stm-fmc.h b/stm-fmc.h new file mode 100644 index 0000000..9e34d32 --- /dev/null +++ b/stm-fmc.h @@ -0,0 +1,45 @@ +/* + * stm-fmc.h + * --------- + * Functions to set up and use the FMC bus. + * + * Copyright (c) 2015, NORDUnet A/S All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - 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. + * + * - Neither the name of the NORDUnet nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT + * HOLDER 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. + */ + +#ifndef __STM_FMC_H +#define __STM_FMC_H + +#include + +extern void fmc_init(void); + +extern int fmc_write_32(uint32_t addr, uint32_t *data); +extern int fmc_read_32(uint32_t addr, uint32_t *data); + +#endif /* __STM_FMC_H */ diff --git a/stm-init.c b/stm-init.c new file mode 100644 index 0000000..aef1b95 --- /dev/null +++ b/stm-init.c @@ -0,0 +1,231 @@ +/** + ****************************************************************************** + * File Name : main.c + * Date : 08/07/2015 17:46:00 + * Description : Main program body + ****************************************************************************** + * + * COPYRIGHT(c) 2015 STMicroelectronics + * + * 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. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f4xx_hal.h" +#include "stm-init.h" +#ifdef HAL_GPIO_MODULE_ENABLED +#include "stm-led.h" +#endif +#ifdef HAL_SRAM_MODULE_ENABLED +#include "stm-fmc.h" +#endif +#ifdef HAL_UART_MODULE_ENABLED +#include "stm-uart.h" +#endif + +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ +static void SystemClock_Config(void); +#ifdef HAL_GPIO_MODULE_ENABLED +static void MX_GPIO_Init(void); +#endif +#ifdef HAL_UART_MODULE_ENABLED +static void MX_USART2_UART_Init(void); +#endif + +void stm_init(void) +{ + + /* MCU Configuration----------------------------------------------------------*/ + + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); + + /* Configure the system clock */ + SystemClock_Config(); + + /* System interrupt init*/ + /* Sets the priority grouping field */ + HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0); + HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); + + /* Initialize all configured peripherals */ +#ifdef HAL_GPIO_MODULE_ENABLED + MX_GPIO_Init(); +#endif +#ifdef HAL_UART_MODULE_ENABLED + MX_USART2_UART_Init(); +#endif +} + +/** System Clock Configuration + * + * HSE crystal at 25 MHz, end result is 180 MHz clock. + */ +static void SystemClock_Config(void) +{ + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_OscInitTypeDef RCC_OscInitStruct; + + __PWR_CLK_ENABLE(); + + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); + + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLM = 25; + RCC_OscInitStruct.PLL.PLLN = 360; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; + RCC_OscInitStruct.PLL.PLLQ = 4; + HAL_RCC_OscConfig(&RCC_OscInitStruct); + + HAL_PWREx_ActivateOverDrive(); + + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5); +} + +#if 0 +/** System Clock Configuration + * + * HSI source, end result is 16 MHz SYSCLK + * +*/ +static void old_SystemClock_Config(void) +{ + + RCC_OscInitTypeDef RCC_OscInitStruct; + + __PWR_CLK_ENABLE(); + + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3); + + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSICalibrationValue = 6; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; + HAL_RCC_OscConfig(&RCC_OscInitStruct); + + /* XXX Does this need HAL_PWREx_ActivateOverDrive() and + * HAL_RCC_ClockConfig() to function properly?? + */ +} +#endif + +#ifdef HAL_UART_MODULE_ENABLED +/* USART2 init function */ +static void MX_USART2_UART_Init(void) +{ + extern UART_HandleTypeDef huart2; + + huart2.Instance = USART2; + huart2.Init.BaudRate = USART2_BAUD_RATE; + huart2.Init.WordLength = UART_WORDLENGTH_8B; + huart2.Init.StopBits = UART_STOPBITS_1; + huart2.Init.Parity = UART_PARITY_NONE; + huart2.Init.Mode = UART_MODE_TX_RX; + huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart2.Init.OverSampling = UART_OVERSAMPLING_16; + + if (HAL_UART_Init(&huart2) != HAL_OK) { + /* Initialization Error */ + Error_Handler(); + } +} +#endif + +#ifdef HAL_GPIO_MODULE_ENABLED +/** Configure pins as + * Analog + * Input + * Output + * EVENT_OUT + * EXTI +*/ +static void MX_GPIO_Init(void) +{ + GPIO_InitTypeDef GPIO_InitStruct; + + /* GPIO Ports Clock Enable */ + __GPIOJ_CLK_ENABLE(); + + /* Configure LED GPIO pins PJ1==red, PJ2==yellow, PJ3==green, PJ4==blue */ + GPIO_InitStruct.Pin = LED_RED | LED_YELLOW | LED_GREEN | LED_BLUE; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_LOW; + HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct); +} +#endif + +/** + * @brief This function is executed in case of error occurrence. + * @param None + * @retval None + */ +void Error_Handler(void) +{ +#ifdef HAL_GPIO_MODULE_ENABLED + HAL_GPIO_WritePin(LED_PORT, LED_RED, GPIO_PIN_SET); +#endif + while (1) { ; } +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ +void assert_failed(uint8_t* file, uint32_t line) +{ + /* USER CODE BEGIN 6 */ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + /* USER CODE END 6 */ + +} + +#endif + +/** + * @} + */ + +/** + * @} +*/ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/stm-init.h b/stm-init.h new file mode 100644 index 0000000..60a728a --- /dev/null +++ b/stm-init.h @@ -0,0 +1,43 @@ +/* + * stm-init.h + * ---------- + * Functions to set up the stm32 peripherals. + * + * Copyright (c) 2015, NORDUnet A/S All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - 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. + * + * - Neither the name of the NORDUnet nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT + * HOLDER 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. + */ + +#ifndef __STM_INIT_H +#define __STM_INIT_H + +#include "stm32f4xx_hal.h" + +extern void stm_init(void); +extern void Error_Handler(void); + +#endif /* __STM_INIT_H */ diff --git a/stm-led.h b/stm-led.h new file mode 100644 index 0000000..5af084a --- /dev/null +++ b/stm-led.h @@ -0,0 +1,50 @@ +/* + * stm-led.h + * --------- + * Defines to control the LEDs through GPIO pins. + * + * Copyright (c) 2015, NORDUnet A/S All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - 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. + * + * - Neither the name of the NORDUnet nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT + * HOLDER 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. + */ + +#ifndef __STM_LED_H +#define __STM_LED_H + +#include "stm32f4xx_hal.h" + +#define LED_PORT GPIOJ +#define LED_RED GPIO_PIN_1 +#define LED_YELLOW GPIO_PIN_2 +#define LED_GREEN GPIO_PIN_3 +#define LED_BLUE GPIO_PIN_4 + +#define led_on(pin) HAL_GPIO_WritePin(LED_PORT,pin,SET) +#define led_off(pin) HAL_GPIO_WritePin(LED_PORT,pin,RESET) +#define led_toggle(pin) HAL_GPIO_TogglePin(LED_PORT,pin) + +#endif /* __STM_LED_H */ diff --git a/stm-uart.c b/stm-uart.c new file mode 100644 index 0000000..602a59c --- /dev/null +++ b/stm-uart.c @@ -0,0 +1,87 @@ +/* + * stm-uart.c + * ---------- + * Functions for sending strings and numbers over the uart. + * + * Copyright (c) 2015, NORDUnet A/S All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - 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. + * + * - Neither the name of the NORDUnet nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT + * HOLDER 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 "stm32f4xx_hal.h" +#include "stm-uart.h" + +#include + +/* initialized in MX_USART2_UART_Init() in stm-init.c */ +UART_HandleTypeDef huart2; + +/* send a single character */ +void uart_send_char(uint8_t ch) +{ + HAL_UART_Transmit(&huart2, &ch, 1, 0x1); +} + +/* send a string */ +void uart_send_string(char *s) +{ + HAL_UART_Transmit(&huart2, (uint8_t *) s, strlen(s), 0x1); +} + +/* Generalized routine to send binary, decimal, and hex integers. + * This code is adapted from Chris Giese's printf.c + */ +void uart_send_number(uint32_t num, uint8_t digits, uint8_t radix) +{ + #define BUFSIZE 32 + char buf[BUFSIZE]; + char *where = buf + BUFSIZE; + + /* initialize buf so we can add leading 0 by adjusting the pointer */ + memset(buf, '0', BUFSIZE); + + /* build the string backwards, starting with the least significant digit */ + do { + uint32_t temp; + temp = num % radix; + where--; + if (temp < 10) + *where = temp + '0'; + else + *where = temp - 10 + 'A'; + num = num / radix; + } while (num != 0); + + if (where > buf + BUFSIZE - digits) + /* pad with leading 0 */ + where = buf + BUFSIZE - digits; + else + /* number is larger than the specified number of digits */ + digits = buf + BUFSIZE - where; + + HAL_UART_Transmit(&huart2, (uint8_t *) where, digits, 0x1); +} diff --git a/stm-uart.h b/stm-uart.h new file mode 100644 index 0000000..7019a48 --- /dev/null +++ b/stm-uart.h @@ -0,0 +1,49 @@ +/* + * stm-uart.h + * --------- + * Functions and defines to use the UART. + * + * Copyright (c) 2015, NORDUnet A/S All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - 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. + * + * - Neither the name of the NORDUnet nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT + * HOLDER 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. + */ + +#ifndef __STM32_UART_H +#define __STM32_UART_H + +#include "stm32f4xx_hal.h" + +#define USART2_BAUD_RATE 115200 + +extern void uart_send_char(uint8_t ch); +extern void uart_send_string(char *s); +extern void uart_send_number(uint32_t num, uint8_t digits, uint8_t radix); +#define uart_send_binary(num, bits) uart_send_number(num, bits, 2) +#define uart_send_integer(num, digits) uart_send_number(num, digits, 10) +#define uart_send_hex(num, digits) uart_send_number(num, digits, 16) + +#endif /* __STM32_UART_H */ diff --git a/stm32f4xx_hal_conf.h b/stm32f4xx_hal_conf.h new file mode 100644 index 0000000..fd13d9e --- /dev/null +++ b/stm32f4xx_hal_conf.h @@ -0,0 +1,423 @@ +/** + ****************************************************************************** + * @file stm32f4xx_hal_conf.h + * @brief HAL configuration file. + ****************************************************************************** + * @attention + * + *

© COPYRIGHT(c) 2015 STMicroelectronics

+ * + * 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. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F4xx_HAL_CONF_H +#define __STM32F4xx_HAL_CONF_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ + +/* ########################## Module Selection ############################## */ +/** + * @brief This is the list of modules to be used in the HAL driver + */ +#define HAL_MODULE_ENABLED + +//#define HAL_ADC_MODULE_ENABLED +//#define HAL_CAN_MODULE_ENABLED +//#define HAL_CRC_MODULE_ENABLED +//#define HAL_CRYP_MODULE_ENABLED +//#define HAL_DAC_MODULE_ENABLED +//#define HAL_DCMI_MODULE_ENABLED +//#define HAL_DMA2D_MODULE_ENABLED +//#define HAL_ETH_MODULE_ENABLED +//#define HAL_NAND_MODULE_ENABLED +//#define HAL_NOR_MODULE_ENABLED +//#define HAL_PCCARD_MODULE_ENABLED +#define HAL_SRAM_MODULE_ENABLED +//#define HAL_SDRAM_MODULE_ENABLED +//#define HAL_HASH_MODULE_ENABLED +//#define HAL_I2C_MODULE_ENABLED +//#define HAL_I2S_MODULE_ENABLED +//#define HAL_IWDG_MODULE_ENABLED +//#define HAL_LTDC_MODULE_ENABLED +#define HAL_RNG_MODULE_ENABLED +//#define HAL_RTC_MODULE_ENABLED +//#define HAL_SAI_MODULE_ENABLED +//#define HAL_SD_MODULE_ENABLED +//#define HAL_SPI_MODULE_ENABLED +//#define HAL_TIM_MODULE_ENABLED +#define HAL_UART_MODULE_ENABLED +//#define HAL_USART_MODULE_ENABLED +//#define HAL_IRDA_MODULE_ENABLED +//#define HAL_SMARTCARD_MODULE_ENABLED +//#define HAL_WWDG_MODULE_ENABLED +//#define HAL_PCD_MODULE_ENABLED +//#define HAL_HCD_MODULE_ENABLED +//#define HAL_QSPI_MODULE_ENABLED +//#define HAL_QSPI_MODULE_ENABLED +//#define HAL_CEC_MODULE_ENABLED +//#define HAL_FMPI2C_MODULE_ENABLED +//#define HAL_SPDIFRX_MODULE_ENABLED +#define HAL_GPIO_MODULE_ENABLED +#define HAL_DMA_MODULE_ENABLED +#define HAL_RCC_MODULE_ENABLED +#define HAL_FLASH_MODULE_ENABLED +#define HAL_PWR_MODULE_ENABLED +#define HAL_CORTEX_MODULE_ENABLED + +/* ########################## HSE/HSI Values adaptation ##################### */ +/** + * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSE is used as system clock source, directly or through the PLL). + */ +#if !defined (HSE_VALUE) + #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for HSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ + +/** + * @brief Internal High Speed oscillator (HSI) value. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSI is used as system clock source, directly or through the PLL). + */ +#if !defined (HSI_VALUE) + #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) + #define LSI_VALUE ((uint32_t)32000) +#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz + The real value may vary depending on the variations + in voltage and temperature. */ +/** + * @brief External Low Speed oscillator (LSE) value. + */ +#if !defined (LSE_VALUE) + #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ + +/** + * @brief External clock source for I2S peripheral + * This value is used by the I2S HAL module to compute the I2S clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) + #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000) /*!< Value of the External audio frequency in Hz*/ +#endif /* EXTERNAL_CLOCK_VALUE */ + +/* Tip: To avoid modifying this file each time you need to use different HSE, + === you can define the HSE value in your toolchain compiler preprocessor. */ + +/* ########################### System Configuration ######################### */ +/** + * @brief This is the HAL system configuration section + */ + +#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY ((uint32_t)0) /*!< tick interrupt priority */ +#define USE_RTOS 0 +#define PREFETCH_ENABLE 1 +#define INSTRUCTION_CACHE_ENABLE 1 +#define DATA_CACHE_ENABLE 1 + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +/* #define USE_FULL_ASSERT 1 */ + +/* ################## Ethernet peripheral configuration ##################### */ + +/* Section 1 : Ethernet peripheral configuration */ + +/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ +#define MAC_ADDR0 2 +#define MAC_ADDR1 0 +#define MAC_ADDR2 0 +#define MAC_ADDR3 0 +#define MAC_ADDR4 0 +#define MAC_ADDR5 0 + +/* Definition of the Ethernet driver buffers size and count */ +#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ +#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ +#define ETH_RXBUFNB ((uint32_t)4) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ +#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ + +/* Section 2: PHY configuration section */ + +/* DP83848 PHY Address*/ +#define DP83848_PHY_ADDRESS 0x01 +/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ +#define PHY_RESET_DELAY ((uint32_t)0x000000FF) +/* PHY Configuration delay */ +#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF) + +#define PHY_READ_TO ((uint32_t)0x0000FFFF) +#define PHY_WRITE_TO ((uint32_t)0x0000FFFF) + +/* Section 3: Common PHY Registers */ + +#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */ +#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */ + +#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */ +#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */ +#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */ +#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */ +#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */ +#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */ +#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */ +#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */ +#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */ +#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */ + +#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */ +#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */ +#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */ + +/* Section 4: Extended PHY Registers */ + +#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */ +#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */ +#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */ + +#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */ +#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */ +#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */ + +#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */ +#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */ + +#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */ +#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */ + +/* Includes ------------------------------------------------------------------*/ +/** + * @brief Include module's header file + */ + +#ifdef HAL_RCC_MODULE_ENABLED + #include "stm32f4xx_hal_rcc.h" +#endif /* HAL_RCC_MODULE_ENABLED */ + +#ifdef HAL_GPIO_MODULE_ENABLED + #include "stm32f4xx_hal_gpio.h" +#endif /* HAL_GPIO_MODULE_ENABLED */ + +#ifdef HAL_DMA_MODULE_ENABLED + #include "stm32f4xx_hal_dma.h" +#endif /* HAL_DMA_MODULE_ENABLED */ + +#ifdef HAL_CORTEX_MODULE_ENABLED + #include "stm32f4xx_hal_cortex.h" +#endif /* HAL_CORTEX_MODULE_ENABLED */ + +#ifdef HAL_ADC_MODULE_ENABLED + #include "stm32f4xx_hal_adc.h" +#endif /* HAL_ADC_MODULE_ENABLED */ + +#ifdef HAL_CAN_MODULE_ENABLED + #include "stm32f4xx_hal_can.h" +#endif /* HAL_CAN_MODULE_ENABLED */ + +#ifdef HAL_CRC_MODULE_ENABLED + #include "stm32f4xx_hal_crc.h" +#endif /* HAL_CRC_MODULE_ENABLED */ + +#ifdef HAL_CRYP_MODULE_ENABLED + #include "stm32f4xx_hal_cryp.h" +#endif /* HAL_CRYP_MODULE_ENABLED */ + +#ifdef HAL_DMA2D_MODULE_ENABLED + #include "stm32f4xx_hal_dma2d.h" +#endif /* HAL_DMA2D_MODULE_ENABLED */ + +#ifdef HAL_DAC_MODULE_ENABLED + #include "stm32f4xx_hal_dac.h" +#endif /* HAL_DAC_MODULE_ENABLED */ + +#ifdef HAL_DCMI_MODULE_ENABLED + #include "stm32f4xx_hal_dcmi.h" +#endif /* HAL_DCMI_MODULE_ENABLED */ + +#ifdef HAL_ETH_MODULE_ENABLED + #include "stm32f4xx_hal_eth.h" +#endif /* HAL_ETH_MODULE_ENABLED */ + +#ifdef HAL_FLASH_MODULE_ENABLED + #include "stm32f4xx_hal_flash.h" +#endif /* HAL_FLASH_MODULE_ENABLED */ + +#ifdef HAL_SRAM_MODULE_ENABLED + #include "stm32f4xx_hal_sram.h" +#endif /* HAL_SRAM_MODULE_ENABLED */ + +#ifdef HAL_NOR_MODULE_ENABLED + #include "stm32f4xx_hal_nor.h" +#endif /* HAL_NOR_MODULE_ENABLED */ + +#ifdef HAL_NAND_MODULE_ENABLED + #include "stm32f4xx_hal_nand.h" +#endif /* HAL_NAND_MODULE_ENABLED */ + +#ifdef HAL_PCCARD_MODULE_ENABLED + #include "stm32f4xx_hal_pccard.h" +#endif /* HAL_PCCARD_MODULE_ENABLED */ + +#ifdef HAL_SDRAM_MODULE_ENABLED + #include "stm32f4xx_hal_sdram.h" +#endif /* HAL_SDRAM_MODULE_ENABLED */ + +#ifdef HAL_HASH_MODULE_ENABLED + #include "stm32f4xx_hal_hash.h" +#endif /* HAL_HASH_MODULE_ENABLED */ + +#ifdef HAL_I2C_MODULE_ENABLED + #include "stm32f4xx_hal_i2c.h" +#endif /* HAL_I2C_MODULE_ENABLED */ + +#ifdef HAL_I2S_MODULE_ENABLED + #include "stm32f4xx_hal_i2s.h" +#endif /* HAL_I2S_MODULE_ENABLED */ + +#ifdef HAL_IWDG_MODULE_ENABLED + #include "stm32f4xx_hal_iwdg.h" +#endif /* HAL_IWDG_MODULE_ENABLED */ + +#ifdef HAL_LTDC_MODULE_ENABLED + #include "stm32f4xx_hal_ltdc.h" +#endif /* HAL_LTDC_MODULE_ENABLED */ + +#ifdef HAL_PWR_MODULE_ENABLED + #include "stm32f4xx_hal_pwr.h" +#endif /* HAL_PWR_MODULE_ENABLED */ + +#ifdef HAL_RNG_MODULE_ENABLED + #include "stm32f4xx_hal_rng.h" +#endif /* HAL_RNG_MODULE_ENABLED */ + +#ifdef HAL_RTC_MODULE_ENABLED + #include "stm32f4xx_hal_rtc.h" +#endif /* HAL_RTC_MODULE_ENABLED */ + +#ifdef HAL_SAI_MODULE_ENABLED + #include "stm32f4xx_hal_sai.h" +#endif /* HAL_SAI_MODULE_ENABLED */ + +#ifdef HAL_SD_MODULE_ENABLED + #include "stm32f4xx_hal_sd.h" +#endif /* HAL_SD_MODULE_ENABLED */ + +#ifdef HAL_SPI_MODULE_ENABLED + #include "stm32f4xx_hal_spi.h" +#endif /* HAL_SPI_MODULE_ENABLED */ + +#ifdef HAL_TIM_MODULE_ENABLED + #include "stm32f4xx_hal_tim.h" +#endif /* HAL_TIM_MODULE_ENABLED */ + +#ifdef HAL_UART_MODULE_ENABLED + #include "stm32f4xx_hal_uart.h" +#endif /* HAL_UART_MODULE_ENABLED */ + +#ifdef HAL_USART_MODULE_ENABLED + #include "stm32f4xx_hal_usart.h" +#endif /* HAL_USART_MODULE_ENABLED */ + +#ifdef HAL_IRDA_MODULE_ENABLED + #include "stm32f4xx_hal_irda.h" +#endif /* HAL_IRDA_MODULE_ENABLED */ + +#ifdef HAL_SMARTCARD_MODULE_ENABLED + #include "stm32f4xx_hal_smartcard.h" +#endif /* HAL_SMARTCARD_MODULE_ENABLED */ + +#ifdef HAL_WWDG_MODULE_ENABLED + #include "stm32f4xx_hal_wwdg.h" +#endif /* HAL_WWDG_MODULE_ENABLED */ + +#ifdef HAL_PCD_MODULE_ENABLED + #include "stm32f4xx_hal_pcd.h" +#endif /* HAL_PCD_MODULE_ENABLED */ + +#ifdef HAL_HCD_MODULE_ENABLED + #include "stm32f4xx_hal_hcd.h" +#endif /* HAL_HCD_MODULE_ENABLED */ + +#ifdef HAL_QSPI_MODULE_ENABLED + #include "stm32f4xx_hal_qspi.h" +#endif /* HAL_QSPI_MODULE_ENABLED */ + +#ifdef HAL_CEC_MODULE_ENABLED + #include "stm32f4xx_hal_cec.h" +#endif /* HAL_CEC_MODULE_ENABLED */ + +#ifdef HAL_FMPI2C_MODULE_ENABLED + #include "stm32f4xx_hal_fmpi2c.h" +#endif /* HAL_FMPI2C_MODULE_ENABLED */ + +#ifdef HAL_SPDIFRX_MODULE_ENABLED + #include "stm32f4xx_hal_spdifrx.h" +#endif /* HAL_SPDIFRX_MODULE_ENABLED */ + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr: If expr is false, it calls assert_failed function + * which reports the name of the source file and the source + * line number of the call that failed. + * If expr is true, it returns no value. + * @retval None + */ + #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ + void assert_failed(uint8_t* file, uint32_t line); +#else + #define assert_param(expr) ((void)0) +#endif /* USE_FULL_ASSERT */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F4xx_HAL_CONF_H */ + + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/stm32f4xx_hal_msp.c b/stm32f4xx_hal_msp.c new file mode 100644 index 0000000..ee2cb7e --- /dev/null +++ b/stm32f4xx_hal_msp.c @@ -0,0 +1,143 @@ +/** +****************************************************************************** +* File Name : stm32f4xx_hal_msp.c +* Description : This file provides code for the MSP Initialization +* and de-Initialization codes. +****************************************************************************** +* +* COPYRIGHT(c) 2015 STMicroelectronics +* +* 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. +* 3. Neither the name of STMicroelectronics nor the names of its contributors +* may be used to endorse or promote products derived from this software +* without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. +* +****************************************************************************** +*/ +/* Includes ------------------------------------------------------------------*/ +#include "stm32f4xx_hal.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/** + * Initializes the Global MSP. + */ +void HAL_MspInit(void) +{ + /* USER CODE BEGIN MspInit 0 */ + + /* USER CODE END MspInit 0 */ + + HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); + + /* System interrupt init*/ + /* SysTick_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); + + /* USER CODE BEGIN MspInit 1 */ + + /* USER CODE END MspInit 1 */ +} + +void HAL_RNG_MspInit(RNG_HandleTypeDef* hrng) +{ + + if(hrng->Instance==RNG) + { + /* USER CODE BEGIN RNG_MspInit 0 */ + + /* USER CODE END RNG_MspInit 0 */ + /* Peripheral clock enable */ + __RNG_CLK_ENABLE(); + /* USER CODE BEGIN RNG_MspInit 1 */ + + /* USER CODE END RNG_MspInit 1 */ + } + +} + +void HAL_RNG_MspDeInit(RNG_HandleTypeDef* hrng) +{ + + if(hrng->Instance==RNG) + { + /* USER CODE BEGIN RNG_MspDeInit 0 */ + + /* USER CODE END RNG_MspDeInit 0 */ + /* Peripheral clock disable */ + __RNG_CLK_DISABLE(); + } + /* USER CODE BEGIN RNG_MspDeInit 1 */ + + /* USER CODE END RNG_MspDeInit 1 */ + +} + + + +void HAL_SRAM_MspInit(SRAM_HandleTypeDef* hsram) +{ +} + + +void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef* hsram) +{ +} + +void HAL_UART_MspInit(UART_HandleTypeDef* huart) +{ + GPIO_InitTypeDef GPIO_InitStruct; + + if (huart->Instance == USART2) { + /* Peripheral clock enable */ + __USART2_CLK_ENABLE(); + __GPIOA_CLK_ENABLE(); + + /**USART2 GPIO Configuration + PA2 ------> USART2_TX + PA3 ------> USART2_RX + */ + GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_LOW; + GPIO_InitStruct.Alternate = GPIO_AF7_USART2; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + } + +} + +void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) +{ + if (huart->Instance == USART2) { + /* Peripheral clock disable */ + __USART2_CLK_DISABLE(); + + /**USART2 GPIO Configuration + PA2 ------> USART2_TX + PA3 ------> USART2_RX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2 | GPIO_PIN_3); + } +} + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/stm32f4xx_it.c b/stm32f4xx_it.c new file mode 100644 index 0000000..b2b64bf --- /dev/null +++ b/stm32f4xx_it.c @@ -0,0 +1,73 @@ +/** +****************************************************************************** +* @file stm32f4xx_it.c +* @brief Interrupt Service Routines. +****************************************************************************** +* +* COPYRIGHT(c) 2015 STMicroelectronics +* +* 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. +* 3. Neither the name of STMicroelectronics nor the names of its contributors +* may be used to endorse or promote products derived from this software +* without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. +* +****************************************************************************** +*/ +/* Includes ------------------------------------------------------------------*/ +#include "stm32f4xx_hal.h" +#include "stm32f4xx.h" +#include "stm32f4xx_it.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/* External variables --------------------------------------------------------*/ + +/******************************************************************************/ +/* Cortex-M4 Processor Interruption and Exception Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles System tick timer. + */ +void SysTick_Handler(void) +{ + /* USER CODE BEGIN SysTick_IRQn 0 */ + + /* USER CODE END SysTick_IRQn 0 */ + HAL_IncTick(); + HAL_SYSTICK_IRQHandler(); + /* USER CODE BEGIN SysTick_IRQn 1 */ + + /* USER CODE END SysTick_IRQn 1 */ +} + +/******************************************************************************/ +/* STM32F4xx Peripheral Interrupt Handlers */ +/* Add here the Interrupt Handlers for the used peripherals. */ +/* For the available peripheral interrupt handler names, */ +/* please refer to the startup file (startup_stm32f4xx.s). */ +/******************************************************************************/ + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/stm32f4xx_it.h b/stm32f4xx_it.h new file mode 100644 index 0000000..546d79c --- /dev/null +++ b/stm32f4xx_it.h @@ -0,0 +1,56 @@ +/** + ****************************************************************************** + * @file stm32f4xx_it.h + * @brief This file contains the headers of the interrupt handlers. + ****************************************************************************** + * + * COPYRIGHT(c) 2015 STMicroelectronics + * + * 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. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F4xx_IT_H +#define __STM32F4xx_IT_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Exported macro ------------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ + +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F4xx_IT_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/syscalls.c b/syscalls.c new file mode 100644 index 0000000..58f3ecc --- /dev/null +++ b/syscalls.c @@ -0,0 +1,196 @@ +/**************************************************************************** +* Copyright (c) 2009 by Michael Fischer. All rights reserved. +* +* 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. +* 3. Neither the name of the author nor the names of its contributors may +* be used to endorse or promote products derived from this software +* without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. +* +**************************************************************************** +* History: +* +* 28.03.09 mifi First Version, based on the original syscall.c from +* newlib version 1.17.0 +****************************************************************************/ + +/**************************************************************************** +* 2015-10-29 pselkirk for cryptech: +* Changed asm to __asm for c99 compatibility. +* Added _exit, _kill, and _getpid from mifi's 2013 revision. +****************************************************************************/ + +#include +#include +#include +#include +#include + +/***************************************************************************/ + +int _read_r (struct _reent *r, int file, char * ptr, int len) +{ + r = r; + file = file; + ptr = ptr; + len = len; + + errno = EINVAL; + return -1; +} + +/***************************************************************************/ + +int _lseek_r (struct _reent *r, int file, int ptr, int dir) +{ + r = r; + file = file; + ptr = ptr; + dir = dir; + + return 0; +} + +/***************************************************************************/ + +int _write_r (struct _reent *r, int file, char * ptr, int len) +{ + r = r; + file = file; + ptr = ptr; + +#if 0 + int index; + + /* For example, output string by UART */ + for(index=0; index stack_ptr) + { + /* Some of the libstdc++-v3 tests rely upon detecting + out of memory errors, so do not abort here. */ +#if 0 + extern void abort (void); + + _write (1, "_sbrk: Heap and stack collision\n", 32); + + abort (); +#else + errno = ENOMEM; + return (caddr_t) -1; +#endif + } + + heap_end += incr; + + return (caddr_t) prev_heap_end; +} + +/***************************************************************************/ + +int _fstat_r (struct _reent *r, int file, struct stat * st) +{ + r = r; + file = file; + + memset (st, 0, sizeof (* st)); + st->st_mode = S_IFCHR; + return 0; +} + +/***************************************************************************/ + +int _isatty_r(struct _reent *r, int fd) +{ + r = r; + fd = fd; + + return 1; +} + +/***************************************************************************/ + +void _exit (int a) +{ + a = a; + + while(1) {}; +} + +/***************************************************************************/ + +int _kill (int a, int b) +{ + a = a; + b = b; + + return 0; +} + +/***************************************************************************/ + +int _getpid(int a) +{ + a = a; + + return 0; +} + +/*** EOF ***/ + + -- cgit v1.2.3