├── .cproject ├── .cproject_org ├── .gitignore ├── .mxproject ├── .project ├── .project_org ├── .settings ├── com.st.stm32cube.ide.mcu.sfrview.prefs ├── language.settings.xml └── org.eclipse.core.resources.prefs ├── Drivers ├── CMSIS │ ├── Device │ │ └── ST │ │ │ └── STM32F4xx │ │ │ ├── Include │ │ │ ├── stm32f407xx.h │ │ │ ├── stm32f4xx.h │ │ │ └── system_stm32f4xx.h │ │ │ └── LICENSE.txt │ ├── Include │ │ ├── cachel1_armv7.h │ │ ├── cmsis_armcc.h │ │ ├── cmsis_armclang.h │ │ ├── cmsis_armclang_ltm.h │ │ ├── cmsis_compiler.h │ │ ├── cmsis_gcc.h │ │ ├── cmsis_iccarm.h │ │ ├── cmsis_version.h │ │ ├── core_armv81mml.h │ │ ├── core_armv8mbl.h │ │ ├── core_armv8mml.h │ │ ├── core_cm0.h │ │ ├── core_cm0plus.h │ │ ├── core_cm1.h │ │ ├── core_cm23.h │ │ ├── core_cm3.h │ │ ├── core_cm33.h │ │ ├── core_cm35p.h │ │ ├── core_cm4.h │ │ ├── core_cm55.h │ │ ├── core_cm7.h │ │ ├── core_cm85.h │ │ ├── core_sc000.h │ │ ├── core_sc300.h │ │ ├── core_starmc1.h │ │ ├── mpu_armv7.h │ │ ├── mpu_armv8.h │ │ ├── pac_armv81.h │ │ ├── pmu_armv8.h │ │ └── tz_context.h │ └── LICENSE.txt └── STM32F4xx_HAL_Driver │ ├── Inc │ ├── Legacy │ │ └── stm32_hal_legacy.h │ ├── stm32f4xx_hal.h │ ├── stm32f4xx_hal_cortex.h │ ├── stm32f4xx_hal_def.h │ ├── stm32f4xx_hal_dma.h │ ├── stm32f4xx_hal_dma_ex.h │ ├── stm32f4xx_hal_exti.h │ ├── stm32f4xx_hal_flash.h │ ├── stm32f4xx_hal_flash_ex.h │ ├── stm32f4xx_hal_flash_ramfunc.h │ ├── stm32f4xx_hal_gpio.h │ ├── stm32f4xx_hal_gpio_ex.h │ ├── stm32f4xx_hal_pcd.h │ ├── stm32f4xx_hal_pcd_ex.h │ ├── stm32f4xx_hal_pwr.h │ ├── stm32f4xx_hal_pwr_ex.h │ ├── stm32f4xx_hal_rcc.h │ ├── stm32f4xx_hal_rcc_ex.h │ ├── stm32f4xx_hal_rtc.h │ ├── stm32f4xx_hal_rtc_ex.h │ ├── stm32f4xx_hal_sd.h │ ├── stm32f4xx_hal_tim.h │ ├── stm32f4xx_hal_tim_ex.h │ ├── stm32f4xx_ll_bus.h │ ├── stm32f4xx_ll_cortex.h │ ├── stm32f4xx_ll_dma.h │ ├── stm32f4xx_ll_exti.h │ ├── stm32f4xx_ll_gpio.h │ ├── stm32f4xx_ll_pwr.h │ ├── stm32f4xx_ll_rcc.h │ ├── stm32f4xx_ll_rtc.h │ ├── stm32f4xx_ll_sdmmc.h │ ├── stm32f4xx_ll_system.h │ ├── stm32f4xx_ll_usb.h │ └── stm32f4xx_ll_utils.h │ ├── LICENSE.txt │ └── Src │ ├── stm32f4xx_hal.c │ ├── stm32f4xx_hal_cortex.c │ ├── stm32f4xx_hal_dma.c │ ├── stm32f4xx_hal_dma_ex.c │ ├── stm32f4xx_hal_exti.c │ ├── stm32f4xx_hal_flash.c │ ├── stm32f4xx_hal_flash_ex.c │ ├── stm32f4xx_hal_flash_ramfunc.c │ ├── stm32f4xx_hal_gpio.c │ ├── stm32f4xx_hal_pcd.c │ ├── stm32f4xx_hal_pcd_ex.c │ ├── stm32f4xx_hal_pwr.c │ ├── stm32f4xx_hal_pwr_ex.c │ ├── stm32f4xx_hal_rcc.c │ ├── stm32f4xx_hal_rcc_ex.c │ ├── stm32f4xx_hal_rtc.c │ ├── stm32f4xx_hal_rtc_ex.c │ ├── stm32f4xx_hal_sd.c │ ├── stm32f4xx_hal_tim.c │ ├── stm32f4xx_hal_tim_ex.c │ ├── stm32f4xx_ll_sdmmc.c │ └── stm32f4xx_ll_usb.c ├── Inc ├── main.h ├── stm32f4xx_hal_conf.h └── stm32f4xx_it.h ├── LICENSE ├── Main ├── Display │ ├── Screen.cpp │ ├── Screen.h │ ├── VideoSettings.h │ ├── draw4.h │ ├── draw4.s │ ├── font8x8.cpp │ └── font8x8.h ├── Emulator │ ├── SpectrumScreen.cpp │ ├── SpectrumScreen.h │ ├── main_ROM.c │ ├── main_ROM.h │ ├── z80Input.cpp │ ├── z80Input.h │ ├── z80emu │ │ ├── README.txt │ │ ├── instructions.h │ │ ├── macros.h │ │ ├── tables.h │ │ ├── z80config.h │ │ ├── z80emu.c │ │ └── z80emu.h │ ├── z80main.cpp │ ├── z80main.h │ ├── z80snapshot.cpp │ ├── z80snapshot.h │ └── z80user.h ├── Keyboard │ ├── Queue.c │ ├── ps2Keyboard.cpp │ ├── ps2Keyboard.h │ └── queue.h ├── SDCard.cpp ├── SDCard.h ├── Sound │ ├── ay3-8912-state.cpp │ ├── ay3-8912-state.h │ ├── midiMessage.c │ ├── midiMessage.h │ ├── pitchtonote.c │ ├── pitchtonote.h │ ├── usb_device.c │ ├── usb_device.h │ ├── usbd_conf.c │ ├── usbd_conf.h │ ├── usbd_core.c │ ├── usbd_core.h │ ├── usbd_ctlreq.c │ ├── usbd_ctlreq.h │ ├── usbd_def.h │ ├── usbd_desc.c │ ├── usbd_desc.h │ ├── usbd_ioreq.c │ ├── usbd_ioreq.h │ ├── usbd_midi.c │ ├── usbd_midi.h │ ├── usbd_midi_if.c │ ├── usbd_midi_if.h │ ├── volume.c │ └── volume.h ├── emulator.cpp ├── emulator.h ├── etl │ ├── LICENSE │ ├── README.mkdn │ ├── algorithm.h │ ├── armv7m │ │ ├── actlr.h │ │ ├── exception_frame.h │ │ ├── exception_table.cc │ │ ├── exception_table.h │ │ ├── exceptions.def │ │ ├── exceptions.h │ │ ├── instructions.h │ │ ├── mpu.h │ │ ├── mpu.reg │ │ ├── nvic.cc │ │ ├── nvic.h │ │ ├── nvic.reg │ │ ├── peripherals.ld │ │ ├── registers.h │ │ ├── scb.cc │ │ ├── scb.h │ │ ├── scb.reg │ │ ├── scb_fp.h │ │ ├── scb_fp.reg │ │ ├── sys_tick.h │ │ ├── sys_tick.reg │ │ └── types.h │ ├── array_count.h │ ├── assert.h │ ├── assert_loop.cc │ ├── attribute_macros.h │ ├── biffield │ │ ├── README.mkdn │ │ ├── checks.h │ │ ├── generate.h │ │ ├── generate_accessors.h │ │ ├── generate_constants.h │ │ ├── generate_fields.h │ │ └── generate_value_types.h │ ├── bits.h │ ├── concatenate.h │ ├── data │ │ ├── maybe.h │ │ ├── range_ptr.h │ │ └── sort.h │ ├── destroy.h │ ├── doc │ │ └── conventions.mkdn │ ├── error │ │ ├── catch.h │ │ ├── check.h │ │ ├── flow.h │ │ ├── ignore.h │ │ ├── result.h │ │ └── strategy.h │ ├── functor.h │ ├── implicit.h │ ├── integer_sequence.h │ ├── invoke.h │ ├── mem │ │ └── arena.h │ ├── non_null.h │ ├── prediction.h │ ├── quote.h │ ├── scope_guard.h │ ├── stm32f4xx │ │ ├── adv_timer.h │ │ ├── adv_timer.reg │ │ ├── ahb.h │ │ ├── ahb1_peripherals.def │ │ ├── apb.h │ │ ├── apb1_peripherals.def │ │ ├── apb2_peripherals.def │ │ ├── basic_timer.h │ │ ├── basic_timer.reg │ │ ├── dac.h │ │ ├── dac.reg │ │ ├── dbg.h │ │ ├── dbg.reg │ │ ├── dma.h │ │ ├── dma.reg │ │ ├── dma_stream.reg │ │ ├── flash.h │ │ ├── flash.reg │ │ ├── gp_timer.h │ │ ├── gp_timer.reg │ │ ├── gpio.cc │ │ ├── gpio.h │ │ ├── gpio.reg │ │ ├── iic.h │ │ ├── iic.reg │ │ ├── interrupt_table.cc │ │ ├── interrupt_table.h │ │ ├── interrupts.cc │ │ ├── interrupts.def │ │ ├── interrupts.h │ │ ├── peripherals.ld │ │ ├── pwr.h │ │ ├── pwr.reg │ │ ├── rcc.cc │ │ ├── rcc.h │ │ ├── rcc.reg │ │ ├── spi.h │ │ ├── spi.reg │ │ ├── syscfg.h │ │ ├── syscfg.reg │ │ ├── types.h │ │ ├── usart.h │ │ └── usart.reg │ ├── type_constant.h │ ├── type_list.h │ ├── type_traits.h │ └── utility.h ├── m4vgalib │ ├── LICENSE │ ├── README.mkdn │ ├── copy_words.S │ ├── copy_words.h │ ├── rasterizer.h │ ├── timing.cc │ ├── timing.h │ ├── vga.cc │ ├── vga.h │ └── vgaConfig.h ├── resources │ └── keyboard.h ├── sdCard │ ├── bsp_driver_sd.c │ ├── bsp_driver_sd.h │ ├── diskio.c │ ├── fatFS │ │ ├── diskio.h │ │ ├── ff.c │ │ ├── ff.h │ │ ├── ffunicode.c │ │ └── integer.h │ ├── fatfs.c │ ├── fatfs.h │ ├── ff_gen_drv.c │ ├── ff_gen_drv.h │ ├── ffconf.h │ ├── flash_diskio.c │ ├── flash_diskio.h │ ├── sd_diskio.c │ └── sd_diskio.h ├── startup.cpp └── startup.h ├── README.md ├── Src ├── main.c ├── stm32f4xx_hal_msp.c ├── stm32f4xx_it.c ├── syscalls.c └── system_stm32f4xx.c ├── doc ├── Board2_1.jpg ├── Board2_2.jpg ├── DIY-More-STM32F407VGT6-pinout.xlsx ├── STM32F407VET6-pinout.xlsx └── stm32f407-z80emu.jpg ├── m4vga-stm32f4xx.ld ├── readme-BOARD2.md ├── startup └── startup_stm32f407xx.s ├── stm32f407-z80emu Debug.cfg ├── stm32f407-z80emu Debug.launch ├── stm32f407-z80emu Release.cfg ├── stm32f407-z80emu Release.launch ├── stm32f407-z80emu.ioc ├── stm32f407-z80emu.xml └── stm32f407-z80emu_converter.log /.gitignore: -------------------------------------------------------------------------------- 1 | /Release/ 2 | /Debug/ 3 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | stm32f407-z80emu 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 24 | org.eclipse.cdt.core.ccnature 25 | com.st.stm32cube.ide.mcu.MCUSW4STM32ConvertedProjectNature 26 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 27 | 28 | 29 | -------------------------------------------------------------------------------- /.project_org: -------------------------------------------------------------------------------- 1 | 2 | 3 | stm32f407-z80emu 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 25 | fr.ac6.mcu.ide.core.MCUProjectNature 26 | org.eclipse.cdt.core.ccnature 27 | 28 | 29 | -------------------------------------------------------------------------------- /.settings/com.st.stm32cube.ide.mcu.sfrview.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | sfrviewstate={"fFavorites"\:{"fLists"\:{}},"fProperties"\:{"fNodeProperties"\:{}}} 3 | -------------------------------------------------------------------------------- /.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//Main/Display/font8x8.cpp=UTF-8 3 | encoding//Main/SDCard.cpp=UTF-8 4 | encoding//Main/emulator.cpp=UTF-8 5 | encoding//Main/startup.cpp=UTF-8 6 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /** @addtogroup CMSIS 20 | * @{ 21 | */ 22 | 23 | /** @addtogroup stm32f4xx_system 24 | * @{ 25 | */ 26 | 27 | /** 28 | * @brief Define to prevent recursive inclusion 29 | */ 30 | #ifndef __SYSTEM_STM32F4XX_H 31 | #define __SYSTEM_STM32F4XX_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /** @addtogroup STM32F4xx_System_Includes 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @} 43 | */ 44 | 45 | 46 | /** @addtogroup STM32F4xx_System_Exported_types 47 | * @{ 48 | */ 49 | /* This variable is updated in three ways: 50 | 1) by calling CMSIS function SystemCoreClockUpdate() 51 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 52 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 53 | Note: If you use this function to configure the system clock; then there 54 | is no need to call the 2 first functions listed above, since SystemCoreClock 55 | variable is updated automatically. 56 | */ 57 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 58 | 59 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 60 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup STM32F4xx_System_Exported_Constants 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @addtogroup STM32F4xx_System_Exported_Macros 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @addtogroup STM32F4xx_System_Exported_Functions 83 | * @{ 84 | */ 85 | 86 | extern void SystemInit(void); 87 | extern void SystemCoreClockUpdate(void); 88 | /** 89 | * @} 90 | */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /*__SYSTEM_STM32F4XX_H */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Device/ST/STM32F4xx/LICENSE.txt: -------------------------------------------------------------------------------- 1 | This software component is provided to you as part of a software package and 2 | applicable license terms are in the Package_license file. If you received this 3 | software component outside of a package or without applicable license terms, 4 | the terms of the Apache-2.0 license shall apply. 5 | You may obtain a copy of the Apache-2.0 at: 6 | https://opensource.org/licenses/Apache-2.0 7 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.5 5 | * @date 02. February 2022 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2022 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 6U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dma_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of DMA HAL extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file in 13 | * the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __STM32F4xx_HAL_DMA_EX_H 21 | #define __STM32F4xx_HAL_DMA_EX_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "stm32f4xx_hal_def.h" 29 | 30 | /** @addtogroup STM32F4xx_HAL_Driver 31 | * @{ 32 | */ 33 | 34 | /** @addtogroup DMAEx 35 | * @{ 36 | */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /** @defgroup DMAEx_Exported_Types DMAEx Exported Types 40 | * @brief DMAEx Exported types 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief HAL DMA Memory definition 46 | */ 47 | typedef enum 48 | { 49 | MEMORY0 = 0x00U, /*!< Memory 0 */ 50 | MEMORY1 = 0x01U /*!< Memory 1 */ 51 | }HAL_DMA_MemoryTypeDef; 52 | 53 | /** 54 | * @} 55 | */ 56 | 57 | /* Exported functions --------------------------------------------------------*/ 58 | /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions 59 | * @brief DMAEx Exported functions 60 | * @{ 61 | */ 62 | 63 | /** @defgroup DMAEx_Exported_Functions_Group1 Extended features functions 64 | * @brief Extended features functions 65 | * @{ 66 | */ 67 | 68 | /* IO operation functions *******************************************************/ 69 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 70 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 71 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory); 72 | 73 | /** 74 | * @} 75 | */ 76 | /** 77 | * @} 78 | */ 79 | 80 | /* Private functions ---------------------------------------------------------*/ 81 | /** @defgroup DMAEx_Private_Functions DMAEx Private Functions 82 | * @brief DMAEx Private functions 83 | * @{ 84 | */ 85 | /** 86 | * @} 87 | */ 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /*__STM32F4xx_HAL_DMA_EX_H*/ 102 | 103 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH RAMFUNC driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file in 13 | * the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | ****************************************************************************** 16 | */ 17 | 18 | /* Define to prevent recursive inclusion -------------------------------------*/ 19 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 20 | #define __STM32F4xx_FLASH_RAMFUNC_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\ 26 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F4xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup FLASH_RAMFUNC 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported macro ------------------------------------------------------------*/ 41 | /* Exported functions --------------------------------------------------------*/ 42 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions 43 | * @{ 44 | */ 45 | 46 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1 47 | * @{ 48 | */ 49 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void); 50 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void); 51 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void); 52 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void); 53 | /** 54 | * @} 55 | */ 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | /** 66 | * @} 67 | */ 68 | 69 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | 75 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 76 | 77 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_pcd_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of PCD HAL Extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef STM32F4xx_HAL_PCD_EX_H 21 | #define STM32F4xx_HAL_PCD_EX_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "stm32f4xx_hal_def.h" 29 | 30 | #if defined (USB_OTG_FS) || defined (USB_OTG_HS) 31 | /** @addtogroup STM32F4xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup PCDEx 36 | * @{ 37 | */ 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* Exported macros -----------------------------------------------------------*/ 41 | /* Exported functions --------------------------------------------------------*/ 42 | /** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions 43 | * @{ 44 | */ 45 | /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 46 | * @{ 47 | */ 48 | #if defined (USB_OTG_FS) || defined (USB_OTG_HS) 49 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size); 50 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size); 51 | #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */ 52 | 53 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) \ 54 | || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) \ 55 | || defined(STM32F423xx) 56 | HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd); 57 | HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd); 58 | #endif /* defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || 59 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || 60 | defined(STM32F423xx) */ 61 | #if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) \ 62 | || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) 63 | HAL_StatusTypeDef HAL_PCDEx_ActivateBCD(PCD_HandleTypeDef *hpcd); 64 | HAL_StatusTypeDef HAL_PCDEx_DeActivateBCD(PCD_HandleTypeDef *hpcd); 65 | void HAL_PCDEx_BCD_VBUSDetect(PCD_HandleTypeDef *hpcd); 66 | #endif /* defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || 67 | defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) */ 68 | void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); 69 | void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** 84 | * @} 85 | */ 86 | #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */ 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif /* __cplusplus */ 91 | 92 | 93 | #endif /* STM32F4xx_HAL_PCD_EX_H */ 94 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/LICENSE.txt: -------------------------------------------------------------------------------- 1 | This software component is provided to you as part of a software package and 2 | applicable license terms are in the Package_license file. If you received this 3 | software component outside of a package or without applicable license terms, 4 | the terms of the BSD-3-Clause license shall apply. 5 | You may obtain a copy of the BSD-3-Clause at: 6 | https://opensource.org/licenses/BSD-3-Clause 7 | -------------------------------------------------------------------------------- /Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2019 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __MAIN_H 24 | #define __MAIN_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal.h" 32 | 33 | /* Private includes ----------------------------------------------------------*/ 34 | /* USER CODE BEGIN Includes */ 35 | 36 | /* USER CODE END Includes */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* USER CODE BEGIN ET */ 40 | 41 | /* USER CODE END ET */ 42 | 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* USER CODE BEGIN EC */ 45 | 46 | /* USER CODE END EC */ 47 | 48 | /* Exported macro ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN EM */ 50 | 51 | /* USER CODE END EM */ 52 | 53 | /* Exported functions prototypes ---------------------------------------------*/ 54 | void Error_Handler(void); 55 | 56 | /* USER CODE BEGIN EFP */ 57 | 58 | /* USER CODE END EFP */ 59 | 60 | /* Private defines -----------------------------------------------------------*/ 61 | 62 | /* USER CODE BEGIN Private defines */ 63 | 64 | /* USER CODE END Private defines */ 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif /* __MAIN_H */ 71 | -------------------------------------------------------------------------------- /Inc/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2019 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F4xx_IT_H 23 | #define __STM32F4xx_IT_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Private includes ----------------------------------------------------------*/ 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN ET */ 36 | 37 | /* USER CODE END ET */ 38 | 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* USER CODE BEGIN EC */ 41 | 42 | /* USER CODE END EC */ 43 | 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* USER CODE BEGIN EM */ 46 | 47 | /* USER CODE END EM */ 48 | 49 | /* Exported functions prototypes ---------------------------------------------*/ 50 | void NMI_Handler(void); 51 | void HardFault_Handler(void); 52 | void MemManage_Handler(void); 53 | void BusFault_Handler(void); 54 | void UsageFault_Handler(void); 55 | void SVC_Handler(void); 56 | void DebugMon_Handler(void); 57 | void SysTick_Handler(void); 58 | void SDIO_IRQHandler(void); 59 | /* USER CODE BEGIN EFP */ 60 | 61 | /* USER CODE END EFP */ 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /* __STM32F4xx_IT_H */ 68 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Please note that this project contains the following libraries with separate 2 | licences: 3 | 1) STMicroelectronics HAL and LL APIs are licensed under the open-source BSD License 4 | 2) cbiffle/etl is licensed under the BSD 2-Clause "Simplified" License (https://github.com/cbiffle/etl/blob/master/LICENSE) 5 | 3) cbiffle/m4vgalib is licensed under the BSD 2-Clause "Simplified" License (https://github.com/cbiffle/m4vgalib/blob/master/LICENSE) 6 | 4) FATFS - see http://elm-chan.org/fsw/ff/00index_e.html 7 | 8 | The rest is licensed under: 9 | ============================================================================== 10 | MIT License 11 | 12 | Copyright (c) 2018 Andrey Belykh 13 | 14 | Permission is hereby granted, free of charge, to any person obtaining a copy 15 | of this software and associated documentation files (the "Software"), to deal 16 | in the Software without restriction, including without limitation the rights 17 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | The above copyright notice and this permission notice shall be included in all 22 | copies or substantial portions of the Software. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 | SOFTWARE. 31 | -------------------------------------------------------------------------------- /Main/Display/Screen.h: -------------------------------------------------------------------------------- 1 | #ifndef _SCREEN_H 2 | #define _SCREEN_H 3 | 4 | #include 5 | #include 6 | #include "m4vgalib/rasterizer.h" 7 | 8 | using namespace vga; 9 | 10 | namespace Display 11 | { 12 | 13 | class Screen: public Rasterizer 14 | { 15 | private: 16 | void PrintChar(char c, uint16_t color); 17 | void PrintCharAt(uint8_t x, uint8_t y, unsigned char c, uint16_t color); 18 | void DrawChar(const uint8_t *f, uint16_t x, uint16_t y, uint8_t c); 19 | void Bitmap(uint16_t x, uint16_t y, const unsigned char *bmp, 20 | uint16_t i, uint8_t width, uint8_t lines); 21 | void CursorNext(); 22 | void InvertColor(); 23 | 24 | uint16_t _startLine; 25 | uint16_t _horizontalBorder; 26 | uint8_t _verticalBorder; 27 | bool _isCursorVisible; 28 | 29 | protected: 30 | virtual uint8_t* GetPixelPointer(uint16_t line); 31 | virtual uint8_t* GetPixelPointer(uint16_t line, uint8_t character); 32 | 33 | uint16_t _hResolution; 34 | uint16_t _hResolutionNoBorder; 35 | uint16_t _vResolution; 36 | 37 | uint8_t* _font = (uint8_t*)font8x8; 38 | uint16_t _attribute = 0x3F10; // white on blue 39 | 40 | public: 41 | uint8_t _cursor_x = 0; 42 | uint8_t _cursor_y = 0; 43 | uint16_t _pixelCount; 44 | uint16_t _attributeCount; 45 | volatile uint32_t _frames = 0; 46 | 47 | VideoSettings Settings; 48 | Screen(VideoSettings settings); 49 | Screen(VideoSettings settings, uint16_t startLine, uint16_t height); 50 | 51 | void Clear(); 52 | void SetFont(const uint8_t* font); 53 | void SetAttribute(uint16_t attribute); 54 | void SetCursorPosition(uint8_t x, uint8_t y); 55 | void ShowCursor(); 56 | void HideCursor(); 57 | 58 | void Print(const char* str); 59 | void PrintAt(uint8_t x, uint8_t y, const char* str); 60 | void PrintAlignRight(uint8_t y, const char *str); 61 | void PrintAlignCenter(uint8_t y, const char *str); 62 | 63 | RasterInfo rasterize(unsigned cycles_per_pixel, unsigned line_number, 64 | Pixel *target) override; 65 | 66 | virtual ~Screen() = default; 67 | }; 68 | 69 | } 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /Main/Display/VideoSettings.h: -------------------------------------------------------------------------------- 1 | #ifndef _VIDEOSETTINGS_H 2 | #define _VIDEOSETTINGS_H 3 | 4 | #include 5 | #include "m4vgalib/timing.h" 6 | 7 | namespace Display 8 | { 9 | 10 | class VideoSettings 11 | { 12 | public: 13 | const vga::Timing* Timing; 14 | 15 | uint8_t Scale; 16 | 17 | // text resolution 18 | uint8_t TextColumns; 19 | uint8_t TextRows; 20 | 21 | // video memory 22 | uint8_t* Pixels; 23 | uint16_t* Attributes; // colors 24 | uint8_t* BorderColor; 25 | }; 26 | 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Main/Display/draw4.h: -------------------------------------------------------------------------------- 1 | #ifndef DRAW4_H 2 | #define DRAW4_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | void Draw4(uint8_t* bitmap, uint16_t* colors, uint8_t* dest); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif // DRAW4_H 17 | -------------------------------------------------------------------------------- /Main/Display/draw4.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | 3 | @ Arguments: 4 | @ r0 pixels 5 | @ r1 colors 6 | @ r2 destination 7 | .section .text.Draw4,"ax",%progbits 8 | //.section .ramcode,"ax",%progbits 9 | .balign 4 10 | .global Draw4 11 | .thumb_func 12 | Draw4: 13 | @ parameters 14 | pix .req r0 15 | col .req r1 16 | dst .req r2 17 | 18 | push {r4} 19 | 20 | ldr r0, [pix] // pixels for characters 0..3 21 | ldr r3, [col], #4 // colors for characters 0..1 22 | 23 | // character #0 24 | ror r0, r0, #4 // pixels >> 4 25 | and r4, r0, #8 26 | lsr r4, r3, r4 27 | strb r4, [dst], #1 28 | .rept 7 29 | ror r0, r0, #31 30 | and r4, r0, #8 31 | lsr r4, r3, r4 32 | strb r4, [dst], #1 33 | .endr 34 | 35 | // character #1 36 | ror r3, r3, #16 // colors 37 | ror r0, r0, #15 38 | and r4, r0, #8 39 | lsr r4, r3, r4 40 | strb r4, [dst], #1 41 | .rept 7 42 | ror r0, r0, #31 43 | and r4, r0, #8 44 | lsr r4, r3, r4 45 | strb r4, [dst], #1 46 | .endr 47 | 48 | ldr r3, [col], #4 // colors for for characters 2..3 49 | 50 | // character #2 51 | ror r0, r0, #15 52 | and r4, r0, #8 53 | lsr r4, r3, r4 54 | strb r4, [dst], #1 55 | .rept 7 56 | ror r0, r0, #31 57 | and r4, r0, #8 58 | lsr r4, r3, r4 59 | strb r4, [dst], #1 60 | .endr 61 | 62 | // character #3 63 | ror r3, r3, #16 // colors 64 | ror r0, r0, #15 65 | and r4, r0, #8 66 | lsr r4, r3, r4 67 | strb r4, [dst], #1 68 | .rept 7 69 | ror r0, r0, #31 70 | and r4, r0, #8 71 | lsr r4, r3, r4 72 | strb r4, [dst], #1 73 | .endr 74 | 75 | pop {r4} 76 | bx lr 77 | -------------------------------------------------------------------------------- /Main/Display/font8x8.h: -------------------------------------------------------------------------------- 1 | #ifndef FONT8X8_H 2 | #define FONT8X8_H 3 | 4 | extern const unsigned char font8x8[]; 5 | 6 | #endif -------------------------------------------------------------------------------- /Main/Emulator/SpectrumScreen.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPECTRUMSCREEN_H 2 | #define _SPECTRUMSCREEN_H 3 | 4 | #include 5 | #include "Display/Screen.h" 6 | 7 | namespace Display 8 | { 9 | 10 | class SpectrumScreen: public Screen 11 | { 12 | protected: 13 | uint8_t* GetPixelPointer(uint16_t line) override; 14 | uint8_t* GetPixelPointer(uint16_t line, uint8_t character) override; 15 | 16 | public: 17 | SpectrumScreen(VideoSettings settings); 18 | SpectrumScreen(VideoSettings settings, uint16_t startLine, uint16_t height); 19 | 20 | void ShowScreenshot(const uint8_t* screenshot); 21 | uint16_t FromSpectrumColor(uint8_t sinclairColor); 22 | uint8_t ToSpectrumColor(uint16_t color); 23 | }; 24 | 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /Main/Emulator/main_ROM.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_ROM_H 2 | #define MAIN_ROM_H 3 | 4 | #include 5 | 6 | extern const uint8_t ROM[]; 7 | 8 | #endif -------------------------------------------------------------------------------- /Main/Emulator/z80Input.h: -------------------------------------------------------------------------------- 1 | #ifndef _Z80INPUT_H_ 2 | #define _Z80INPUT_H_ 3 | 4 | #include 5 | 6 | extern uint8_t indata[]; 7 | 8 | enum { 9 | ZX_KEY_SHIFT = 0, 10 | ZX_KEY_Z, 11 | ZX_KEY_X, 12 | ZX_KEY_C, 13 | ZX_KEY_V, 14 | 15 | ZX_KEY_A, 16 | ZX_KEY_S, 17 | ZX_KEY_D, 18 | ZX_KEY_F, 19 | ZX_KEY_G, 20 | 21 | ZX_KEY_Q, 22 | ZX_KEY_W, 23 | ZX_KEY_E, 24 | ZX_KEY_R, 25 | ZX_KEY_T, 26 | 27 | ZX_KEY_1, 28 | ZX_KEY_2, 29 | ZX_KEY_3, 30 | ZX_KEY_4, 31 | ZX_KEY_5, 32 | 33 | ZX_KEY_0, 34 | ZX_KEY_9, 35 | ZX_KEY_8, 36 | ZX_KEY_7, 37 | ZX_KEY_6, 38 | 39 | ZX_KEY_P, 40 | ZX_KEY_O, 41 | ZX_KEY_I, 42 | ZX_KEY_U, 43 | ZX_KEY_Y, 44 | 45 | ZX_KEY_ENTER, 46 | ZX_KEY_L, 47 | ZX_KEY_K, 48 | ZX_KEY_J, 49 | ZX_KEY_H, 50 | 51 | ZX_KEY_SPACE, 52 | ZX_KEY_SYM, 53 | ZX_KEY_M, 54 | ZX_KEY_N, 55 | ZX_KEY_B, 56 | 57 | ZX_KEY_LAST 58 | }; 59 | 60 | extern const uint8_t keyaddr[ZX_KEY_LAST]; 61 | extern const uint8_t keybuf[ZX_KEY_LAST]; 62 | 63 | bool OnKey(uint32_t scanCode, bool isKeyUp); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /Main/Emulator/z80emu/z80config.h: -------------------------------------------------------------------------------- 1 | /* z80config.h 2 | * Define or comment out macros in this file to configure the emulator. 3 | * 4 | * Copyright (c) 2016, 2017 Lin Ke-Fong 5 | * 6 | * This code is free, do whatever you want with it. 7 | */ 8 | 9 | #ifndef __Z80CONFIG_INCLUDED__ 10 | #define __Z80CONFIG_INCLUDED__ 11 | 12 | /* Define this macro if the host processor is big endian. */ 13 | 14 | /* #define Z80_BIG_ENDIAN */ 15 | 16 | /* Emulation can be speed up a little bit by emulating only the documented 17 | * flags. 18 | */ 19 | 20 | /* #define Z80_DOCUMENTED_FLAGS_ONLY */ 21 | 22 | /* HALT, DI, EI, RETI, and RETN instructions can be catched. When such an 23 | * instruction is catched, the emulator is stopped and the PC register points 24 | * at the opcode to be executed next. The catched instruction can be determined 25 | * from the Z80_STATE's status value. Keep in mind that no interrupt can be 26 | * accepted at the instruction right after a DI or EI on an actual processor. 27 | */ 28 | 29 | /* 30 | #define Z80_CATCH_HALT 31 | #define Z80_CATCH_DI 32 | #define Z80_CATCH_EI 33 | #define Z80_CATCH_RETI 34 | #define Z80_CATCH_RETN 35 | */ 36 | 37 | /* Undefined 0xed prefixed opcodes may be catched, otherwise they are treated 38 | * like NOP instructions. When one is catched, Z80_STATUS_ED_UNDEFINED is set 39 | * in Z80_STATE's status member and the PC register points at the 0xed prefix 40 | * before the undefined opcode. 41 | */ 42 | 43 | /* #define Z80_CATCH_ED_UNDEFINED */ 44 | 45 | /* The emulator cannot be stopped between prefixed opcodes. This can be a 46 | * problem if there is a long sequence of 0xdd and/or 0xfd prefixes. But if 47 | * Z80_PREFIX_FAILSAFE is defined, it will always be able to stop after at 48 | * least numbers_cycles are executed, in which case Z80_STATE's status is set 49 | * to Z80_STATUS_PREFIX. Note that if the memory where the opcodes are read, 50 | * has wait states (slow memory), then the additional cycles for a one byte 51 | * fetch (the non executed prefix) must be substracted. Even if it is safer, 52 | * most program won't need this feature. 53 | */ 54 | 55 | /* #define Z80_PREFIX_FAILSAFE */ 56 | 57 | /* By defining this macro, the emulator will always fetch the displacement or 58 | * address of a conditionnal jump or call instruction, even if the condition 59 | * is false and the fetch can be avoided. Define this macro if you need to 60 | * account for memory wait states on code read. 61 | */ 62 | 63 | /* #define Z80_FALSE_CONDITION_FETCH */ 64 | 65 | /* It may be possible to overwrite the opcode of the currently executing LDIR, 66 | * LDDR, INIR, or OTDR instruction. Define this macro if you need to handle 67 | * these pathological cases. 68 | */ 69 | 70 | /* #define Z80_HANDLE_SELF_MODIFYING_CODE */ 71 | 72 | /* For interrupt mode 2, bit 0 of the 16-bit address to the interrupt vector 73 | * can be masked to zero. Some documentation states that this bit is forced to 74 | * zero. For instance, Zilog's application note about interrupts, states that 75 | * "only 7 bits are required" and "the least significant bit is zero". Yet, 76 | * this is quite unclear, even from Zilog's manuals. So this is left as an 77 | * option. 78 | */ 79 | 80 | /* #define Z80_MASK_IM2_VECTOR_ADDRESS */ 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /Main/Emulator/z80main.h: -------------------------------------------------------------------------------- 1 | #ifndef __ZXMAIN_INCLUDED__ 2 | #define __ZXMAIN_INCLUDED__ 3 | 4 | #include "z80user.h" 5 | #include "main_ROM.h" 6 | #include "SpectrumScreen.h" 7 | #include "Sound/ay3-8912-state.h" 8 | 9 | using namespace Display; 10 | 11 | extern SpectrumScreen* _spectrumScreen; 12 | extern Sound::Ay3_8912_state _ay3_8912; 13 | extern Z80_STATE _zxCpu; 14 | extern uint8_t RamBuffer[]; 15 | 16 | void zx_setup(SpectrumScreen* spectrumScreen); 17 | int32_t zx_loop(); 18 | void zx_reset(); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /Main/Emulator/z80snapshot.h: -------------------------------------------------------------------------------- 1 | #ifndef __Z80SNAPSHOT_INCLUDED__ 2 | #define __Z80SNAPSHOT_INCLUDED__ 3 | 4 | #include 5 | #include "fatfs.h" 6 | 7 | namespace zx 8 | { 9 | 10 | bool LoadZ80Snapshot(FIL* file, uint8_t buffer1[0x4000], uint8_t buffer2[0x4000]); 11 | bool LoadScreenFromZ80Snapshot(FIL* file, uint8_t buffer1[0x4000]); 12 | bool LoadScreenshot(FIL* file, uint8_t buffer1[0x4000]); 13 | bool SaveZ80Snapshot(FIL* file, uint8_t buffer1[0x4000], uint8_t buffer2[0x4000]); 14 | 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Main/Keyboard/Queue.c: -------------------------------------------------------------------------------- 1 | #include "queue.h" 2 | 3 | #define QUEUE_SIZE (QUEUE_ELEMENTS + 1) 4 | 5 | static int Queue[QUEUE_SIZE]; 6 | static uint8_t QueueIn, QueueOut; 7 | 8 | void QueueInit() 9 | { 10 | QueueIn = QueueOut = 0; 11 | } 12 | 13 | int QueuePut(int32_t element) 14 | { 15 | if (QueueIn == ((QueueOut - 1 + QUEUE_SIZE) % QUEUE_SIZE)) 16 | { 17 | return -1; /* Queue Full*/ 18 | } 19 | 20 | Queue[QueueIn] = element; 21 | QueueIn = (QueueIn + 1) % QUEUE_SIZE; 22 | 23 | return 0; // No errors 24 | } 25 | 26 | int QueueGet(int32_t* element) 27 | { 28 | if (QueueIn == QueueOut) 29 | { 30 | return -1; /* Queue Empty - nothing to get*/ 31 | } 32 | 33 | *element = Queue[QueueOut]; 34 | QueueOut = (QueueOut + 1) % QUEUE_SIZE; 35 | 36 | return 0; // No errors 37 | } 38 | -------------------------------------------------------------------------------- /Main/Keyboard/queue.h: -------------------------------------------------------------------------------- 1 | #ifndef _QUEUE_H_ 2 | #define _QUEUE_H_ 3 | 4 | #include 5 | 6 | #define QUEUE_ELEMENTS 6 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | void QueueInit(); 13 | int QueuePut(int32_t element); 14 | int QueueGet(int32_t *element); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif -------------------------------------------------------------------------------- /Main/SDCard.h: -------------------------------------------------------------------------------- 1 | #ifndef __SDCARD_H__ 2 | #define __SDCARD_H__ 3 | 4 | #include "fatfs.h" 5 | 6 | bool loadSnapshotSetup(); 7 | bool loadSnapshotLoop(); 8 | 9 | bool saveSnapshotSetup(); 10 | bool saveSnapshotLoop(); 11 | 12 | #endif /* __SDCARD_H__ */ 13 | -------------------------------------------------------------------------------- /Main/Sound/ay3-8912-state.h: -------------------------------------------------------------------------------- 1 | #ifndef _AY3_8912_STATE_H 2 | #define _AY3_8912_STATE_H 3 | 4 | #include 5 | 6 | namespace Sound 7 | { 8 | 9 | class Ay3_8912_state 10 | { 11 | public: 12 | // Registers 13 | uint8_t finePitchChannelA = 0xFF; 14 | uint8_t coarsePitchChannelA = 0xFF; 15 | uint8_t finePitchChannelB = 0xFF; 16 | uint8_t coarsePitchChannelB = 0xFF; 17 | uint8_t finePitchChannelC = 0xFF; 18 | uint8_t coarsePitchChannelC = 0xFF; 19 | uint8_t noisePitch = 0xFF; 20 | uint8_t mixer = 0xFF; 21 | uint8_t volumeChannelA = 0xFF; 22 | uint8_t volumeChannelB = 0xFF; 23 | uint8_t volumeChannelC = 0xFF; 24 | uint8_t envelopeFineDuration = 0xFF; 25 | uint8_t envelopeCoarseDuration = 0xFF; 26 | uint8_t envelopeShape = 0xFF; 27 | uint8_t ioPortA = 0xFF; 28 | 29 | // Status 30 | uint8_t selectedRegister = 0xFF; 31 | uint8_t channelNote[3] = { 0xFF, 0xFF, 0xFF }; 32 | uint8_t channelVolume[3] = { 0xFF, 0xFF, 0xFF }; 33 | 34 | void selectRegister(uint8_t registerNumber); 35 | void setRegisterData(uint8_t data); 36 | uint8_t getRegisterData(); 37 | 38 | private: 39 | void updated(); 40 | }; 41 | 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Main/Sound/midiMessage.c: -------------------------------------------------------------------------------- 1 | #include "midimessage.h" 2 | #include "usbd_midi_if.h" 3 | 4 | static uint8_t _buffer[64]; 5 | static uint8_t _bufferIndex = 0; 6 | 7 | void midiMessage(uint8_t message, uint8_t channel, uint8_t data1, uint8_t data2) 8 | { 9 | if (_bufferIndex >= 63 - 4) 10 | { 11 | // Discard unsent messages 12 | _bufferIndex = 0; 13 | } 14 | 15 | _buffer[_bufferIndex] = message >> 4; 16 | _bufferIndex++; 17 | _buffer[_bufferIndex] = message | (channel & 0x0F); 18 | _bufferIndex++; 19 | _buffer[_bufferIndex] = data1 & 0x7F; 20 | _bufferIndex++; 21 | _buffer[_bufferIndex] = data2 & 0x7F; 22 | _bufferIndex++; 23 | 24 | if (MIDI_Transmit_FS(_buffer, _bufferIndex) == USBD_OK) 25 | { 26 | _bufferIndex = 0; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Main/Sound/midiMessage.h: -------------------------------------------------------------------------------- 1 | #ifndef _MIDIMESSAGE_H 2 | #define _MIDIMESSAGE_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define MIDI_NOTE_ON 0x90 11 | #define MIDI_NOTE_OFF 0x80 12 | #define MIDI_CONTROL_CHANGE 0xB0 13 | #define MIDI_PROGRAM_CHANGE 0xC0 14 | 15 | #define MIDI_CC_VOLUME 7 16 | #define MIDI_INSTRUMENT_LEAD1 80 17 | 18 | void midiMessage(uint8_t message, uint8_t channel, uint8_t data1, uint8_t data2); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Main/Sound/pitchtonote.h: -------------------------------------------------------------------------------- 1 | #ifndef _PITCHTONOTE_H 2 | #define _PITCHTONOTE_H 3 | 4 | extern const unsigned char pitchToNote[]; 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /Main/Sound/usb_device.c: -------------------------------------------------------------------------------- 1 | #include "usbd_midi.h" 2 | #include "usbd_midi_if.h" 3 | #include "usb_device.h" 4 | #include "usbd_core.h" 5 | #include "usbd_desc.h" 6 | 7 | USBD_HandleTypeDef hUsbDeviceFS; 8 | 9 | /** 10 | * Init USB device Library, add supported class and start the library 11 | * @retval None 12 | */ 13 | void MX_USB_DEVICE_Init(void) 14 | { 15 | if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK) 16 | { 17 | Error_Handler(); 18 | } 19 | 20 | if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_MIDI) != USBD_OK) 21 | { 22 | Error_Handler(); 23 | } 24 | 25 | if (USBD_MIDI_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) 26 | { 27 | Error_Handler(); 28 | } 29 | 30 | if (USBD_Start(&hUsbDeviceFS) != USBD_OK) 31 | { 32 | Error_Handler(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Main/Sound/usb_device.h: -------------------------------------------------------------------------------- 1 | #ifndef __USB_DEVICE__H__ 2 | #define __USB_DEVICE__H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* Includes ------------------------------------------------------------------*/ 9 | #include "stm32f4xx.h" 10 | #include "stm32f4xx_hal.h" 11 | #include "usbd_def.h" 12 | 13 | void MX_USB_DEVICE_Init(void); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif /* __USB_DEVICE__H__ */ 20 | -------------------------------------------------------------------------------- /Main/Sound/usbd_conf.h: -------------------------------------------------------------------------------- 1 | #ifndef __USBD_CONF__H__ 2 | #define __USBD_CONF__H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | #include 10 | #include 11 | #include 12 | #include "main.h" 13 | #include "stm32f4xx.h" 14 | #include "stm32f4xx_hal.h" 15 | 16 | #define USBD_MAX_NUM_INTERFACES 1U 17 | #define USBD_MAX_NUM_CONFIGURATION 1U 18 | #define USBD_MAX_STR_DESC_SIZ 512U 19 | #define USBD_SUPPORT_USER_STRING 0U 20 | #define USBD_DEBUG_LEVEL 0U 21 | #define USBD_LPM_ENABLED 0U 22 | #define USBD_SELF_POWERED 1U 23 | 24 | #define DEVICE_FS 0 25 | #define DEVICE_HS 1 26 | 27 | #define USBD_malloc malloc 28 | #define USBD_free free 29 | #define USBD_memset memset 30 | #define USBD_memcpy memcpy 31 | #define USBD_Delay HAL_Delay 32 | 33 | #if (USBD_DEBUG_LEVEL > 0) 34 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\ 35 | printf("\n"); 36 | #else 37 | #define USBD_UsrLog(...) 38 | #endif 39 | 40 | #if (USBD_DEBUG_LEVEL > 1) 41 | 42 | #define USBD_ErrLog(...) printf("ERROR: ") ;\ 43 | printf(__VA_ARGS__);\ 44 | printf("\n"); 45 | #else 46 | #define USBD_ErrLog(...) 47 | #endif 48 | 49 | #if (USBD_DEBUG_LEVEL > 2) 50 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\ 51 | printf(__VA_ARGS__);\ 52 | printf("\n"); 53 | #else 54 | #define USBD_DbgLog(...) 55 | #endif 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* __USBD_CONF__H__ */ 62 | -------------------------------------------------------------------------------- /Main/Sound/usbd_core.h: -------------------------------------------------------------------------------- 1 | #ifndef __USBD_CORE_H 2 | #define __USBD_CORE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | /* Includes ------------------------------------------------------------------*/ 10 | #include "usbd_conf.h" 11 | #include "usbd_def.h" 12 | #include "usbd_ioreq.h" 13 | #include "usbd_ctlreq.h" 14 | 15 | #ifndef USBD_DEBUG_LEVEL 16 | #define USBD_DEBUG_LEVEL 0U 17 | #endif /* USBD_DEBUG_LEVEL */ 18 | 19 | #define USBD_SOF USBD_LL_SOF 20 | 21 | USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, 22 | USBD_DescriptorsTypeDef *pdesc, uint8_t id); 23 | USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev); 24 | USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev); 25 | USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev); 26 | USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, 27 | USBD_ClassTypeDef *pclass); 28 | 29 | USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev); 30 | USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 31 | USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 32 | 33 | USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup); 34 | USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, 35 | uint8_t *pdata); 36 | USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, 37 | uint8_t *pdata); 38 | 39 | USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev); 40 | USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, 41 | USBD_SpeedTypeDef speed); 42 | USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev); 43 | USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev); 44 | 45 | USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev); 46 | USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, 47 | uint8_t epnum); 48 | USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, 49 | uint8_t epnum); 50 | 51 | USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev); 52 | USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev); 53 | 54 | /* USBD Low Level Driver */ 55 | USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev); 56 | USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev); 57 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev); 58 | USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev); 59 | USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, 60 | uint8_t ep_type, uint16_t ep_mps); 61 | 62 | USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 63 | USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 64 | USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 65 | USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, 66 | uint8_t ep_addr); 67 | uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 68 | USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, 69 | uint8_t dev_addr); 70 | USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, 71 | uint8_t *pbuf, uint16_t size); 72 | 73 | USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, 74 | uint8_t ep_addr, uint8_t *pbuf, uint16_t size); 75 | 76 | uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 77 | void USBD_LL_Delay(uint32_t Delay); 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif /* __USBD_CORE_H */ 84 | -------------------------------------------------------------------------------- /Main/Sound/usbd_ctlreq.h: -------------------------------------------------------------------------------- 1 | #ifndef __USB_REQUEST_H 2 | #define __USB_REQUEST_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | #include "usbd_def.h" 10 | 11 | USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, 12 | USBD_SetupReqTypedef *req); 13 | USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, 14 | USBD_SetupReqTypedef *req); 15 | USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, 16 | USBD_SetupReqTypedef *req); 17 | 18 | void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 19 | 20 | void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata); 21 | 22 | void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len); 23 | /** 24 | * @} 25 | */ 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* __USB_REQUEST_H */ 32 | -------------------------------------------------------------------------------- /Main/Sound/usbd_desc.h: -------------------------------------------------------------------------------- 1 | #ifndef __USBD_DESC__C__ 2 | #define __USBD_DESC__C__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | /* Includes ------------------------------------------------------------------*/ 10 | #include "usbd_def.h" 11 | 12 | #define DEVICE_ID1 (UID_BASE) 13 | #define DEVICE_ID2 (UID_BASE + 0x4) 14 | #define DEVICE_ID3 (UID_BASE + 0x8) 15 | 16 | #define USB_SIZ_STRING_SERIAL 0x1A 17 | 18 | extern USBD_DescriptorsTypeDef FS_Desc; 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif /* __USBD_DESC__C__ */ 25 | -------------------------------------------------------------------------------- /Main/Sound/usbd_ioreq.c: -------------------------------------------------------------------------------- 1 | #include "usbd_ioreq.h" 2 | 3 | /** 4 | * @brief USBD_CtlSendData 5 | * send data on the ctl pipe 6 | * @param pdev: device instance 7 | * @param buff: pointer to data buffer 8 | * @param len: length of data to be sent 9 | * @retval status 10 | */ 11 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, 12 | uint16_t len) 13 | { 14 | /* Set EP0 State */ 15 | pdev->ep0_state = USBD_EP0_DATA_IN; 16 | pdev->ep_in[0].total_length = len; 17 | pdev->ep_in[0].rem_length = len; 18 | 19 | /* Start the transfer */ 20 | USBD_LL_Transmit(pdev, 0x00U, pbuf, len); 21 | 22 | return USBD_OK; 23 | } 24 | 25 | /** 26 | * @brief USBD_CtlContinueSendData 27 | * continue sending data on the ctl pipe 28 | * @param pdev: device instance 29 | * @param buff: pointer to data buffer 30 | * @param len: length of data to be sent 31 | * @retval status 32 | */ 33 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, 34 | uint8_t *pbuf, uint16_t len) 35 | { 36 | /* Start the next transfer */ 37 | USBD_LL_Transmit(pdev, 0x00U, pbuf, len); 38 | 39 | return USBD_OK; 40 | } 41 | 42 | /** 43 | * @brief USBD_CtlPrepareRx 44 | * receive data on the ctl pipe 45 | * @param pdev: device instance 46 | * @param buff: pointer to data buffer 47 | * @param len: length of data to be received 48 | * @retval status 49 | */ 50 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, uint8_t *pbuf, 51 | uint16_t len) 52 | { 53 | /* Set EP0 State */ 54 | pdev->ep0_state = USBD_EP0_DATA_OUT; 55 | pdev->ep_out[0].total_length = len; 56 | pdev->ep_out[0].rem_length = len; 57 | 58 | /* Start the transfer */ 59 | USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 60 | 61 | return USBD_OK; 62 | } 63 | 64 | /** 65 | * @brief USBD_CtlContinueRx 66 | * continue receive data on the ctl pipe 67 | * @param pdev: device instance 68 | * @param buff: pointer to data buffer 69 | * @param len: length of data to be received 70 | * @retval status 71 | */ 72 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, uint8_t *pbuf, 73 | uint16_t len) 74 | { 75 | USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 76 | 77 | return USBD_OK; 78 | } 79 | 80 | /** 81 | * @brief USBD_CtlSendStatus 82 | * send zero lzngth packet on the ctl pipe 83 | * @param pdev: device instance 84 | * @retval status 85 | */ 86 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev) 87 | { 88 | /* Set EP0 State */ 89 | pdev->ep0_state = USBD_EP0_STATUS_IN; 90 | 91 | /* Start the transfer */ 92 | USBD_LL_Transmit(pdev, 0x00U, NULL, 0U); 93 | 94 | return USBD_OK; 95 | } 96 | 97 | /** 98 | * @brief USBD_CtlReceiveStatus 99 | * receive zero lzngth packet on the ctl pipe 100 | * @param pdev: device instance 101 | * @retval status 102 | */ 103 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev) 104 | { 105 | /* Set EP0 State */ 106 | pdev->ep0_state = USBD_EP0_STATUS_OUT; 107 | 108 | /* Start the transfer */ 109 | USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); 110 | 111 | return USBD_OK; 112 | } 113 | 114 | /** 115 | * @brief USBD_GetRxCount 116 | * returns the received data length 117 | * @param pdev: device instance 118 | * @param ep_addr: endpoint address 119 | * @retval Rx Data blength 120 | */ 121 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 122 | { 123 | return USBD_LL_GetRxDataSize(pdev, ep_addr); 124 | } 125 | -------------------------------------------------------------------------------- /Main/Sound/usbd_ioreq.h: -------------------------------------------------------------------------------- 1 | #ifndef __USBD_IOREQ_H 2 | #define __USBD_IOREQ_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | #include "usbd_def.h" 10 | #include "usbd_core.h" 11 | 12 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, 13 | uint16_t len); 14 | 15 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, 16 | uint8_t *pbuf, uint16_t len); 17 | 18 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, uint8_t *pbuf, 19 | uint16_t len); 20 | 21 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, uint8_t *pbuf, 22 | uint16_t len); 23 | 24 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev); 25 | 26 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev); 27 | 28 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /* __USBD_IOREQ_H */ 35 | -------------------------------------------------------------------------------- /Main/Sound/usbd_midi.h: -------------------------------------------------------------------------------- 1 | #ifndef __USB_MIDI_H 2 | #define __USB_MIDI_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "usbd_ioreq.h" 9 | 10 | #define MIDI_IN_EP 0x81U /* EP1 for data IN */ 11 | #define MIDI_OUT_EP 0x01U /* EP1 for data OUT */ 12 | #define MIDI_CMD_EP 0x82U /* EP2 for CDC commands */ 13 | 14 | #ifndef MIDI_HS_BINTERVAL 15 | #define MIDI_HS_BINTERVAL 0x10U 16 | #endif /* MIDI_HS_BINTERVAL */ 17 | 18 | #ifndef MIDI_FS_BINTERVAL 19 | #define MIDI_FS_BINTERVAL 0x10U 20 | #endif /* MIDI_FS_BINTERVAL */ 21 | 22 | #define MIDI_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */ 23 | #define MIDI_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */ 24 | #define MIDI_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */ 25 | 26 | #define USB_MIDI_CONFIG_DESC_SIZ 101 27 | #define MIDI_DATA_HS_IN_PACKET_SIZE MIDI_DATA_HS_MAX_PACKET_SIZE 28 | #define MIDI_DATA_HS_OUT_PACKET_SIZE MIDI_DATA_HS_MAX_PACKET_SIZE 29 | 30 | #define MIDI_DATA_FS_IN_PACKET_SIZE MIDI_DATA_FS_MAX_PACKET_SIZE 31 | #define MIDI_DATA_FS_OUT_PACKET_SIZE MIDI_DATA_FS_MAX_PACKET_SIZE 32 | 33 | #define MIDI_SEND_ENCAPSULATED_COMMAND 0x00U 34 | #define MIDI_GET_ENCAPSULATED_RESPONSE 0x01U 35 | #define MIDI_SET_COMM_FEATURE 0x02U 36 | #define MIDI_GET_COMM_FEATURE 0x03U 37 | #define MIDI_CLEAR_COMM_FEATURE 0x04U 38 | #define MIDI_SET_LINE_CODING 0x20U 39 | #define MIDI_GET_LINE_CODING 0x21U 40 | #define MIDI_SET_CONTROL_LINE_STATE 0x22U 41 | #define MIDI_SEND_BREAK 0x23U 42 | 43 | typedef struct { 44 | uint32_t bitrate; 45 | uint8_t format; 46 | uint8_t paritytype; 47 | uint8_t datatype; 48 | } USBD_MIDI_LineCodingTypeDef; 49 | 50 | typedef struct _USBD_MIDI_Itf { 51 | int8_t (*Init)(void); 52 | int8_t (*DeInit)(void); 53 | int8_t (*Control)(uint8_t cmd, uint8_t* pbuf, uint16_t length); 54 | int8_t (*Receive)(uint8_t* Buf, uint32_t *Len); 55 | } USBD_MIDI_ItfTypeDef; 56 | 57 | typedef struct { 58 | uint32_t data[MIDI_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32bits alignment */ 59 | uint8_t CmdOpCode; 60 | uint8_t CmdLength; 61 | uint8_t *RxBuffer; 62 | uint8_t *TxBuffer; 63 | uint32_t RxLength; 64 | uint32_t TxLength; 65 | 66 | __IO uint32_t TxState; 67 | __IO uint32_t RxState; 68 | } USBD_MIDI_HandleTypeDef; 69 | 70 | extern USBD_ClassTypeDef USBD_MIDI; 71 | #define USBD_MIDI_CLASS &USBD_MIDI 72 | 73 | uint8_t USBD_MIDI_RegisterInterface(USBD_HandleTypeDef *pdev, 74 | USBD_MIDI_ItfTypeDef *fops); 75 | 76 | uint8_t USBD_MIDI_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, 77 | uint16_t length); 78 | 79 | uint8_t USBD_MIDI_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff); 80 | 81 | uint8_t USBD_MIDI_ReceivePacket(USBD_HandleTypeDef *pdev); 82 | 83 | uint8_t USBD_MIDI_TransmitPacket(USBD_HandleTypeDef *pdev); 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /* __USB_MIDI_H */ 90 | -------------------------------------------------------------------------------- /Main/Sound/usbd_midi_if.h: -------------------------------------------------------------------------------- 1 | #ifndef __USBD_MIDI_IF_H__ 2 | #define __USBD_MIDI_IF_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | #include "usbd_midi.h" 10 | 11 | extern USBD_MIDI_ItfTypeDef USBD_Interface_fops_FS; 12 | 13 | uint8_t MIDI_Transmit_FS(uint8_t* Buf, uint16_t Len); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif /* __USBD_MIDI_IF_H__ */ 20 | -------------------------------------------------------------------------------- /Main/Sound/volume.c: -------------------------------------------------------------------------------- 1 | #include "volume.h" 2 | 3 | const unsigned char volume[] = { 4 | 0, 8, 17, 25, 34, 42, 51, 59, 68, 76, 85, 93, 102, 110, 119, 127 5 | }; 6 | -------------------------------------------------------------------------------- /Main/Sound/volume.h: -------------------------------------------------------------------------------- 1 | #ifndef _VOLUME_H 2 | #define _VOLUME_H 3 | 4 | extern const unsigned char volume[]; 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /Main/emulator.h: -------------------------------------------------------------------------------- 1 | #ifndef __EMULATOR_H__ 2 | #define __EMULATOR_H__ 3 | 4 | #include "Display/Screen.h" 5 | #include "Emulator/SpectrumScreen.h" 6 | #include "fatfs.h" 7 | 8 | using namespace Display; 9 | 10 | #define DEBUG_COLUMNS 50 11 | #define DEBUG_ROWS 8 12 | 13 | typedef struct 14 | { 15 | uint8_t Pixels[32 * 8 * 24]; 16 | uint16_t Attributes[32 * 24]; 17 | uint8_t BorderColor; 18 | } SpectrumScreenData; 19 | 20 | extern Screen DebugScreen; 21 | extern SpectrumScreen MainScreen; 22 | extern uint8_t _buffer16K_1[0x4000]; 23 | extern uint8_t _buffer16K_2[0x4000]; 24 | 25 | void showKeyboardSetup(); 26 | bool showKeyboardLoop(); 27 | 28 | void setDateTimeSetup(); 29 | bool setDateTimeLoop(); 30 | 31 | void showHelp(); 32 | void clearHelp(); 33 | void toggleHelp(); 34 | void restoreHelp(); 35 | 36 | void initializeVideo(); 37 | void startVideo(); 38 | void showErrorMessage(const char* errorMessage); 39 | void showTitle(const char* title); 40 | 41 | void saveState(); 42 | void restoreState(bool restoreScreen); 43 | 44 | void showRegisters(); 45 | 46 | #endif /* __EMULATOR_H__ */ 47 | -------------------------------------------------------------------------------- /Main/etl/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 - 2014, Cliff L. Biffle 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /Main/etl/README.mkdn: -------------------------------------------------------------------------------- 1 | Embedded Template Library 2 | ========================= 3 | 4 | This is my collection of reusable embedded code. I found myself either 5 | rewriting or copying and pasting code like this into each project, so I 6 | centralized it here. 7 | 8 | This is intended to be used as a submodule. It's designed to be used in 9 | projects that do not rely on toolchain facilities like libc, libstdc++, 10 | or startup code, because I'm weird like that. 11 | 12 | The tests are in a separate repo for now. 13 | 14 | **Caveat hax0r:** this code is currently subject to change at my whims. I am 15 | not currently supporting a 'released' version. (This is mostly true because I 16 | haven't heard from anyone who wants to use it.) 17 | -------------------------------------------------------------------------------- /Main/etl/algorithm.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ALGORITHM_H_INCLUDED 2 | #define _ETL_ALGORITHM_H_INCLUDED 3 | 4 | /* 5 | * Provides algorithmic utility functions that weren't interesting enough 6 | * to merit their own header. 7 | * 8 | * Analog of C++ , which is not available in freestanding 9 | * implementations. 10 | */ 11 | 12 | namespace etl { 13 | 14 | template 15 | constexpr T const & min(T const & a, T const & b) { 16 | return a < b ? a : b; 17 | } 18 | 19 | template 20 | constexpr T const & max(T const & a, T const & b) { 21 | return a > b ? a : b; 22 | } 23 | 24 | } // namespace etl 25 | 26 | #endif // _ETL_ALGORITHM_H_INCLUDED 27 | -------------------------------------------------------------------------------- /Main/etl/armv7m/actlr.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ARMV7M_ACTLR_H_INCLUDED 2 | #define _ETL_ARMV7M_ACTLR_H_INCLUDED 3 | 4 | #include "etl/armv7m/types.h" 5 | 6 | namespace etl { 7 | namespace armv7m { 8 | 9 | /* 10 | * The Auxiliary Control Register, which is sort of lurking off on its own 11 | * and is implementation-defined. 12 | */ 13 | extern Word volatile actlr; 14 | 15 | } // namespace armv7m 16 | } // namespace etl 17 | 18 | #endif // _ETL_ARMV7M_ACTLR_H_INCLUDED 19 | -------------------------------------------------------------------------------- /Main/etl/armv7m/exception_frame.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ARMV7M_EXCEPTION_FRAME_H_INCLUDED 2 | #define _ETL_ARMV7M_EXCEPTION_FRAME_H_INCLUDED 3 | 4 | /* 5 | * Describes the structure pushed onto the active stack when the processor 6 | * begins servicing an interrupt. 7 | */ 8 | 9 | #include "etl/armv7m/types.h" 10 | 11 | namespace etl { 12 | namespace armv7m { 13 | 14 | struct ExceptionFrame { 15 | Word r0, r1, r2, r3; 16 | Word r12; 17 | Word r14, r15; 18 | Word psr; 19 | }; 20 | 21 | } // namespace armv7m 22 | } // namespace etl 23 | 24 | #endif // _ETL_ARMV7M_EXCEPTION_FRAME_H_INCLUDED 25 | -------------------------------------------------------------------------------- /Main/etl/armv7m/exception_table.cc: -------------------------------------------------------------------------------- 1 | #include "etl/armv7m/exception_table.h" 2 | 3 | #include "etl/attribute_macros.h" 4 | 5 | namespace etl { 6 | namespace armv7m { 7 | 8 | // Architectural sanity check: 9 | static_assert(sizeof(ExceptionTable) == 16 * sizeof(Word), 10 | "ExceptionTable size is wrong."); 11 | 12 | /* 13 | * There are a couple of nuances to the exception table definition. 14 | * 15 | * 1. We place it in a section called .etl_armv7m_exception_table. There's 16 | * nothing special about that name, except that the linker scripts look for 17 | * it and put it in the right place. 18 | * 19 | * 2. We make the table const, ensuring that the linker will let us place it 20 | * in Flash if the linker script wants it there. 21 | * 22 | * 3. Of course, this table doesn't include any vendor-specific interrupt 23 | * vectors, which are typically tacked on right at the end using a separate 24 | * section in the linker script. 25 | * 26 | * While this is marked ETL_USED, this is often not sufficient given how we 27 | * build the code. The linker script may need to contain an explicit EXTERN 28 | * declaration ensuring that this gets linked in. 29 | */ 30 | ETL_SECTION(".etl_armv7m_exception_table") 31 | ETL_USED 32 | ExceptionTable const exception_table = { 33 | &etl_armv7m_initial_stack_top, 34 | etl_armv7m_reset_handler, 35 | 36 | #define ETL_ARMV7M_EXCEPTION(name) etl_armv7m_##name##_handler, 37 | #define ETL_ARMV7M_EXCEPTION_RESERVED(n) nullptr, 38 | #include "etl/armv7m/exceptions.def" 39 | #undef ETL_ARMV7M_EXCEPTION 40 | #undef ETL_ARMV7M_EXCEPTION_RESERVED 41 | }; 42 | 43 | } // namespace armv7m 44 | } // namespace etl 45 | -------------------------------------------------------------------------------- /Main/etl/armv7m/exception_table.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ARMV7M_EXCEPTION_TABLE_H_INCLUDED 2 | #define _ETL_ARMV7M_EXCEPTION_TABLE_H_INCLUDED 3 | 4 | #include "etl/armv7m/types.h" 5 | 6 | /* 7 | * ARMv7M Exceptions 8 | * 9 | * The architecture defines 16 exceptions, some of which are reserved. These 10 | * signal processor-internal conditions, as opposed to interrupts, which are 11 | * defined by the SoC and signal external conditions. 12 | * 13 | * Exception names and ordering are defined in the exceptions.def x-macro 14 | * file. 15 | * 16 | * For ease of interfacing with assembly, exception handlers are defined as 17 | * C-style unmangled symbols in the top-level namespace. 18 | * 19 | * We don't provide any default exception linkage. The application is 20 | * responsible for mapping *all* exceptions to handler functions, which may be 21 | * trivial. (Note that this is explicitly different from CMSIS implementations, 22 | * which usually provide weak definitions.) 23 | */ 24 | 25 | /* 26 | * Handler hooks are named `etl_armv7m_foo_handler`, where `foo` is the name of 27 | * the exception as defined in exceptions.def. e.g. etl_armv7m_reset_handler. 28 | * They're defined with C linkage to allow them to be easily defined outside of 29 | * this namespace, by the application. 30 | */ 31 | 32 | extern "C" { 33 | void etl_armv7m_reset_handler(); 34 | 35 | #define ETL_ARMV7M_EXCEPTION(name) void etl_armv7m_ ## name ## _handler(); 36 | #define ETL_ARMV7M_EXCEPTION_RESERVED(n) /* nothing */ 37 | #include "etl/armv7m/exceptions.def" 38 | #undef ETL_ARMV7M_EXCEPTION 39 | #undef ETL_ARMV7M_EXCEPTION_RESERVED 40 | 41 | /* 42 | * The exception table also contains the initial stack pointer, to be used 43 | * when calling the reset handler. The application must define this, either 44 | * in code or the linker script, to be the word just above the initial stack. 45 | * 46 | * It's const because, typically, it's an address just above the top of RAM -- 47 | * so you'd best not try to write it. 48 | */ 49 | 50 | extern etl::armv7m::Word const etl_armv7m_initial_stack_top; 51 | } 52 | 53 | namespace etl { 54 | namespace armv7m { 55 | 56 | // ARMv7-M ISR entry points look like this: 57 | typedef void (*ExceptionHandler)(void); 58 | 59 | struct ExceptionTable { 60 | Word const *initial_stack_top; 61 | ExceptionHandler reset_handler; 62 | 63 | #define ETL_ARMV7M_EXCEPTION(name) ExceptionHandler name ## _handler; 64 | #define ETL_ARMV7M_EXCEPTION_RESERVED(n) ExceptionHandler __reserved ## n; 65 | #include "etl/armv7m/exceptions.def" 66 | #undef ETL_ARMV7M_EXCEPTION 67 | #undef ETL_ARMV7M_EXCEPTION_RESERVED 68 | }; 69 | 70 | } // namespace armv7m 71 | } // namespace etl 72 | 73 | #endif // _ETL_ARMV7M_EXCEPTION_TABLE_H_INCLUDED 74 | -------------------------------------------------------------------------------- /Main/etl/armv7m/exceptions.def: -------------------------------------------------------------------------------- 1 | /* vim:syntax=cpp: 2 | * Definitions of ARMv7M architectural exceptions. This is an X-Macro file. 3 | * 4 | * This file is order-sensitive! ARMv7M numbers exceptions starting with 1 5 | * in the order given below. 6 | * 7 | * Note that some vendors (ab)use the RESERVED exception vectors for their 8 | * own purposes, so you SHOULD NOT attempt to (ab)use them yourself! 9 | * 10 | * We omit the reset vector here. 11 | */ 12 | ETL_ARMV7M_EXCEPTION(nmi ) 13 | ETL_ARMV7M_EXCEPTION(hard_fault ) 14 | ETL_ARMV7M_EXCEPTION(mem_manage_fault) 15 | ETL_ARMV7M_EXCEPTION(bus_fault ) 16 | ETL_ARMV7M_EXCEPTION(usage_fault ) 17 | 18 | ETL_ARMV7M_EXCEPTION_RESERVED( 7) 19 | ETL_ARMV7M_EXCEPTION_RESERVED( 8) 20 | ETL_ARMV7M_EXCEPTION_RESERVED( 9) 21 | ETL_ARMV7M_EXCEPTION_RESERVED(10) 22 | 23 | ETL_ARMV7M_EXCEPTION(sv_call ) 24 | ETL_ARMV7M_EXCEPTION(debug_monitor) 25 | 26 | ETL_ARMV7M_EXCEPTION_RESERVED(13) 27 | 28 | ETL_ARMV7M_EXCEPTION(pend_sv ) 29 | ETL_ARMV7M_EXCEPTION(sys_tick) 30 | -------------------------------------------------------------------------------- /Main/etl/armv7m/exceptions.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ARMV7M_EXCEPTIONS_H_INCLUDED 2 | #define _ETL_ARMV7M_EXCEPTIONS_H_INCLUDED 3 | 4 | namespace etl { 5 | namespace armv7m { 6 | 7 | /* 8 | * This provides number and name for each architectural exception, using the 9 | * same numbering as the IPSR and vectactive registers. 10 | */ 11 | enum class Exception { 12 | reset = 1, // Not present in exceptions.def for convenience 13 | 14 | #define ETL_ARMV7M_EXCEPTION(name) name, 15 | #define ETL_ARMV7M_EXCEPTION_RESERVED(n) __reserved_ ## n, 16 | #include "etl/armv7m/exceptions.def" 17 | #undef ETL_ARMV7M_EXCEPTION 18 | #undef ETL_ARMV7M_EXCEPTION_RESERVED 19 | }; 20 | 21 | } // namespace armv7m 22 | } // namespace etl 23 | 24 | #endif // _ETL_ARMV7M_EXCEPTIONS_H_INCLUDED 25 | -------------------------------------------------------------------------------- /Main/etl/armv7m/instructions.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ARMV7M_INSTRUCTIONS_H_INCLUDED 2 | #define _ETL_ARMV7M_INSTRUCTIONS_H_INCLUDED 3 | 4 | /* 5 | * C++ function wrappers for GCC ARM intrinsics and inline assembly. 6 | */ 7 | 8 | #include 9 | 10 | #include "etl/attribute_macros.h" 11 | 12 | namespace etl { 13 | namespace armv7m { 14 | 15 | /* 16 | * Wait For Interrupt -- idles the processor until an interrupt arrives. 17 | * This can frequently save power, depending on how the processor is configured. 18 | */ 19 | ETL_INLINE void wait_for_interrupt() { 20 | asm volatile ("wfi"); 21 | } 22 | 23 | /* 24 | * Data Synchronization Barrier -- ensures that all memory accesses that occur 25 | * before this point (in program order) have completed before the next 26 | * instruction executes. This is useful when writing to system control 27 | * registers. 28 | * 29 | * Note that a DSB is *not* sufficient when writing a register that may affect 30 | * what areas of memory can be executed. It doesn't prevent the processor from 31 | * fetching instructions past the DSB, just executing them. For that, you also 32 | * need an ISB (below). 33 | */ 34 | ETL_INLINE void data_synchronization_barrier() { 35 | asm volatile ("dsb"); 36 | } 37 | 38 | /* 39 | * Data Memory Barrier -- ensures that all memory accesses that occur before 40 | * this point (in program order) complete before any memory accesses that occur 41 | * after this point. 42 | */ 43 | ETL_INLINE void data_memory_barrier() { 44 | asm volatile ("dmb"); 45 | } 46 | 47 | /* 48 | * Instruction Synchronization Barrier -- ensures that all instructions after 49 | * this point (in program order) are fetched from memory only after any context 50 | * changes before this point have completed. In particular, this is necessary 51 | * when changing memory cache settings, access permissions, branch prediction, 52 | * or interrupt priorities. 53 | * 54 | * This is effectively equivalent to (and roughly as costly as) a complete 55 | * flush of all processor pipelines. 56 | * 57 | * Note that this doesn't necessarily imply a data barrier. If your context 58 | * altering operation is a result of writing memory, you probably also need a 59 | * DSB (above). 60 | */ 61 | ETL_INLINE void instruction_synchronization_barrier() { 62 | asm volatile ("isb"); 63 | } 64 | 65 | /* 66 | * Disables interrupts ("cpsid i"). On ARMv7-M this uses PRIMASK. 67 | */ 68 | ETL_INLINE void disable_interrupts() { 69 | asm volatile ("cpsid i"); 70 | } 71 | 72 | /* 73 | * Enables interrupts ("cpsie i"). On ARMv7-M this uses PRIMASK. 74 | */ 75 | ETL_INLINE void enable_interrupts() { 76 | asm volatile ("cpsie i"); 77 | } 78 | 79 | 80 | 81 | } // namespace armv7m 82 | } // namespace etl 83 | 84 | #endif // _ETL_ARMV7M_INSTRUCTIONS_H_INCLUDED 85 | -------------------------------------------------------------------------------- /Main/etl/armv7m/mpu.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ARMV7M_MPU_H_INCLUDED 2 | #define _ETL_ARMV7M_MPU_H_INCLUDED 3 | 4 | #include "etl/armv7m/types.h" 5 | 6 | namespace etl { 7 | namespace armv7m { 8 | 9 | /* 10 | * The ARMv7-M Memory Protection Unit, or MPU, is defined by section B3.5 11 | * of the ARMv7-M ARM. 12 | * 13 | * See the comments in the register definition file for more details. 14 | */ 15 | struct Mpu { 16 | enum class AccessPermissions : Byte { 17 | p_none_u_none = 0b000, 18 | p_write_u_none = 0b001, 19 | p_write_u_read = 0b010, 20 | p_write_u_write = 0b011, 21 | p_read_u_none = 0b101, 22 | p_read_u_read = 0b110, 23 | }; 24 | 25 | #define ETL_BFF_DEFINITION_FILE "etl/armv7m/mpu.reg" 26 | #include "etl/biffield/generate.h" 27 | #undef ETL_BFF_DEFINITION_FILE 28 | }; 29 | 30 | extern Mpu mpu; 31 | 32 | } // namespace armv7m 33 | } // namespace etl 34 | 35 | #endif // _ETL_ARMV7M_MPU_H_INCLUDED 36 | -------------------------------------------------------------------------------- /Main/etl/armv7m/nvic.cc: -------------------------------------------------------------------------------- 1 | #include "etl/armv7m/nvic.h" 2 | #include "etl/armv7m/instructions.h" 3 | 4 | namespace etl { 5 | namespace armv7m { 6 | 7 | void Nvic::enable_irq(unsigned irq) { 8 | unsigned bank = irq / 32; 9 | unsigned index = irq % 32; 10 | 11 | write_iser(bank, iser_value_t().with_bit(index, true)); 12 | data_memory_barrier(); 13 | instruction_synchronization_barrier(); 14 | } 15 | 16 | void Nvic::disable_irq(unsigned irq) { 17 | unsigned bank = irq / 32; 18 | unsigned index = irq % 32; 19 | 20 | write_icer(bank, icer_value_t().with_bit(index, true)); 21 | data_memory_barrier(); 22 | instruction_synchronization_barrier(); 23 | } 24 | 25 | void Nvic::clear_pending_irq(unsigned irq) { 26 | unsigned bank = irq / 32; 27 | unsigned index = irq % 32; 28 | 29 | write_icpr(bank, icpr_value_t().with_bit(index, true)); 30 | data_memory_barrier(); 31 | instruction_synchronization_barrier(); 32 | } 33 | 34 | void Nvic::set_irq_priority(unsigned irq, Byte priority) { 35 | unsigned bank = irq / 4; 36 | unsigned index = irq % 4; 37 | 38 | update_ipr(bank, [&](ipr_value_t x) { 39 | return x.with_priority(index, priority); 40 | }); 41 | 42 | // swap implies a DMB. 43 | instruction_synchronization_barrier(); 44 | } 45 | 46 | } // namespace armv7m 47 | } // namespace etl 48 | -------------------------------------------------------------------------------- /Main/etl/armv7m/nvic.reg: -------------------------------------------------------------------------------- 1 | // vim:syntax=cpp: 2 | // ARMv7-M Nested Vectored Interrupt Controller register definitions 3 | 4 | /* 5 | * The Interrupt Set Enabled Registers have one bit for each potential 6 | * interrupt source. Writing ones causes the corresponding interrupt(s) to 7 | * become enabled; others remain unchanged. 8 | */ 9 | ETL_BFF_REG_ARRAY_RW(Word, iser, 16, 10 | ETL_BFF_FIELD_ARRAY(31: 0, 1, bool, bit) 11 | ETL_BFF_FIELD (31: 0, Word, all_bits) 12 | ) 13 | ETL_BFF_REG_RESERVED(Word, after_iser, 16) 14 | 15 | /* 16 | * The Interrupt Clear Enabled Registers have one bit for each potential 17 | * interrupt source. Writing ones causes the corresponding interrupt(s) to 18 | * become disabled; others remain unchanged. 19 | */ 20 | ETL_BFF_REG_ARRAY_RW(Word, icer, 16, 21 | ETL_BFF_FIELD_ARRAY(31: 0, 1, bool, bit) 22 | ETL_BFF_FIELD (31: 0, Word, all_bits) 23 | ) 24 | ETL_BFF_REG_RESERVED(Word, after_icer, 16) 25 | 26 | /* 27 | * The Interrupt Set Pending Registers have one bit for each potential 28 | * interrupt source. Writing ones causes the corresponding interrupt(s) to 29 | * become pending; others remain unchanged. 30 | */ 31 | ETL_BFF_REG_ARRAY_RW(Word, ispr, 16, 32 | ETL_BFF_FIELD_ARRAY(31: 0, 1, bool, bit) 33 | ETL_BFF_FIELD (31: 0, Word, all_bits) 34 | ) 35 | ETL_BFF_REG_RESERVED(Word, after_ispr, 16) 36 | 37 | /* 38 | * The Interrupt Clear Pending Registers have one bit for each potential 39 | * interrupt source. Writing ones causes the corresponding interrupt(s) to 40 | * become non-pending; others remain unchanged. 41 | */ 42 | ETL_BFF_REG_ARRAY_RW(Word, icpr, 16, 43 | ETL_BFF_FIELD_ARRAY(31: 0, 1, bool, bit) 44 | ETL_BFF_FIELD (31: 0, Word, all_bits) 45 | ) 46 | ETL_BFF_REG_RESERVED(Word, after_icpr, 16) 47 | 48 | /* 49 | * The Interrupt Active Bit Registers have one bit for each potential 50 | * interrupt source. The bit is 1 if the interrupt is active, 0 otherwise. 51 | */ 52 | ETL_BFF_REG_ARRAY_RO(Word, iabr, 16, 53 | ETL_BFF_FIELD_ARRAY(31: 0, 1, bool, bit) 54 | ETL_BFF_FIELD (31: 0, Word, all_bits) 55 | ) 56 | ETL_BFF_REG_RESERVED(Word, after_iabr, 48) 57 | 58 | /* 59 | * The Interrupt Priority Registers contain an 8-bit field for each potential 60 | * interrupt source. The field contains the interrupt's priority. Note that 61 | * SoC vendors may leave some LSBs of the field unimplemented. 62 | */ 63 | ETL_BFF_REG_ARRAY_RW(Word, ipr, 124, 64 | ETL_BFF_FIELD_ARRAY(31: 0, 8, Byte, priority) 65 | ) 66 | -------------------------------------------------------------------------------- /Main/etl/armv7m/peripherals.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This linker script assigns addresses to standard ARMv7-M peripherals. 3 | */ 4 | 5 | _ZN3etl6armv7m5actlrE = 0xe000e008; 6 | _ZN3etl6armv7m8sys_tickE = 0xe000e010; 7 | _ZN3etl6armv7m4nvicE = 0xe000e100; 8 | _ZN3etl6armv7m3scbE = 0xe000ed00; 9 | _ZN3etl6armv7m6scb_fpE = 0xe000ed34; 10 | _ZN3etl6armv7m3mpuE = 0xe000ed90; 11 | -------------------------------------------------------------------------------- /Main/etl/armv7m/registers.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ARMV7M_REGISTERS_H_INCLUDED 2 | #define _ETL_ARMV7M_REGISTERS_H_INCLUDED 3 | 4 | #include "etl/armv7m/types.h" 5 | 6 | namespace etl { 7 | namespace armv7m { 8 | 9 | /* 10 | * Reads the contents of the Process Stack Pointer. 11 | */ 12 | inline Word get_psp() { 13 | Word result; 14 | asm ("mrs %0, PSP" : "=r"(result)); 15 | return result; 16 | } 17 | 18 | /* 19 | * Sets the contents of the Process Stack Pointer. Note that this will blow 20 | * the compiler's mind if done while executing from the PSP. 21 | */ 22 | inline void set_psp(Word value) { 23 | asm volatile ("msr PSP, %0" :: "r"(value)); 24 | } 25 | 26 | /* 27 | * Reads the contents of the Main Stack Pointer. 28 | */ 29 | inline Word get_msp() { 30 | Word result; 31 | asm ("mrs %0, MSP" : "=r"(result)); 32 | return result; 33 | } 34 | 35 | /* 36 | * Sets the contents of the BASEPRI register. 37 | */ 38 | inline void set_basepri(Word value) { 39 | asm volatile ("msr BASEPRI, %0" :: "r"(value)); 40 | } 41 | 42 | /* 43 | * Reads the contents of the BASEPRI register. 44 | */ 45 | inline Word get_basepri() { 46 | Word result; 47 | asm ("mrs %0, BASEPRI" : "=r"(result)); 48 | return result; 49 | } 50 | 51 | /* 52 | * Sets the contents of the CONTROL register. 53 | */ 54 | inline void set_control(Word value) { 55 | asm volatile ("msr CONTROL, %0" :: "r"(value)); 56 | } 57 | 58 | /* 59 | * Sets the contents of PRIMASK. 60 | */ 61 | inline void set_primask(bool value) { 62 | asm volatile ("msr PRIMASK, %0" :: "r"(value)); 63 | } 64 | 65 | /* 66 | * Reads the contents of the Interrupt Program Status Register. 67 | */ 68 | inline Word get_ipsr() { 69 | Word result; 70 | asm ("mrs %0, IPSR" : "=r"(result)); 71 | return result; 72 | } 73 | 74 | } // namespace armv7m 75 | } // namespace etl 76 | 77 | #endif // _ETL_ARMV7M_REGISTERS_H_INCLUDED 78 | -------------------------------------------------------------------------------- /Main/etl/armv7m/scb.cc: -------------------------------------------------------------------------------- 1 | #include "etl/armv7m/scb.h" 2 | 3 | #include "etl/assert.h" 4 | #include "etl/armv7m/instructions.h" 5 | 6 | namespace etl { 7 | namespace armv7m { 8 | 9 | void Scb::enable_faults() { 10 | update_shcsr([] (shcsr_value_t v) { 11 | return v.with_memfaultena(true) 12 | .with_busfaultena(true) 13 | .with_usgfaultena(true); 14 | }); 15 | instruction_synchronization_barrier(); 16 | } 17 | 18 | void Scb::set_exception_priority(Exception e, Byte p) { 19 | unsigned index = static_cast(e); 20 | ETL_ASSERT(index >= 4 && index <= 15); 21 | 22 | unsigned bank = (index - 4) / 4; 23 | unsigned slot = index % 4; 24 | 25 | switch (bank) { 26 | case 0: write_shpr1(read_shpr1().with_pri(slot, p)); break; 27 | case 1: write_shpr2(read_shpr2().with_pri(slot, p)); break; 28 | case 2: write_shpr3(read_shpr3().with_pri(slot, p)); break; 29 | } 30 | } 31 | 32 | } // namespace armv7m 33 | } // namespace etl 34 | -------------------------------------------------------------------------------- /Main/etl/armv7m/scb.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ARMV7M_SCB_H_INCLUDED 2 | #define _ETL_ARMV7M_SCB_H_INCLUDED 3 | 4 | #include "etl/armv7m/exceptions.h" 5 | #include "etl/armv7m/types.h" 6 | 7 | namespace etl { 8 | namespace armv7m { 9 | 10 | struct Scb { 11 | enum class CpAccess { 12 | none = 0b00, 13 | privileged = 0b01, 14 | full = 0b11, 15 | }; 16 | 17 | #define ETL_BFF_DEFINITION_FILE "etl/armv7m/scb.reg" 18 | #include "etl/biffield/generate.h" 19 | #undef ETL_BFF_DEFINITION_FILE 20 | 21 | public: 22 | /* 23 | * At reset, the processor sets MemManage, Bus, and Usage faults to the Hard 24 | * Fault handler, which complicates diagnostics. This fixes that. 25 | */ 26 | void enable_faults(); 27 | 28 | /* 29 | * Sets the priority of a configurable-priority exception. 30 | */ 31 | void set_exception_priority(Exception, Byte); 32 | }; 33 | 34 | extern Scb scb; 35 | 36 | } // namespace armv7m 37 | } // namespace etl 38 | 39 | #endif // _ETL_ARMV7M_SCB_H_INCLUDED 40 | -------------------------------------------------------------------------------- /Main/etl/armv7m/scb.reg: -------------------------------------------------------------------------------- 1 | // vim:syntax=cpp: 2 | // The ARMv7-M System Control Block (SCB) 3 | 4 | ETL_BFF_REG_RO(Word, cpuid, 5 | ETL_BFF_FIELD(31:24, Byte, implementer) 6 | ETL_BFF_FIELD(23:20, Byte, variant) 7 | ETL_BFF_FIELD(19:16, Byte, architecture) 8 | ETL_BFF_FIELD(15: 4, Word, partno) 9 | ETL_BFF_FIELD( 3: 0, Word, revision) 10 | ) 11 | 12 | ETL_BFF_REG_RW(Word, icsr, 13 | ETL_BFF_FIELD(31:31, bool, nmipendset) 14 | ETL_BFF_FIELD(28:28, bool, pendsvset) 15 | ETL_BFF_FIELD(27:27, bool, pendsvclr) 16 | ETL_BFF_FIELD(26:26, bool, pendstset) 17 | ETL_BFF_FIELD(25:25, bool, pendstclr) 18 | ETL_BFF_FIELD(23:23, bool, isrpreempt) 19 | ETL_BFF_FIELD(22:22, bool, isrpending) 20 | ETL_BFF_FIELD(20:12, unsigned, vectpending) 21 | ETL_BFF_FIELD(11:11, bool, rettobase) 22 | ETL_BFF_FIELD( 8: 0, unsigned, vectactive) 23 | ) 24 | 25 | ETL_BFF_REG_RW(Word, vtor, ) 26 | ETL_BFF_REG_RW(Word, aircr, ) 27 | ETL_BFF_REG_RW(Word, scr, ) 28 | ETL_BFF_REG_RW(Word, ccr, 29 | ETL_BFF_FIELD( 9: 9, bool, stkalign) 30 | ETL_BFF_FIELD( 8: 8, bool, bfhfnmign) 31 | ETL_BFF_FIELD( 4: 4, bool, div_0_trp) 32 | ETL_BFF_FIELD( 3: 3, bool, unalign_trp) 33 | ETL_BFF_FIELD( 1: 1, bool, usersetmpend) 34 | ETL_BFF_FIELD( 0: 0, bool, nonbasethrdena) 35 | ) 36 | ETL_BFF_REG_RW(Word, shpr1, 37 | ETL_BFF_FIELD_ARRAY(31: 0, 8, Byte, pri) 38 | ) 39 | ETL_BFF_REG_RW(Word, shpr2, 40 | ETL_BFF_FIELD_ARRAY(31: 0, 8, Byte, pri) 41 | ) 42 | ETL_BFF_REG_RW(Word, shpr3, 43 | ETL_BFF_FIELD_ARRAY(31: 0, 8, Byte, pri) 44 | ) 45 | 46 | ETL_BFF_REG_RW(Word, shcsr, 47 | ETL_BFF_FIELD(18:18, bool, usgfaultena) 48 | ETL_BFF_FIELD(17:17, bool, busfaultena) 49 | ETL_BFF_FIELD(16:16, bool, memfaultena) 50 | ETL_BFF_FIELD(15:15, bool, svcallpended) 51 | ETL_BFF_FIELD(14:14, bool, busfaultpended) 52 | ETL_BFF_FIELD(13:13, bool, memfaultpended) 53 | ETL_BFF_FIELD(12:12, bool, usgfaultpended) 54 | ETL_BFF_FIELD(11:11, bool, systickact) 55 | ETL_BFF_FIELD(10:10, bool, pendsvact) 56 | ETL_BFF_FIELD( 8: 8, bool, monitoract) 57 | ETL_BFF_FIELD( 7: 7, bool, svcallact) 58 | ETL_BFF_FIELD( 3: 3, bool, usgfaultact) 59 | ETL_BFF_FIELD( 1: 1, bool, busfaultact) 60 | ETL_BFF_FIELD( 0: 0, bool, memfaultact) 61 | ) 62 | 63 | ETL_BFF_REG_RW(Word, cfsr, 64 | ETL_BFF_FIELD(31:16, HalfWord, ufsr) 65 | ETL_BFF_FIELD(15: 8, Byte, bfsr) 66 | ETL_BFF_FIELD( 7: 0, Byte, mmfsr) 67 | ) 68 | ETL_BFF_REG_RW(Word, hfsr, ) 69 | ETL_BFF_REG_RW(Word, dfsr, ) 70 | ETL_BFF_REG_RW(Word, mmfar, ) 71 | ETL_BFF_REG_RW(Word, bfar, ) 72 | ETL_BFF_REG_RW(Word, afsr, ) 73 | 74 | ETL_BFF_REG_RESERVED(Word, 40, 18) 75 | 76 | ETL_BFF_REG_RW(Word, cpacr, 77 | ETL_BFF_FIELD(23:22, CpAccess, cp11) 78 | ETL_BFF_FIELD(21:20, CpAccess, cp10) 79 | ) 80 | -------------------------------------------------------------------------------- /Main/etl/armv7m/scb_fp.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ARMV7M_SCB_FP_H_INCLUDED 2 | #define _ETL_ARMV7M_SCB_FP_H_INCLUDED 3 | 4 | #include "etl/armv7m/types.h" 5 | 6 | namespace etl { 7 | namespace armv7m { 8 | 9 | struct ScbFp { 10 | #define ETL_BFF_DEFINITION_FILE "etl/armv7m/scb_fp.reg" 11 | #include "etl/biffield/generate.h" 12 | #undef ETL_BFF_DEFINITION_FILE 13 | }; 14 | 15 | extern ScbFp scb_fp; 16 | 17 | } // namespace armv7m 18 | } // namespace etl 19 | 20 | #endif // _ETL_ARMV7M_SCB_FP_H_INCLUDED 21 | -------------------------------------------------------------------------------- /Main/etl/armv7m/scb_fp.reg: -------------------------------------------------------------------------------- 1 | ETL_BFF_REG_RW(Word, fpccr, 2 | ETL_BFF_FIELD(31:31, bool, aspen) 3 | ETL_BFF_FIELD(30:30, bool, lspen) 4 | ETL_BFF_FIELD( 8: 8, bool, monrdy) 5 | ETL_BFF_FIELD( 6: 6, bool, bfrdy) 6 | ETL_BFF_FIELD( 5: 5, bool, mmrdy) 7 | ETL_BFF_FIELD( 4: 4, bool, hfrdy) 8 | ETL_BFF_FIELD( 3: 3, bool, thread) 9 | ETL_BFF_FIELD( 1: 1, bool, user) 10 | ETL_BFF_FIELD( 0: 0, bool, lspact) 11 | ) 12 | ETL_BFF_REG_RW(Word, fpcar, ) 13 | ETL_BFF_REG_RW(Word, fpdscr, ) 14 | ETL_BFF_REG_RO(Word, mvfr0, ) 15 | ETL_BFF_REG_RO(Word, mvfr1, ) 16 | -------------------------------------------------------------------------------- /Main/etl/armv7m/sys_tick.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ARMV7M_SYS_TICK_H_INCLUDED 2 | #define _ETL_ARMV7M_SYS_TICK_H_INCLUDED 3 | 4 | #include "etl/armv7m/types.h" 5 | 6 | namespace etl { 7 | namespace armv7m { 8 | 9 | struct SysTick { 10 | #define ETL_BFF_DEFINITION_FILE "etl/armv7m/sys_tick.reg" 11 | #include "etl/biffield/generate.h" 12 | #undef ETL_BFF_DEFINITION_FILE 13 | }; 14 | 15 | extern SysTick sys_tick; 16 | 17 | } // namespace armv7m 18 | } // namespace etl 19 | 20 | #endif // _ETL_ARMV7M_SYS_TICK_H_INCLUDED 21 | -------------------------------------------------------------------------------- /Main/etl/armv7m/sys_tick.reg: -------------------------------------------------------------------------------- 1 | ETL_BFF_REG_RW(Word, csr, 2 | ETL_BFF_FIELD (16:16, bool, countflag) 3 | ETL_BFF_FIELD_E( 2: 2, bool, clksource, 4 | ETL_BFF_ENUM(false, external_reference) 5 | ETL_BFF_ENUM(true, cpu_clock) 6 | ) 7 | ETL_BFF_FIELD ( 1: 1, bool, tickint) 8 | ETL_BFF_FIELD ( 0: 0, bool, enable) 9 | ) 10 | ETL_BFF_REG_RW(Word, rvr, 11 | ETL_BFF_FIELD(23: 0, unsigned, reload) 12 | ) 13 | ETL_BFF_REG_RW(Word, cvr, 14 | ETL_BFF_FIELD(31: 0, unsigned, current) 15 | ) 16 | ETL_BFF_REG_RW(Word, calib, 17 | ETL_BFF_FIELD(31:31, bool, noref) 18 | ETL_BFF_FIELD(30:30, bool, skew) 19 | ETL_BFF_FIELD(23: 0, unsigned, tenms) 20 | ) 21 | -------------------------------------------------------------------------------- /Main/etl/armv7m/types.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ARMV7M_TYPES_H_INCLUDED 2 | #define _ETL_ARMV7M_TYPES_H_INCLUDED 3 | 4 | #include 5 | 6 | namespace etl { 7 | namespace armv7m { 8 | 9 | /* 10 | * Abstract definitions of types used by the ARMv7-M architecture, using the 11 | * names used in the spec. We use these in cases, like registers, where the 12 | * size is more important than the numeric interpretation. 13 | * 14 | * We happen to use unsigned integers below to avoid sign-extension surprises 15 | * when shifting. 16 | */ 17 | 18 | typedef std::uint64_t DoubleWord; 19 | typedef std::uint32_t Word; 20 | typedef std::uint16_t HalfWord; 21 | typedef std::uint8_t Byte; 22 | 23 | } // namespace armv7m 24 | } // namespace etl 25 | 26 | #endif // _ETL_ARMV7M_TYPES_H_INCLUDED 27 | -------------------------------------------------------------------------------- /Main/etl/array_count.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ARRAY_COUNT_H_INCLUDED 2 | #define _ETL_ARRAY_COUNT_H_INCLUDED 3 | 4 | #include 5 | 6 | /* 7 | * Finds the number of elements in a static array. Replacement for the error 8 | * prone C idiom "sizeof(e) / sizeof(e[0])". 9 | */ 10 | 11 | namespace etl { 12 | 13 | template 14 | constexpr std::size_t array_count(E (&)[count]) { 15 | return count; 16 | } 17 | 18 | } // namespace etl 19 | 20 | #endif // _ETL_ARRAY_COUNT_H_INCLUDED 21 | -------------------------------------------------------------------------------- /Main/etl/assert.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ASSERT_H_INCLUDED 2 | #define _ETL_ASSERT_H_INCLUDED 3 | 4 | #include "etl/attribute_macros.h" 5 | 6 | /* 7 | * An assertion facility similar to the standard's, but which can call through 8 | * to a portable assertion handler instead of doing whatever the libc feels 9 | * like doing (often involving stack unwinding and other things we don't 10 | * support). 11 | * 12 | * In general, ETL_ASSERT(foo) is equivalent to assert(foo). If the macro 13 | * ETL_USE_SYSTEM_ASSERT is defined, the two are *precisely* equivalent. 14 | * Otherwise, ETL_ASSERT compiles code that tests the assertion; if it fails, 15 | * the hook function etl::assertion_failed is called. 16 | * 17 | * The application is responsible for defining etl::assertion_failed. 18 | * 19 | * The ETL implementation of ETL_ASSERT_CE is designed to be usable in constexpr 20 | * functions. When ETL_USE_SYSTEM_ASSERT is defined, your mileage may vary. 21 | */ 22 | 23 | namespace etl { 24 | /* 25 | * Hook used by ETL_ASSERT when an assertion fails. This is relevant 26 | * only when ETL_USE_SYSTEM_ASSERT is not defined, but it's prototyped 27 | * here unconditionally so that applications can change modes without 28 | * needing to compile out their implementations. 29 | * 30 | * Note that while assertion_failed has an argument slot to receive a 31 | * function name, ETL_ASSERT (below) does not pass one. This is due to 32 | * an odd interpretation of constexpr semantics by the GCC team in 4.8/4.9. 33 | */ 34 | ETL_NORETURN void assertion_failed(char const * file, 35 | int line, 36 | char const * function, 37 | char const * expression); 38 | } // namespace etl 39 | 40 | #ifdef ETL_USE_SYSTEM_ASSERT 41 | 42 | #include 43 | #define ETL_ASSERT(c) assert(c) 44 | #define ETL_ASSERT_CE(c) assert(c) 45 | 46 | #else // !defined(ETL_USE_SYSTEM_ASSERT) 47 | 48 | #define ETL_ASSERT(c) \ 49 | ((c) ? void(0) : ::etl::assertion_failed(__FILE__, \ 50 | __LINE__, \ 51 | __func__, \ 52 | #c)) 53 | 54 | /* 55 | * __func__ is defined, in C99 and C++11, as equivalent to a static const 56 | * string at function scope. In GCC 4.8/4.9, referencing it seems to cause 57 | * it to be added to the function...causing the function not to consist of 58 | * a return statement, and thus violate the constexpr rules for C++11. 59 | * 60 | * Sigh. 61 | * 62 | * Thus we provide a separate assert macro for use in constexpr environments. 63 | * TODO(cbiffle): unify these macros if the compiler folks figure out what 64 | * the right behavior is. 65 | */ 66 | #define ETL_ASSERT_CE(c) \ 67 | ((c) ? void(0) : ::etl::assertion_failed(__FILE__, \ 68 | __LINE__, \ 69 | "" /* TODO */, \ 70 | #c)) 71 | 72 | #endif // defined(ETL_USE_SYSTEM_ASSERT) 73 | 74 | 75 | #endif // _ETL_ASSERT_H_INCLUDED 76 | -------------------------------------------------------------------------------- /Main/etl/assert_loop.cc: -------------------------------------------------------------------------------- 1 | #include "etl/assert.h" 2 | 3 | namespace etl { 4 | 5 | void assertion_failed(char const * file, 6 | int line, 7 | char const * function, 8 | char const * expression) { 9 | // Parameters are named to help GDB display them. 10 | while (true); 11 | } 12 | 13 | } // namespace etl 14 | -------------------------------------------------------------------------------- /Main/etl/attribute_macros.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ATTRIBUTE_MACROS_H_INCLUDED 2 | #define _ETL_ATTRIBUTE_MACROS_H_INCLUDED 3 | 4 | /* 5 | * These are shorthand for GCC's attribute syntax. (The ETL_INLINE macro 6 | * also includes a keyword needed to make the attribute work.) 7 | */ 8 | 9 | /* 10 | * Function attributes. Place before return type in declaration. 11 | */ 12 | 13 | // Function does not return. 14 | #define ETL_NORETURN __attribute__((noreturn)) 15 | 16 | // Function should omit normal prologue/epilogue. 17 | #define ETL_NAKED __attribute__((naked)) 18 | 19 | // Function body should *really* not be generated outline. 20 | // This overrides conservative heuristics at -Os. 21 | #define ETL_INLINE inline __attribute__((always_inline)) 22 | 23 | // Function should *never* be inlined. Really. 24 | #define ETL_NOINLINE __attribute__((noinline)) 25 | 26 | 27 | /* 28 | * Data attributes. 29 | */ 30 | 31 | // Lay out data as specified. May hurt efficiency. 32 | #define ETL_PACKED __attribute__((packed)) 33 | 34 | // Ensure object starts at multiple of n bytes. 35 | #define ETL_ALIGNED(n) __attribute__((aligned(n))) 36 | 37 | 38 | /* 39 | * Multi-purpose attributes 40 | */ 41 | 42 | // Put object in specified linker section. 43 | #define ETL_SECTION(s) __attribute__((section(s))) 44 | 45 | // Consider object to be 'used' during linker GC. 46 | #define ETL_USED __attribute__((used)) 47 | 48 | // Object can be overridden during link time. 49 | #define ETL_WEAK __attribute__((weak)) 50 | 51 | // Object is an alias for something else. 52 | #define ETL_ALIAS(sym) __attribute__((alias(sym))) 53 | 54 | 55 | #endif // _ETL_ATTRIBUTE_MACROS_H_INCLUDED 56 | -------------------------------------------------------------------------------- /Main/etl/biffield/generate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * To produce register field, accessor, and type declarations, include this 3 | * file after defining ETL_BFF_DEFINITION_FILE. 4 | */ 5 | #define _ETL_BFF_INCLUDED_THROUGH_GENERATE 6 | 7 | /* 8 | * The order of these steps is significant. See the individual files for 9 | * details. 10 | */ 11 | public: 12 | #include "etl/biffield/generate_constants.h" 13 | #include "etl/biffield/generate_value_types.h" 14 | #include "etl/biffield/generate_accessors.h" 15 | 16 | private: 17 | #include "etl/biffield/checks.h" 18 | #include "etl/biffield/generate_fields.h" 19 | 20 | public: 21 | 22 | #undef _ETL_BFF_INCLUDED_THROUGH_GENERATE 23 | -------------------------------------------------------------------------------- /Main/etl/biffield/generate_fields.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_BFF_INCLUDED_THROUGH_GENERATE 2 | #error Do not include etl/biffield/generate_fields.h directly, \ 3 | use etl/biffield/generate.h 4 | #endif 5 | 6 | // This is non-const to dodge a GCC warning. Believe it! 7 | #define ETL_BFF_REG_RESERVED(__at, __rn, __n) __at _reserved_##__rn[__n]; 8 | 9 | 10 | #define ETL_BFF_REG_ARRAY_RW(__at, __rn, __n, __fs) \ 11 | __at volatile _##__rn[__n]; 12 | 13 | // This is non-const to dodge a GCC warning. Believe it! 14 | #define ETL_BFF_REG_ARRAY_RO(__at, __rn, __n, __fs) \ 15 | __at volatile _##__rn[__n]; 16 | 17 | #define ETL_BFF_REG_ARRAY_WO(__at, __rn, __n, __fs) \ 18 | __at volatile _##__rn[__n]; 19 | 20 | 21 | #define ETL_BFF_REG_RW(__at, __n, __fs) \ 22 | __at volatile _##__n; 23 | 24 | // This is non-const to dodge a GCC warning. Believe it! 25 | #define ETL_BFF_REG_RO(__at, __n, __fs) \ 26 | __at volatile _## __n; 27 | 28 | #define ETL_BFF_REG_WO(__at, __n, __fs) \ 29 | __at volatile _##__n; 30 | 31 | #include ETL_BFF_DEFINITION_FILE 32 | 33 | #undef ETL_BFF_REG_RW 34 | #undef ETL_BFF_REG_RO 35 | #undef ETL_BFF_REG_WO 36 | 37 | #undef ETL_BFF_REG_ARRAY_RW 38 | #undef ETL_BFF_REG_ARRAY_WO 39 | #undef ETL_BFF_REG_ARRAY_RO 40 | 41 | #undef ETL_BFF_REG_RESERVED 42 | -------------------------------------------------------------------------------- /Main/etl/concatenate.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_CONCATENATE_H_INCLUDED 2 | #define _ETL_CONCATENATE_H_INCLUDED 3 | 4 | /* 5 | * A macro for concatenating text tokens. Doing this is surprisingly involved 6 | * with the C preprocessor. 7 | */ 8 | #define ETL_CONCATENATE(a, b) _ETL_CONCATENATE(a, b) 9 | #define _ETL_CONCATENATE(a, b) a ## b 10 | 11 | #endif // _ETL_CONCATENATE_H_INCLUDED 12 | -------------------------------------------------------------------------------- /Main/etl/data/sort.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_DATA_SORT_H_INCLUDED 2 | #define _ETL_DATA_SORT_H_INCLUDED 3 | 4 | #include "etl/utility.h" 5 | #include "etl/data/range_ptr.h" 6 | 7 | namespace etl { 8 | namespace data { 9 | 10 | /* 11 | * Sorts the contents of a range in-place using quicksort and an arbitrary 12 | * comparison function. 13 | */ 14 | template 15 | void qsort(RangePtr elements, CompareFn && less_fn) { 16 | using std::size_t; 17 | using etl::swap; 18 | 19 | if (elements.count() <= 1) return; 20 | 21 | auto pivot_index = elements.count() / 2; 22 | 23 | // Move pivot to end for now. 24 | swap(elements[pivot_index], elements[elements.count() - 1]); 25 | pivot_index = elements.count() - 1; 26 | 27 | // 'partition' will hold the index in the array of the first element (other 28 | // than the pivot) that is greater than or equal to the pivot. 29 | size_t partition = 0; 30 | 31 | for (size_t i = 0; i < pivot_index; ++i) { 32 | if (less_fn(elements[i], elements[pivot_index])) { 33 | swap(elements[i], elements[partition++]); 34 | } 35 | } 36 | 37 | // Move pivot into final position. 38 | swap(elements[partition], elements[pivot_index]); 39 | 40 | qsort(elements.first(partition), less_fn); 41 | qsort(elements.tail_from(partition + 1), less_fn); 42 | } 43 | 44 | 45 | } // namespace data 46 | } // namespace etl 47 | 48 | #endif // _ETL_DATA_SORT_H_INCLUDED 49 | -------------------------------------------------------------------------------- /Main/etl/destroy.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_DESTROY_H_INCLUDED 2 | #define _ETL_DESTROY_H_INCLUDED 3 | 4 | namespace etl { 5 | 6 | /* 7 | * Invokes an object's destructor. This is sugar for the pattern 8 | * t.~T(); 9 | * 10 | * Note that the compiler does not realize the object's life has ended, so it's 11 | * easy to accidentally use a destroyed object. Be careful. 12 | */ 13 | template 14 | void destroy(T & object) { 15 | object.~T(); 16 | } 17 | 18 | } // namespace etl 19 | 20 | #endif // _ETL_DESTROY_H_INCLUDED 21 | -------------------------------------------------------------------------------- /Main/etl/doc/conventions.mkdn: -------------------------------------------------------------------------------- 1 | ETL Conventions 2 | =============== 3 | 4 | 5 | Use of the Preprocessor 6 | ----------------------- 7 | 8 | **All macros used in ETL shall be UPPER_CASE_WITH_UNDERSCORES.** Lower- and 9 | mixed-case identifiers are reserved for cases where they can be namespaced, and 10 | macros cannot be namespaced. 11 | 12 | To avoid conflicts with application code, preprocessor symbols defined in ETL 13 | header files should start with one of these two prefixes: 14 | 15 | - `ETL_` for macros intended for use by the application. 16 | - `_ETL_` for internal implementation macros. 17 | 18 | In certain cases macros are used to provide convenient syntax for the 19 | application (e.g. `CHECK`). These macros *may* omit the prefix, but *only* if 20 | the following rules are followed: 21 | 22 | 1. The macro must be defined in its own header file, so that applications can 23 | explicitly opt-in to the namespace pollution. 24 | 25 | 2. The macro must *never* be used in an ETL header file, which would 26 | cause it to indirectly appear in the application. 27 | 28 | As a compromise, define the actual macro using the `ETL_` prefix, and provide 29 | an adapter header that re-exports it using the unprefixed name. 30 | 31 | 32 | ### Include guards 33 | 34 | Include guards follow the same rules as other internal-use macros. They should 35 | include the full path to the file, starting at the base `etl` directory, and use 36 | a leading underscore and a trailing `_INCLUDED` marker. The final `#endif` must 37 | carry an explanatory comment repeating the include guard name. 38 | 39 | For example, a file named `etl/foo/bar/example.h` should be structured as 40 | follows: 41 | 42 | #ifndef _ETL_FOO_BAR_EXAMPLE_H_INCLUDED 43 | #define _ETL_FOO_BAR_EXAMPLE_H_INCLUDED 44 | 45 | // content goes here 46 | 47 | #endif // _ETL_FOO_BAR_EXAMPLE_H_INCLUDED 48 | 49 | 50 | Namespaces 51 | ---------- 52 | 53 | Exported symbols should be within the top-level `etl` namespace, except when 54 | this is not possible (due to e.g. compatibility with external conventions). 55 | 56 | Namespace nesting should match directory nesting. A type `Encoder` defined in 57 | a file at `etl/util/data/encoder.h` must live in an `etl::util::data` namespace. 58 | 59 | Avoid exporting symbols with C linkage. Where this can't be avoided, name the 60 | symbols following namespace convention: `etl_armv7m_reset_handler`. 61 | -------------------------------------------------------------------------------- /Main/etl/error/catch.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ERROR_CATCH_H_INCLUDED 2 | #define _ETL_ERROR_CATCH_H_INCLUDED 3 | 4 | #include "etl/error/flow.h" 5 | 6 | #define CATCH(expr) ETL_CATCH(expr) 7 | 8 | #endif // _ETL_ERROR_CATCH_H_INCLUDED 9 | -------------------------------------------------------------------------------- /Main/etl/error/check.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ERROR_CHECK_H_INCLUDED 2 | #define _ETL_ERROR_CHECK_H_INCLUDED 3 | 4 | #include "etl/error/flow.h" 5 | 6 | #define CHECK(expr) ETL_CHECK(expr) 7 | 8 | #endif // _ETL_ERROR_CHECK_H_INCLUDED 9 | -------------------------------------------------------------------------------- /Main/etl/error/flow.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ERROR_FLOW_H_INCLUDED 2 | #define _ETL_ERROR_FLOW_H_INCLUDED 3 | 4 | /* 5 | * These macros provide an alternative to exceptions for non-local flow 6 | * control when errors are encountered. 7 | * 8 | * A common C/C++ error handling idiom reads as follows: 9 | * 10 | * int e; 11 | * e = operation1(); 12 | * if (e != OK) return e; 13 | * e = operation2(); 14 | * if (e != OK) return e; 15 | * ... and so on 16 | * 17 | * (In C code, or C++ code that can't rely on RAII patterns, the 'return e' 18 | * may be replaced by 'goto label'.) 19 | * 20 | * This isn't a great pattern for several reasons: 21 | * - It encourages large-scoped variables, with their attendant perils. 22 | * - It's verbose. 23 | * - It's repetitive, in that most dangerous way where a single *incorrect* 24 | * repetition is both easy to miss and potentially fatal (as in the 'goto 25 | * fail' bug). 26 | * 27 | * The equivalent code written with the ETL error flow macros reads: 28 | * 29 | * ETL_CHECK(operation1()); 30 | * ETL_CHECK(operation2()); 31 | * 32 | * The macros generate code that includes a return statement. The reader can 33 | * concentrate on the straight-line non-error execution path, but is made 34 | * aware of the precise points where the function may terminate early (the 35 | * macro uses). 36 | * 37 | * If you really want to get the error into a variable, without affecting 38 | * control flow, there is ETL_CATCH. It's most useful with more complex 39 | * error types and is rare. 40 | * 41 | * Finally, there's ETL_IGNORE, which explicitly does not act on the success 42 | * or failure of an operation. 43 | */ 44 | 45 | #include "etl/error/strategy.h" 46 | 47 | #define ETL_FLOW_PRECONDITION(macro, expr) \ 48 | static_assert(::etl::error::Strategy::is_error_type, \ 49 | "Only types that participate in the ETL error handling " \ 50 | "system can be used with " #macro ". The result of this " \ 51 | "expression does not appear to participate: " \ 52 | #expr) \ 53 | 54 | #define ETL_CHECK(expr) \ 55 | ({ \ 56 | ETL_FLOW_PRECONDITION(CHECK, expr); \ 57 | \ 58 | decltype(expr) etl_flow_value(expr); \ 59 | if (::etl::error::Strategy::is_bad(etl_flow_value)) { \ 60 | return ::etl::error::Strategy \ 61 | ::move_error(etl_flow_value); \ 62 | } \ 63 | ::etl::error::Strategy::move_success(etl_flow_value); \ 64 | }) 65 | 66 | #define ETL_CATCH(expr) \ 67 | ({ \ 68 | ETL_FLOW_PRECONDITION(CATCH, expr); \ 69 | \ 70 | decltype(expr) etl_flow_value(expr); \ 71 | ::etl::error::Strategy::move_error(etl_flow_value); \ 72 | }) 73 | 74 | #define ETL_IGNORE(expr) \ 75 | ({ \ 76 | ETL_FLOW_PRECONDITION(IGNORE, expr); \ 77 | \ 78 | decltype(expr) etl_flow_value(expr); \ 79 | static_cast(etl_flow_value); \ 80 | }) 81 | 82 | #endif // _ETL_ERROR_FLOW_H_INCLUDED 83 | -------------------------------------------------------------------------------- /Main/etl/error/ignore.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ERROR_IGNORE_H_INCLUDED 2 | #define _ETL_ERROR_IGNORE_H_INCLUDED 3 | 4 | #include "etl/error/flow.h" 5 | 6 | #define IGNORE(expr) ETL_IGNORE(expr) 7 | 8 | #endif // _ETL_ERROR_IGNORE_H_INCLUDED 9 | -------------------------------------------------------------------------------- /Main/etl/error/result.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ERROR_RESULT_H_INCLUDED 2 | #define _ETL_ERROR_RESULT_H_INCLUDED 3 | 4 | #include "etl/assert.h" 5 | #include "etl/utility.h" 6 | 7 | #include "etl/error/strategy.h" 8 | 9 | namespace etl { 10 | namespace error { 11 | 12 | /* 13 | * Tag type used to signify an error result. 14 | */ 15 | struct Left {}; 16 | static constexpr Left left {}; 17 | 18 | /* 19 | * Tag type used to signify a success result. 20 | */ 21 | struct Right {}; 22 | static constexpr Right right {}; 23 | 24 | /* 25 | * Return value from operations that may fail; represents a return code with an 26 | * optional result value that is only constructed if the return code signifies 27 | * success. 28 | */ 29 | template 30 | class Result { 31 | public: 32 | using EStrategy = Strategy; 33 | 34 | static_assert(EStrategy::is_error_type, 35 | "Result must be used with participating error types"); 36 | 37 | Result() = delete; 38 | 39 | constexpr Result(E const & error) 40 | : _status{(ETL_ASSERT_CE(EStrategy::is_bad(error)), error)} {} 41 | 42 | constexpr Result(Left const &, E const & error) 43 | : _status{(ETL_ASSERT_CE(EStrategy::is_bad(error)), error)} {} 44 | 45 | template 46 | Result(Right const &, W && value) 47 | : _status{EStrategy::success_value}, 48 | _storage{etl::forward(value)} {} 49 | 50 | constexpr bool is_error() const { 51 | return EStrategy::is_bad(_status); 52 | } 53 | 54 | constexpr explicit operator bool() const { 55 | return !is_error(); 56 | } 57 | 58 | constexpr E get_status() const { 59 | return _status; 60 | } 61 | 62 | V & ref() { 63 | ETL_ASSERT(!is_error()); 64 | return _storage.object; 65 | } 66 | 67 | private: 68 | E _status; 69 | 70 | union Storage { 71 | struct {} dummy; 72 | V object; 73 | 74 | ETL_INLINE constexpr Storage() : dummy{} {} 75 | 76 | template 77 | ETL_INLINE Storage(W && value) : object{forward(value)} {} 78 | } _storage; 79 | }; 80 | 81 | template 82 | struct Strategy> { 83 | static constexpr bool is_error_type = true; 84 | 85 | static constexpr bool has_success_value = false; 86 | 87 | static bool is_bad(Result const & e) { 88 | return e.is_error(); 89 | } 90 | 91 | static E move_error(Result & e) { 92 | return etl::move(e.get_status()); 93 | } 94 | 95 | static V move_success(Result & e) { 96 | return etl::move(e.ref()); 97 | } 98 | }; 99 | 100 | } // namespace error 101 | } // namespace etl 102 | 103 | #endif // _ETL_ERROR_RESULT_H_INCLUDED 104 | -------------------------------------------------------------------------------- /Main/etl/error/strategy.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_ERROR_STRATEGY_H_INCLUDED 2 | #define _ETL_ERROR_STRATEGY_H_INCLUDED 3 | 4 | namespace etl { 5 | namespace error { 6 | 7 | /* 8 | * Describes how a type participates in the error handling system. 9 | * 10 | * By default, types don't participate. Types can be opted in by specializing 11 | * Strategy. This allows a type to be used with CHECK and the other error 12 | * handling facilities. 13 | * 14 | * Error types are classified into two groups: *basic errors* carry only an 15 | * error/success indicator, while *wrapped errors* carry an arbitrary value 16 | * on success. 17 | */ 18 | template 19 | struct Strategy { 20 | static constexpr bool is_error_type = false; 21 | }; 22 | 23 | /* 24 | * Convenience implementation for the common case where an error is an 25 | * enumeration type with a "success value". 26 | */ 27 | template 28 | struct TraditionalEnumStrategy { 29 | static constexpr bool is_error_type = true; 30 | static constexpr bool has_success_value = true; 31 | static constexpr E success_value = success; 32 | 33 | static constexpr bool is_bad(E error) { 34 | return error != success_value; 35 | } 36 | 37 | static constexpr E move_error(E error) { return error; } 38 | 39 | /* 40 | * This indicates that this type has no "success" component, causing 41 | * CHECK and friends to become void and preventing their use in expression 42 | * contexts. 43 | */ 44 | static void move_success(E) {} 45 | }; 46 | 47 | } // namespace error 48 | } // namespace etl 49 | 50 | #endif // _ETL_ERROR_STRATEGY_H_INCLUDED 51 | -------------------------------------------------------------------------------- /Main/etl/implicit.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_IMPLICIT_H_INCLUDED 2 | #define _ETL_IMPLICIT_H_INCLUDED 3 | 4 | /* 5 | * This do-nothing macro serves as a reminder that an operation is *not* 6 | * explicit. It exists because its author wishes C++ required things to 7 | * be explicitly marked implicit. 8 | */ 9 | #define ETL_IMPLICIT /* empty */ 10 | 11 | #endif // _ETL_IMPLICIT_H_INCLUDED 12 | -------------------------------------------------------------------------------- /Main/etl/invoke.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_INVOKE_H_INCLUDED 2 | #define _ETL_INVOKE_H_INCLUDED 3 | 4 | #include "etl/type_constant.h" 5 | 6 | namespace etl { 7 | 8 | /* 9 | * Converting between C++03-style member type metafunctions and C++11-style 10 | * alias metafunctions. 11 | * 12 | * In general, the syntax "typename T::type" or "typename T::Type" can be 13 | * replaced by "etl::Invoke", regardless of the complexity of T. 14 | * 15 | * If both 'type' and 'Type' members are present, the uppercase one will be 16 | * preferred. 17 | */ 18 | 19 | // Helper class for distinguishing std from etl conventions 20 | template 21 | struct HasUppercaseTypeMember { 22 | private: 23 | /* 24 | * Idiom alert. 25 | * 26 | * We want to determine if T has a member type named Type. If we try to 27 | * reference it and it doesn't exist, we'll take a compiler error. 28 | * 29 | * But if we try to reference it in a template context and it's *ambiguous*, 30 | * we get a pass. 31 | * 32 | * So, we introduce ambiguity by extending T and adding a Type member type. 33 | * 34 | * If T had a Type member already, the "No" overload of test below -- normally 35 | * treated as more specific and a better overload match -- will be ambiguous 36 | * and the compiler will disable it. 37 | * 38 | * If T has no Type member, we've added one in Derived, so the "No" overload 39 | * will be unambiguously preferred. 40 | * 41 | * Here's hoping that some future version of C++ adds some kind of "syntactic 42 | * validity predicates" that can test this more cleanly, such as the 43 | * 'requires' blocks proposed in Concepts Lite. 44 | */ 45 | using Yes = char[2]; 46 | using No = char[1]; 47 | 48 | struct Fallback { struct Type {}; }; 49 | struct Derived : T, Fallback {}; 50 | 51 | template 52 | static No & test(typename U::Type *); 53 | 54 | template 55 | static Yes & test(U *); 56 | 57 | public: 58 | static constexpr bool value = sizeof(test(nullptr)) == sizeof(Yes); 59 | }; 60 | 61 | template ::value> 62 | struct InvokeHelper : public TypeConstant {}; 63 | 64 | template 65 | struct InvokeHelper : public TypeConstant {}; 66 | 67 | template 68 | using Invoke = typename InvokeHelper::Type; 69 | 70 | } // namespace etl 71 | 72 | #endif // _ETL_INVOKE_H_INCLUDED 73 | -------------------------------------------------------------------------------- /Main/etl/prediction.h: -------------------------------------------------------------------------------- 1 | #ifndef ETL_PREDICTION_H 2 | #define ETL_PREDICTION_H 3 | 4 | #define ETL_LIKELY(__c) __builtin_expect(!!(__c), 1) 5 | #define ETL_UNLIKELY(__c) __builtin_expect(!!(__c), 0) 6 | 7 | #endif // ETL_PREDICTION_H 8 | -------------------------------------------------------------------------------- /Main/etl/quote.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_QUOTE_H_INCLUDED 2 | #define _ETL_QUOTE_H_INCLUDED 3 | 4 | /* 5 | * The C preprocessor won't rewrite macros inside string literals. This is 6 | * particularly annoying for dynamic #includes. The ETL_QUOTE macro rewrites 7 | * macros inside its argument and turns the result into a string literal. 8 | */ 9 | #define _ETL_QUOTE(x) #x 10 | #define ETL_QUOTE(x) _ETL_QUOTE(x) 11 | 12 | #endif // _ETL_QUOTE_H_INCLUDED 13 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/adv_timer.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_ADV_TIMER_H_INCLUDED 2 | #define _ETL_STM32F4XX_ADV_TIMER_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | 6 | namespace etl { 7 | namespace stm32f4xx { 8 | 9 | struct AdvTimer { 10 | enum class OcMode { 11 | frozen = 0b000, 12 | ch1_active_on_match = 0b001, 13 | ch1_inactive_on_match = 0b010, 14 | toggle = 0b011, 15 | force_inactive = 0b100, 16 | force_active = 0b101, 17 | pwm1 = 0b110, 18 | pwm2 = 0b111, 19 | }; 20 | 21 | #define ETL_BFF_DEFINITION_FILE "etl/stm32f4xx/adv_timer.reg" 22 | #include "etl/biffield/generate.h" 23 | #undef ETL_BFF_DEFINITION_FILE 24 | }; 25 | 26 | extern AdvTimer tim1; 27 | extern AdvTimer tim8; 28 | 29 | } // namespace stm32f4xx 30 | } // namespace etl 31 | 32 | #endif // _ETL_STM32F4XX_ADV_TIMER_H_INCLUDED 33 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/ahb.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_AHB_H_INCLUDED 2 | #define _ETL_STM32F4XX_AHB_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | 6 | namespace etl { 7 | namespace stm32f4xx { 8 | 9 | /* 10 | * Names for AHB peripherals, so that we can reset/enable them generically. 11 | * The enum values *happen* to contain some useful information, but you should 12 | * not rely on this unless you're the RCC driver -- it may change. 13 | */ 14 | enum class AhbPeripheral : Word { 15 | /* 16 | * AHB1 peripherals 17 | */ 18 | #define ETL_NONE (0xFF) 19 | #define ETL_STM32F4XX_AHB_PERIPH(name, rst, en) \ 20 | name = (0 << 16) | (rst << 8) | (en << 0), 21 | #include "etl/stm32f4xx/ahb1_peripherals.def" 22 | #undef ETL_STM32F4XX_AHB_PERIPH 23 | #undef ETL_NONE 24 | }; 25 | 26 | inline unsigned get_bus_index(AhbPeripheral p) { 27 | return static_cast(static_cast(p) >> 16); 28 | } 29 | 30 | inline unsigned get_reset_index(AhbPeripheral p) { 31 | return static_cast(static_cast(p) >> 8); 32 | } 33 | 34 | inline unsigned get_enable_index(AhbPeripheral p) { 35 | return static_cast(p); 36 | } 37 | 38 | } // namespace stm32f4xx 39 | } // namespace etl 40 | 41 | #endif // _ETL_STM32F4XX_AHB_H_INCLUDED 42 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/ahb1_peripherals.def: -------------------------------------------------------------------------------- 1 | // vim:syntax=cpp: 2 | // This is an x-macro file giving the STM32F4xx AHB peripheral configuration. 3 | // 4 | // The columns are, from left to right, 5 | // - Peripheral name as given in the memory map table of the reference manual. 6 | // - Reset bit assignment in the AHB1RSTR. 7 | // - Clock enable bit assignment in the AHB1(LP)ENR. 8 | // 9 | // In the latter two cases, the special value NONE means that the peripheral 10 | // doesn't have a simple enable/reset line. Some peripherals with NONE lack 11 | // the functionality entirely, while some are reset/enabled through other 12 | // means. 13 | 14 | ETL_STM32F4XX_AHB_PERIPH(gpioa, 0, 0) 15 | ETL_STM32F4XX_AHB_PERIPH(gpiob, 1, 1) 16 | ETL_STM32F4XX_AHB_PERIPH(gpioc, 2, 2) 17 | ETL_STM32F4XX_AHB_PERIPH(gpiod, 3, 3) 18 | ETL_STM32F4XX_AHB_PERIPH(gpioe, 4, 4) 19 | ETL_STM32F4XX_AHB_PERIPH(gpiof, 5, 5) 20 | ETL_STM32F4XX_AHB_PERIPH(gpiog, 6, 6) 21 | ETL_STM32F4XX_AHB_PERIPH(gpioh, 7, 7) 22 | ETL_STM32F4XX_AHB_PERIPH(gpioi, 8, 8) 23 | ETL_STM32F4XX_AHB_PERIPH(gpioj, 9, 9) 24 | ETL_STM32F4XX_AHB_PERIPH(gpiok, 10, 10) 25 | ETL_STM32F4XX_AHB_PERIPH(crc, 12, 12) 26 | ETL_STM32F4XX_AHB_PERIPH(rcc, ETL_NONE, ETL_NONE) 27 | ETL_STM32F4XX_AHB_PERIPH(flash, ETL_NONE, ETL_NONE) 28 | ETL_STM32F4XX_AHB_PERIPH(bkpsram, ETL_NONE, 18) 29 | ETL_STM32F4XX_AHB_PERIPH(dma1, 21, 21) 30 | ETL_STM32F4XX_AHB_PERIPH(dma2, 22, 22) 31 | ETL_STM32F4XX_AHB_PERIPH(ethernet, 25, ETL_NONE) 32 | ETL_STM32F4XX_AHB_PERIPH(dma2d, 23, 23) 33 | ETL_STM32F4XX_AHB_PERIPH(usb_otg_hs, 29, ETL_NONE) 34 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/apb.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_APB_H_INCLUDED 2 | #define _ETL_STM32F4XX_APB_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | 6 | namespace etl { 7 | namespace stm32f4xx { 8 | 9 | enum class ApbPeripheral : HalfWord { 10 | /* 11 | * APB1 peripherals 12 | */ 13 | #define ETL_STM32F4XX_APB_PERIPH(slot, name) name = (0 << 8) | slot, 14 | #define ETL_STM32F4XX_APB_RESERVED(slot) /* nothing */ 15 | #include "etl/stm32f4xx/apb1_peripherals.def" 16 | #undef ETL_STM32F4XX_APB_RESERVED 17 | #undef ETL_STM32F4XX_APB_PERIPH 18 | 19 | /* 20 | * APB2 peripherals 21 | */ 22 | #define ETL_STM32F4XX_APB_PERIPH(slot, name) name = (1 << 8) | slot, 23 | #define ETL_STM32F4XX_APB_RESERVED(slot) /* nothing */ 24 | #include "etl/stm32f4xx/apb2_peripherals.def" 25 | #undef ETL_STM32F4XX_APB_RESERVED 26 | #undef ETL_STM32F4XX_APB_PERIPH 27 | }; 28 | 29 | inline unsigned get_bus_index(ApbPeripheral p) { 30 | return (static_cast(p) >> 8) & 0xFF; 31 | } 32 | 33 | inline unsigned get_slot_index(ApbPeripheral p) { 34 | return static_cast(p) & 0xFF; 35 | } 36 | 37 | } // namespace stm32f4xx 38 | } // namespace etl 39 | 40 | #endif // _ETL_STM32F4XX_APB_H_INCLUDED 41 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/apb1_peripherals.def: -------------------------------------------------------------------------------- 1 | /* APB1 */ 2 | ETL_STM32F4XX_APB_PERIPH(0, tim2) 3 | ETL_STM32F4XX_APB_PERIPH(1, tim3) 4 | ETL_STM32F4XX_APB_PERIPH(2, tim4) 5 | ETL_STM32F4XX_APB_PERIPH(3, tim5) 6 | ETL_STM32F4XX_APB_PERIPH(4, tim6) 7 | ETL_STM32F4XX_APB_PERIPH(5, tim7) 8 | ETL_STM32F4XX_APB_PERIPH(6, tim12) 9 | ETL_STM32F4XX_APB_PERIPH(7, tim13) 10 | ETL_STM32F4XX_APB_PERIPH(8, tim14) 11 | ETL_STM32F4XX_APB_RESERVED(9) 12 | ETL_STM32F4XX_APB_PERIPH(10, rtc) 13 | ETL_STM32F4XX_APB_PERIPH(11, wwdg) 14 | ETL_STM32F4XX_APB_PERIPH(12, iwdg) 15 | ETL_STM32F4XX_APB_PERIPH(13, i2s2ext) 16 | ETL_STM32F4XX_APB_PERIPH(14, spi2_i2s2) 17 | ETL_STM32F4XX_APB_PERIPH(15, spi3_i2s3) 18 | ETL_STM32F4XX_APB_PERIPH(16, i2s3ext) 19 | ETL_STM32F4XX_APB_PERIPH(17, usart2) 20 | ETL_STM32F4XX_APB_PERIPH(18, usart3) 21 | ETL_STM32F4XX_APB_PERIPH(19, uart4) 22 | ETL_STM32F4XX_APB_PERIPH(20, uart5) 23 | ETL_STM32F4XX_APB_PERIPH(21, i2c1) 24 | ETL_STM32F4XX_APB_PERIPH(22, i2c2) 25 | ETL_STM32F4XX_APB_PERIPH(23, i2c3) 26 | ETL_STM32F4XX_APB_RESERVED(24) 27 | ETL_STM32F4XX_APB_PERIPH(25, can1) 28 | ETL_STM32F4XX_APB_PERIPH(26, can2) 29 | ETL_STM32F4XX_APB_RESERVED(27) 30 | ETL_STM32F4XX_APB_PERIPH(28, pwr) 31 | ETL_STM32F4XX_APB_PERIPH(29, dac) 32 | ETL_STM32F4XX_APB_PERIPH(30, uart7) 33 | ETL_STM32F4XX_APB_PERIPH(31, uart8) 34 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/apb2_peripherals.def: -------------------------------------------------------------------------------- 1 | /* APB2 */ 2 | ETL_STM32F4XX_APB_PERIPH(0, tim1) 3 | ETL_STM32F4XX_APB_PERIPH(1, tim8) 4 | ETL_STM32F4XX_APB_RESERVED(2) 5 | ETL_STM32F4XX_APB_RESERVED(3) 6 | ETL_STM32F4XX_APB_PERIPH(4, usart1) 7 | ETL_STM32F4XX_APB_PERIPH(5, usart6) 8 | ETL_STM32F4XX_APB_RESERVED(6) 9 | ETL_STM32F4XX_APB_RESERVED(7) 10 | ETL_STM32F4XX_APB_PERIPH(8, adc1_2_3) 11 | ETL_STM32F4XX_APB_RESERVED(9) 12 | ETL_STM32F4XX_APB_RESERVED(10) 13 | ETL_STM32F4XX_APB_PERIPH(11, sdio) 14 | ETL_STM32F4XX_APB_PERIPH(12, spi1) 15 | ETL_STM32F4XX_APB_PERIPH(13, spi4) 16 | ETL_STM32F4XX_APB_PERIPH(14, syscfg) 17 | ETL_STM32F4XX_APB_PERIPH(15, exti) 18 | ETL_STM32F4XX_APB_PERIPH(16, tim9) 19 | ETL_STM32F4XX_APB_PERIPH(17, tim10) 20 | ETL_STM32F4XX_APB_PERIPH(18, tim11) 21 | ETL_STM32F4XX_APB_RESERVED(19) 22 | ETL_STM32F4XX_APB_PERIPH(20, spi5) 23 | ETL_STM32F4XX_APB_PERIPH(21, spi6) 24 | ETL_STM32F4XX_APB_PERIPH(22, sai1) 25 | ETL_STM32F4XX_APB_RESERVED(23) 26 | ETL_STM32F4XX_APB_RESERVED(24) 27 | ETL_STM32F4XX_APB_RESERVED(25) 28 | ETL_STM32F4XX_APB_PERIPH(26, lcd_tft) 29 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/basic_timer.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_BASIC_TIMER_H_INCLUDED 2 | #define _ETL_STM32F4XX_BASIC_TIMER_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | 6 | namespace etl { 7 | namespace stm32f4xx { 8 | 9 | struct BasicTimer { 10 | #define ETL_BFF_DEFINITION_FILE "etl/stm32f4xx/basic_timer.reg" 11 | #include "etl/biffield/generate.h" 12 | #undef ETL_BFF_DEFINITION_FILE 13 | }; 14 | 15 | extern BasicTimer tim6; 16 | extern BasicTimer tim7; 17 | 18 | } // namespace stm32f4xx 19 | } // namespace etl 20 | 21 | #endif // _ETL_STM32F4XX_BASIC_TIMER_H_INCLUDED 22 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/basic_timer.reg: -------------------------------------------------------------------------------- 1 | ETL_BFF_REG_RW(Word, cr1, 2 | ETL_BFF_FIELD( 7: 7, bool, arpe) 3 | ETL_BFF_FIELD( 3: 3, bool, opm) 4 | ETL_BFF_FIELD( 2: 2, bool, urs) 5 | ETL_BFF_FIELD( 1: 1, bool, udis) 6 | ETL_BFF_FIELD( 0: 0, bool, cen) 7 | ) 8 | 9 | ETL_BFF_REG_RW(Word, cr2, 10 | ) 11 | 12 | ETL_BFF_REG_RESERVED(Word, 8, 1) 13 | 14 | ETL_BFF_REG_RW(Word, dier, 15 | ETL_BFF_FIELD( 8: 8, bool, ude) 16 | ETL_BFF_FIELD( 0: 0, bool, uie) 17 | ) 18 | 19 | ETL_BFF_REG_RW(Word, sr, 20 | ETL_BFF_FIELD( 0: 0, bool, uif) 21 | ) 22 | 23 | ETL_BFF_REG_RW(Word, egr, 24 | ETL_BFF_FIELD( 0: 0, bool, ug) 25 | ) 26 | 27 | ETL_BFF_REG_RESERVED(Word, 18, 3) 28 | 29 | ETL_BFF_REG_RW(Word, cnt, 30 | ) 31 | 32 | ETL_BFF_REG_RW(Word, psc, 33 | ) 34 | 35 | ETL_BFF_REG_RW(Word, arr, 36 | ) 37 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/dac.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_DAC_H_INCLUDED 2 | #define _ETL_STM32F4XX_DAC_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | 6 | namespace etl { 7 | namespace stm32f4xx { 8 | 9 | struct Dac { 10 | enum class LfsrMask : unsigned { 11 | unmask_1_lsb = 0b0000, 12 | unmask_2_lsbs = 0b0001, 13 | unmask_3_lsbs = 0b0010, 14 | unmask_4_lsbs = 0b0011, 15 | unmask_5_lsbs = 0b0100, 16 | unmask_6_lsbs = 0b0101, 17 | unmask_7_lsbs = 0b0110, 18 | unmask_8_lsbs = 0b0111, 19 | unmask_9_lsbs = 0b1000, 20 | unmask_10_lsbs = 0b1001, 21 | unmask_11_lsbs = 0b1010, 22 | unmask_12_lsbs = 0b1011, 23 | }; 24 | 25 | enum class TriangleAmplitude : unsigned { 26 | amplitude_1 = 0b0000, 27 | amplitude_3 = 0b0001, 28 | amplitude_7 = 0b0010, 29 | amplitude_15 = 0b0011, 30 | amplitude_31 = 0b0100, 31 | amplitude_63 = 0b0101, 32 | amplitude_127 = 0b0110, 33 | amplitude_255 = 0b0111, 34 | amplitude_511 = 0b1000, 35 | amplitude_1023 = 0b1001, 36 | amplitude_2047 = 0b1010, 37 | amplitude_4095 = 0b1011, 38 | }; 39 | 40 | enum class Waveform : unsigned { 41 | disabled = 0b00, 42 | noise = 0b01, 43 | triangle = 0b10, 44 | }; 45 | 46 | enum class Trigger : unsigned { 47 | tim6_trgo = 0b000, 48 | tim8_trgo = 0b001, 49 | tim7_trgo = 0b010, 50 | tim5_trgo = 0b011, 51 | tim2_trgo = 0b100, 52 | tim4_trgo = 0b101, 53 | exti9 = 0b110, 54 | swtrig = 0b111, 55 | }; 56 | 57 | #define ETL_BFF_DEFINITION_FILE "etl/stm32f4xx/dac.reg" 58 | #include "etl/biffield/generate.h" 59 | #undef ETL_BFF_DEFINITION_FILE 60 | }; 61 | 62 | extern Dac dac; 63 | 64 | } // namespace stm32f4xx 65 | } // namespace etl 66 | 67 | #endif // _ETL_STM32F4XX_DAC_H_INCLUDED 68 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/dac.reg: -------------------------------------------------------------------------------- 1 | ETL_BFF_REG_RW(Word, cr, 2 | ETL_BFF_FIELD (29:29, bool, dmaudrie2) 3 | ETL_BFF_FIELD (28:28, bool, dmaen2) 4 | 5 | ETL_BFF_FIELD (27:24, LfsrMask, mamp2_lfsr) 6 | ETL_BFF_FIELD (27:24, TriangleAmplitude, mamp2_tri) 7 | ETL_BFF_FIELD (23:22, Waveform, wave2) 8 | ETL_BFF_FIELD (21:19, Trigger, tsel2) 9 | ETL_BFF_FIELD (18:18, bool, ten2) 10 | ETL_BFF_FIELD (17:17, bool, boff2) 11 | ETL_BFF_FIELD (16:16, bool, en2) 12 | 13 | ETL_BFF_FIELD (13:13, bool, dmaudrie1) 14 | ETL_BFF_FIELD (12:12, bool, dmaen1) 15 | ETL_BFF_FIELD (11: 8, LfsrMask, mamp1_lfsr) 16 | ETL_BFF_FIELD (11: 8, TriangleAmplitude, mamp1_tri) 17 | ETL_BFF_FIELD ( 7: 6, Waveform, wave1) 18 | ETL_BFF_FIELD ( 5: 3, Trigger, tsel1) 19 | ETL_BFF_FIELD ( 2: 2, bool, ten1) 20 | ETL_BFF_FIELD ( 1: 1, bool, boff1) 21 | ETL_BFF_FIELD ( 0: 0, bool, en1) 22 | ) 23 | 24 | ETL_BFF_REG_RW(Word, swtrigr, 25 | ETL_BFF_FIELD ( 1: 1, bool, swtrig2) 26 | ETL_BFF_FIELD ( 0: 0, bool, swtrig1) 27 | ) 28 | 29 | ETL_BFF_REG_RW(Word, dhr12r1, 30 | ETL_BFF_FIELD (11: 0, unsigned, dacc1dhr) 31 | ) 32 | ETL_BFF_REG_RW(Word, dhr12l1, 33 | ETL_BFF_FIELD (15: 4, unsigned, dacc1dhr) 34 | ) 35 | ETL_BFF_REG_RW(Word, dhr8r1, 36 | ETL_BFF_FIELD ( 7: 0, unsigned, dacc1dhr) 37 | ) 38 | 39 | ETL_BFF_REG_RW(Word, dhr12r2, 40 | ETL_BFF_FIELD (11: 0, unsigned, dacc2dhr) 41 | ) 42 | ETL_BFF_REG_RW(Word, dhr12l2, 43 | ETL_BFF_FIELD (15: 4, unsigned, dacc2dhr) 44 | ) 45 | ETL_BFF_REG_RW(Word, dhr8r2, 46 | ETL_BFF_FIELD ( 7: 0, unsigned, dacc2dhr) 47 | ) 48 | 49 | ETL_BFF_REG_RW(Word, dhr12rd, 50 | ETL_BFF_FIELD (27:16, unsigned, dacc2dhr) 51 | ETL_BFF_FIELD (11: 0, unsigned, dacc1dhr) 52 | ) 53 | ETL_BFF_REG_RW(Word, dhr12ld, 54 | ETL_BFF_FIELD (31:20, unsigned, dacc2dhr) 55 | ETL_BFF_FIELD (15: 4, unsigned, dacc1dhr) 56 | ) 57 | ETL_BFF_REG_RW(Word, dhr8rd, 58 | ETL_BFF_FIELD (15: 8, unsigned, dacc2dhr) 59 | ETL_BFF_FIELD ( 7: 0, unsigned, dacc1dhr) 60 | ) 61 | 62 | ETL_BFF_REG_RO(Word, dor1, 63 | ETL_BFF_FIELD (11: 0, unsigned, dacc1dor) 64 | ) 65 | ETL_BFF_REG_RO(Word, dor2, 66 | ETL_BFF_FIELD (11: 0, unsigned, dacc2dor) 67 | ) 68 | 69 | ETL_BFF_REG_RW(Word, sr, 70 | ETL_BFF_FIELD (29:29, unsigned, dmaudr2) 71 | ETL_BFF_FIELD (13:13, unsigned, dmaudr1) 72 | ) 73 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/dbg.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_DBG_H_INCLUDED 2 | #define _ETL_STM32F4XX_DBG_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | 6 | namespace etl { 7 | namespace stm32f4xx { 8 | 9 | struct Dbg { 10 | #define ETL_BFF_DEFINITION_FILE "etl/stm32f4xx/dbg.reg" 11 | #include "etl/biffield/generate.h" 12 | #undef ETL_BFF_DEFINITION_FILE 13 | }; 14 | 15 | extern Dbg dbg; 16 | 17 | } // namespace stm32f4xx 18 | } // namespace etl 19 | 20 | #endif // _ETL_STM32F4XX_DBG_H_INCLUDED 21 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/dbg.reg: -------------------------------------------------------------------------------- 1 | ETL_BFF_REG_RW(Word, dbgmcu_idcode, 2 | ETL_BFF_FIELD(31:16, unsigned, rev_id) 3 | ETL_BFF_FIELD(11: 0, unsigned, dev_id) 4 | ) 5 | ETL_BFF_REG_RW(Word, dbgmcu_cr, ) 6 | ETL_BFF_REG_RW(Word, dbgmcu_apb1_fz, 7 | ETL_BFF_FIELD(26:26, bool, dbg_can2_stop) 8 | ETL_BFF_FIELD(25:25, bool, dbg_can1_stop) 9 | ETL_BFF_FIELD(23:23, bool, dbg_i2c3_smbus_timeout) 10 | ETL_BFF_FIELD(22:22, bool, dbg_i2c2_smbus_timeout) 11 | ETL_BFF_FIELD(21:21, bool, dbg_i2c1_smbus_timeout) 12 | ETL_BFF_FIELD(12:12, bool, dbg_iwdg_stop) 13 | ETL_BFF_FIELD(11:11, bool, dbg_wwdg_stop) 14 | ETL_BFF_FIELD(10:10, bool, dbg_rtc_stop) 15 | ETL_BFF_FIELD( 8: 8, bool, dbg_tim14_stop) 16 | ETL_BFF_FIELD( 7: 7, bool, dbg_tim13_stop) 17 | ETL_BFF_FIELD( 6: 6, bool, dbg_tim12_stop) 18 | ETL_BFF_FIELD( 5: 5, bool, dbg_tim7_stop) 19 | ETL_BFF_FIELD( 4: 4, bool, dbg_tim6_stop) 20 | ETL_BFF_FIELD( 3: 3, bool, dbg_tim5_stop) 21 | ETL_BFF_FIELD( 2: 2, bool, dbg_tim4_stop) 22 | ETL_BFF_FIELD( 1: 1, bool, dbg_tim3_stop) 23 | ETL_BFF_FIELD( 0: 0, bool, dbg_tim2_stop) 24 | ) 25 | 26 | ETL_BFF_REG_RW(Word, dbgmcu_apb2_fz, 27 | ETL_BFF_FIELD(18:18, bool, dbg_tim11_stop) 28 | ETL_BFF_FIELD(17:17, bool, dbg_tim10_stop) 29 | ETL_BFF_FIELD(16:16, bool, dbg_tim9_stop) 30 | ETL_BFF_FIELD( 1: 1, bool, dbg_tim8_stop) 31 | ETL_BFF_FIELD( 0: 0, bool, dbg_tim1_stop) 32 | ) 33 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/dma.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_DMA_H_INCLUDED 2 | #define _ETL_STM32F4XX_DMA_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | 6 | namespace etl { 7 | namespace stm32f4xx { 8 | 9 | struct Dma { 10 | struct Stream { 11 | enum class BurstSize { 12 | single = 0b00, 13 | incr_4_beat = 0b01, 14 | incr_8_beat = 0b10, 15 | incr_16_beat = 0b11, 16 | }; 17 | 18 | enum class TransferSize { 19 | byte = 0b00, 20 | half_word = 0b01, 21 | word = 0b10, 22 | }; 23 | 24 | #define ETL_BFF_DEFINITION_FILE "etl/stm32f4xx/dma_stream.reg" 25 | #include "etl/biffield/generate.h" 26 | #undef ETL_BFF_DEFINITION_FILE 27 | }; 28 | 29 | #define ETL_BFF_DEFINITION_FILE "etl/stm32f4xx/dma.reg" 30 | #include "etl/biffield/generate.h" 31 | #undef ETL_BFF_DEFINITION_FILE 32 | 33 | Stream stream0; 34 | Stream stream1; 35 | Stream stream2; 36 | Stream stream3; 37 | Stream stream4; 38 | Stream stream5; 39 | Stream stream6; 40 | Stream stream7; 41 | }; 42 | 43 | extern Dma dma1; 44 | extern Dma dma2; 45 | 46 | } // namespace stm32f4xx 47 | } // namespace etl 48 | 49 | #endif // _ETL_STM32F4XX_DMA_H_INCLUDED 50 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/dma.reg: -------------------------------------------------------------------------------- 1 | ETL_BFF_REG_RW(Word, lisr, 2 | ETL_BFF_FIELD(27:27, bool, tcif3) 3 | ETL_BFF_FIELD(26:26, bool, htif3) 4 | ETL_BFF_FIELD(25:25, bool, teif3) 5 | ETL_BFF_FIELD(24:24, bool, dmeif3) 6 | ETL_BFF_FIELD(22:22, bool, feif3) 7 | 8 | ETL_BFF_FIELD(21:21, bool, tcif2) 9 | ETL_BFF_FIELD(20:20, bool, htif2) 10 | ETL_BFF_FIELD(19:19, bool, teif2) 11 | ETL_BFF_FIELD(18:18, bool, dmeif2) 12 | ETL_BFF_FIELD(16:16, bool, feif2) 13 | 14 | ETL_BFF_FIELD(11:11, bool, tcif1) 15 | ETL_BFF_FIELD(10:10, bool, htif1) 16 | ETL_BFF_FIELD( 9: 9, bool, teif1) 17 | ETL_BFF_FIELD( 8: 8, bool, dmeif1) 18 | ETL_BFF_FIELD( 6: 6, bool, feif1) 19 | 20 | ETL_BFF_FIELD( 5: 5, bool, tcif0) 21 | ETL_BFF_FIELD( 4: 4, bool, htif0) 22 | ETL_BFF_FIELD( 3: 3, bool, teif0) 23 | ETL_BFF_FIELD( 2: 2, bool, dmeif0) 24 | ETL_BFF_FIELD( 0: 0, bool, feif0) 25 | ) 26 | ETL_BFF_REG_RW(Word, hisr, 27 | ETL_BFF_FIELD(27:27, bool, tcif7) 28 | ETL_BFF_FIELD(26:26, bool, htif7) 29 | ETL_BFF_FIELD(25:25, bool, teif7) 30 | ETL_BFF_FIELD(24:24, bool, dmeif7) 31 | ETL_BFF_FIELD(22:22, bool, feif7) 32 | 33 | ETL_BFF_FIELD(21:21, bool, tcif6) 34 | ETL_BFF_FIELD(20:20, bool, htif6) 35 | ETL_BFF_FIELD(19:19, bool, teif6) 36 | ETL_BFF_FIELD(18:18, bool, dmeif6) 37 | ETL_BFF_FIELD(16:16, bool, feif6) 38 | 39 | ETL_BFF_FIELD(11:11, bool, tcif5) 40 | ETL_BFF_FIELD(10:10, bool, htif5) 41 | ETL_BFF_FIELD( 9: 9, bool, teif5) 42 | ETL_BFF_FIELD( 8: 8, bool, dmeif5) 43 | ETL_BFF_FIELD( 6: 6, bool, feif5) 44 | 45 | ETL_BFF_FIELD( 5: 5, bool, tcif4) 46 | ETL_BFF_FIELD( 4: 4, bool, htif4) 47 | ETL_BFF_FIELD( 3: 3, bool, teif4) 48 | ETL_BFF_FIELD( 2: 2, bool, dmeif4) 49 | ETL_BFF_FIELD( 0: 0, bool, feif4) 50 | ) 51 | ETL_BFF_REG_RW(Word, lifcr, 52 | ETL_BFF_FIELD(27:27, bool, ctcif3) 53 | ETL_BFF_FIELD(26:26, bool, chtif3) 54 | ETL_BFF_FIELD(25:25, bool, cteif3) 55 | ETL_BFF_FIELD(24:24, bool, cdmeif3) 56 | ETL_BFF_FIELD(22:22, bool, cfeif3) 57 | 58 | ETL_BFF_FIELD(21:21, bool, ctcif2) 59 | ETL_BFF_FIELD(20:20, bool, chtif2) 60 | ETL_BFF_FIELD(19:19, bool, cteif2) 61 | ETL_BFF_FIELD(18:18, bool, cdmeif2) 62 | ETL_BFF_FIELD(16:16, bool, cfeif2) 63 | 64 | ETL_BFF_FIELD(11:11, bool, ctcif1) 65 | ETL_BFF_FIELD(10:10, bool, chtif1) 66 | ETL_BFF_FIELD( 9: 9, bool, cteif1) 67 | ETL_BFF_FIELD( 8: 8, bool, cdmeif1) 68 | ETL_BFF_FIELD( 6: 6, bool, cfeif1) 69 | 70 | ETL_BFF_FIELD( 5: 5, bool, ctcif0) 71 | ETL_BFF_FIELD( 4: 4, bool, chtif0) 72 | ETL_BFF_FIELD( 3: 3, bool, cteif0) 73 | ETL_BFF_FIELD( 2: 2, bool, cdmeif0) 74 | ETL_BFF_FIELD( 0: 0, bool, cfeif0) 75 | ) 76 | ETL_BFF_REG_RW(Word, hifcr, 77 | ETL_BFF_FIELD(27:27, bool, ctcif7) 78 | ETL_BFF_FIELD(26:26, bool, chtif7) 79 | ETL_BFF_FIELD(25:25, bool, cteif7) 80 | ETL_BFF_FIELD(24:24, bool, cdmeif7) 81 | ETL_BFF_FIELD(22:22, bool, cfeif7) 82 | 83 | ETL_BFF_FIELD(21:21, bool, ctcif6) 84 | ETL_BFF_FIELD(20:20, bool, chtif6) 85 | ETL_BFF_FIELD(19:19, bool, cteif6) 86 | ETL_BFF_FIELD(18:18, bool, cdmeif6) 87 | ETL_BFF_FIELD(16:16, bool, cfeif6) 88 | 89 | ETL_BFF_FIELD(11:11, bool, ctcif5) 90 | ETL_BFF_FIELD(10:10, bool, chtif5) 91 | ETL_BFF_FIELD( 9: 9, bool, cteif5) 92 | ETL_BFF_FIELD( 8: 8, bool, cdmeif5) 93 | ETL_BFF_FIELD( 6: 6, bool, cfeif5) 94 | 95 | ETL_BFF_FIELD( 5: 5, bool, ctcif4) 96 | ETL_BFF_FIELD( 4: 4, bool, chtif4) 97 | ETL_BFF_FIELD( 3: 3, bool, cteif4) 98 | ETL_BFF_FIELD( 2: 2, bool, cdmeif4) 99 | ETL_BFF_FIELD( 0: 0, bool, cfeif4) 100 | ) 101 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/dma_stream.reg: -------------------------------------------------------------------------------- 1 | ETL_BFF_REG_RW(Word, cr, 2 | ETL_BFF_FIELD (27:25, unsigned, chsel) 3 | ETL_BFF_FIELD (24:23, BurstSize, mburst) 4 | ETL_BFF_FIELD (22:21, BurstSize, pburst) 5 | ETL_BFF_FIELD (19:19, unsigned, ct) 6 | ETL_BFF_FIELD (18:18, bool, dbm) 7 | ETL_BFF_FIELD_E(17:16, unsigned, pl, 8 | ETL_BFF_ENUM(0b00, low) 9 | ETL_BFF_ENUM(0b01, medium) 10 | ETL_BFF_ENUM(0b10, high) 11 | ETL_BFF_ENUM(0b11, very_high) 12 | ) 13 | ETL_BFF_FIELD (15:15, bool, pincos) 14 | ETL_BFF_FIELD (14:13, TransferSize, msize) 15 | ETL_BFF_FIELD (12:11, TransferSize, psize) 16 | ETL_BFF_FIELD (10:10, bool, minc) 17 | ETL_BFF_FIELD ( 9: 9, bool, pinc) 18 | ETL_BFF_FIELD ( 8: 8, bool, circ) 19 | ETL_BFF_FIELD_E( 7: 6, unsigned, dir, 20 | ETL_BFF_ENUM(0b00, peripheral_to_memory) 21 | ETL_BFF_ENUM(0b01, memory_to_peripheral) 22 | ETL_BFF_ENUM(0b10, memory_to_memory) 23 | ) 24 | ETL_BFF_FIELD ( 5: 5, bool, pfctrl) 25 | ETL_BFF_FIELD ( 4: 4, bool, tcie) 26 | ETL_BFF_FIELD ( 3: 3, bool, htie) 27 | ETL_BFF_FIELD ( 2: 2, bool, teie) 28 | ETL_BFF_FIELD ( 1: 1, bool, dmeie) 29 | ETL_BFF_FIELD ( 0: 0, bool, en) 30 | ) 31 | ETL_BFF_REG_RW(Word, ndtr, ) 32 | ETL_BFF_REG_RW(Word, par, ) 33 | ETL_BFF_REG_RW(Word, m0ar, ) 34 | ETL_BFF_REG_RW(Word, m1ar, ) 35 | ETL_BFF_REG_RW(Word, fcr, 36 | ETL_BFF_FIELD ( 7: 7, bool, feie) 37 | ETL_BFF_FIELD_E( 5: 3, unsigned, fs, 38 | ETL_BFF_ENUM(0b000, less_than_quarter_full) 39 | ETL_BFF_ENUM(0b001, less_than_half_full) 40 | ETL_BFF_ENUM(0b010, less_than_three_quarters_full) 41 | ETL_BFF_ENUM(0b011, less_than_full) 42 | ETL_BFF_ENUM(0b100, empty) 43 | ETL_BFF_ENUM(0b101, full) 44 | ) 45 | ETL_BFF_FIELD ( 2: 2, bool, dmdis) 46 | ETL_BFF_FIELD_E( 1: 0, unsigned, fth, 47 | ETL_BFF_ENUM(0b00, quarter) 48 | ETL_BFF_ENUM(0b01, half) 49 | ETL_BFF_ENUM(0b10, three_quarters) 50 | ETL_BFF_ENUM(0b11, full) 51 | ) 52 | ) 53 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/flash.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_FLASH_H_INCLUDED 2 | #define _ETL_STM32F4XX_FLASH_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | 6 | namespace etl { 7 | namespace stm32f4xx { 8 | 9 | struct Flash { 10 | #define ETL_BFF_DEFINITION_FILE "etl/stm32f4xx/flash.reg" 11 | #include "etl/biffield/generate.h" 12 | #undef ETL_BFF_DEFINITION_FILE 13 | }; 14 | 15 | extern Flash flash; 16 | 17 | } // namespace stm32f4xx 18 | } // namespace etl 19 | 20 | #endif // _ETL_STM32F4XX_FLASH_H_INCLUDED 21 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/flash.reg: -------------------------------------------------------------------------------- 1 | ETL_BFF_REG_RW(Word, acr, 2 | ETL_BFF_FIELD(12:12, bool, dcrst) 3 | ETL_BFF_FIELD(11:11, bool, icrst) 4 | ETL_BFF_FIELD(10:10, bool, dcen) 5 | ETL_BFF_FIELD( 9: 9, bool, icen) 6 | ETL_BFF_FIELD( 8: 8, bool, prften) 7 | ETL_BFF_FIELD( 2: 0, unsigned, latency) 8 | ) 9 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/gp_timer.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_GP_TIMER_H_INCLUDED 2 | #define _ETL_STM32F4XX_GP_TIMER_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | 6 | namespace etl { 7 | namespace stm32f4xx { 8 | 9 | struct GpTimer { 10 | enum class OcMode { 11 | frozen = 0b000, 12 | ch1_active_on_match = 0b001, 13 | ch1_inactive_on_match = 0b010, 14 | toggle = 0b011, 15 | force_inactive = 0b100, 16 | force_active = 0b101, 17 | pwm1 = 0b110, 18 | pwm2 = 0b111, 19 | }; 20 | 21 | #define ETL_BFF_DEFINITION_FILE "etl/stm32f4xx/gp_timer.reg" 22 | #include "etl/biffield/generate.h" 23 | #undef ETL_BFF_DEFINITION_FILE 24 | }; 25 | 26 | extern GpTimer tim2; 27 | extern GpTimer tim3; 28 | extern GpTimer tim4; 29 | extern GpTimer tim5; 30 | 31 | } // namespace stm32f4xx 32 | } // namespace etl 33 | 34 | #endif // _ETL_STM32F4XX_GP_TIMER_H_INCLUDED 35 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/gpio.cc: -------------------------------------------------------------------------------- 1 | #include "etl/stm32f4xx/gpio.h" 2 | 3 | namespace etl { 4 | namespace stm32f4xx { 5 | 6 | /* 7 | * Each of the GPIO registers gets a very similar mutator. Generate these 8 | * with a macro to avoid copy-pasting. 9 | */ 10 | 11 | #define GPIO_MUTATOR(name, type, reg, field) \ 12 | void Gpio::set_ ## name (HalfWord mask_, type x) { \ 13 | auto val = read_ ## reg(); \ 14 | Word mask = mask_; \ 15 | for (unsigned i = 0; i < 16; ++i) { \ 16 | if (mask & 1) val = val.with_ ## field(i, x); \ 17 | mask >>= 1; \ 18 | } \ 19 | write_ ## reg(val); \ 20 | } 21 | 22 | GPIO_MUTATOR(mode, Mode, moder, mode) 23 | GPIO_MUTATOR(output_type, OutputType, otyper, otype) 24 | GPIO_MUTATOR(output_speed, OutputSpeed, ospeedr, ospeed) 25 | GPIO_MUTATOR(pull, Pull, pupdr, pupd) 26 | 27 | void Gpio::set_alternate_function(HalfWord mask_, unsigned af) { 28 | af &= 0xF; 29 | 30 | auto val_low = read_afrl(); 31 | auto val_high = read_afrh(); 32 | 33 | Word mask = mask_; 34 | 35 | for (unsigned i = 0; i < 8; ++i) { 36 | if (mask & 1) val_low = val_low.with_af(i, af); 37 | if (mask & (1 << 8)) val_high = val_high.with_af(i, af); 38 | mask >>= 1; 39 | } 40 | 41 | write_afrl(val_low); 42 | write_afrh(val_high); 43 | } 44 | 45 | } // namespace stm32f4xx 46 | } // namespace etl 47 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/gpio.reg: -------------------------------------------------------------------------------- 1 | ETL_BFF_REG_RW(Word, moder, 2 | ETL_BFF_FIELD_ARRAY(31: 0, 2, Mode, mode) 3 | ) 4 | ETL_BFF_REG_RW(Word, otyper, 5 | ETL_BFF_FIELD_ARRAY(15: 0, 1, OutputType, otype) 6 | ) 7 | ETL_BFF_REG_RW(Word, ospeedr, 8 | ETL_BFF_FIELD_ARRAY(31: 0, 2, OutputSpeed, ospeed) 9 | ) 10 | ETL_BFF_REG_RW(Word, pupdr, 11 | ETL_BFF_FIELD_ARRAY(31: 0, 2, Pull, pupd) 12 | ) 13 | ETL_BFF_REG_RW(Word, idr, 14 | ETL_BFF_FIELD_ARRAY(15: 0, 1, bool, id) 15 | ) 16 | ETL_BFF_REG_RW(Word, odr, 17 | ETL_BFF_FIELD_ARRAY(15: 0, 1, bool, od) 18 | ETL_BFF_FIELD(15: 0, HalfWord, bits) 19 | ) 20 | ETL_BFF_REG_RW(Word, bsrr, 21 | ETL_BFF_FIELD_ARRAY(31:16, 1, bool, reset) 22 | ETL_BFF_FIELD (31:16, HalfWord, resetbits) 23 | ETL_BFF_FIELD_ARRAY(15: 0, 1, bool, set) 24 | ETL_BFF_FIELD (15: 0, HalfWord, setbits) 25 | ) 26 | ETL_BFF_REG_RW(Word, lckr, 27 | ETL_BFF_FIELD(16:16, bool, lckk) 28 | ETL_BFF_FIELD_ARRAY(15: 0, 1, bool, lck) 29 | ) 30 | ETL_BFF_REG_RW(Word, afrl, 31 | ETL_BFF_FIELD_ARRAY(31: 0, 4, unsigned, af) 32 | ) 33 | ETL_BFF_REG_RW(Word, afrh, 34 | ETL_BFF_FIELD_ARRAY(31: 0, 4, unsigned, af) 35 | ) 36 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/iic.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_IIC_H_INCLUDED 2 | #define _ETL_STM32F4XX_IIC_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | 6 | namespace etl { 7 | namespace stm32f4xx { 8 | 9 | struct Iic { 10 | #define ETL_BFF_DEFINITION_FILE "etl/stm32f4xx/iic.reg" 11 | #include "etl/biffield/generate.h" 12 | #undef ETL_BFF_DEFINITION_FILE 13 | }; 14 | 15 | extern Iic iic1; 16 | 17 | } // namespace stm32f4xx 18 | } // namespace etl 19 | 20 | #endif // _ETL_STM32F4XX_IIC_H_INCLUDED 21 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/iic.reg: -------------------------------------------------------------------------------- 1 | ETL_BFF_REG_RW(Word, cr1, 2 | ETL_BFF_FIELD( 9: 9, bool, stop) 3 | ETL_BFF_FIELD( 8: 8, bool, start) 4 | ETL_BFF_FIELD( 0: 0, bool, pe) 5 | ) 6 | ETL_BFF_REG_RW(Word, cr2, 7 | ETL_BFF_FIELD( 5: 0, unsigned, freq) 8 | ) 9 | ETL_BFF_REG_RW(Word, oar1, ) 10 | ETL_BFF_REG_RW(Word, oar2, ) 11 | ETL_BFF_REG_RW(Word, dr, ) 12 | ETL_BFF_REG_RW(Word, sr1, 13 | ETL_BFF_FIELD(10:10, bool, af) 14 | ETL_BFF_FIELD( 7: 7, bool, txe) 15 | ETL_BFF_FIELD( 2: 2, bool, btf) 16 | ETL_BFF_FIELD( 1: 1, bool, addr) 17 | ETL_BFF_FIELD( 0: 0, bool, sb) 18 | ) 19 | ETL_BFF_REG_RW(Word, sr2, ) 20 | ETL_BFF_REG_RW(Word, ccr, 21 | ETL_BFF_FIELD(15:15, bool, fs) 22 | ETL_BFF_FIELD(11: 0, unsigned, ccr) 23 | ) 24 | ETL_BFF_REG_RW(Word, trise, 25 | ETL_BFF_FIELD( 5: 0, unsigned, trise) 26 | ) 27 | ETL_BFF_REG_RW(Word, fltr, ) 28 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/interrupt_table.cc: -------------------------------------------------------------------------------- 1 | #include "etl/stm32f4xx/interrupt_table.h" 2 | #include "etl/attribute_macros.h" 3 | #include "etl/stm32f4xx/interrupts.h" 4 | 5 | namespace etl { 6 | namespace stm32f4xx { 7 | 8 | 9 | typedef void (*InterruptHandler)(void); 10 | 11 | struct InterruptTable { 12 | #define ETL_STM32F4XX_IRQ(name) InterruptHandler name ## _handler; 13 | #include "etl/stm32f4xx/interrupts.def" 14 | #undef ETL_STM32F4XX_IRQ 15 | }; 16 | 17 | /* 18 | * There are a couple of nuances to the interrupt table definition. 19 | * 20 | * 1. We place it in a section called .etl_stm32f4xx_interrupt_table. There's 21 | * nothing special about that name, except that the linker scripts look for 22 | * it and put it in the right place. 23 | * 24 | * 2. We make the table const, ensuring that the linker will let us place it 25 | * in Flash if the linker script wants it there. 26 | */ 27 | ETL_SECTION(".etl_stm32f4xx_interrupt_table") 28 | ETL_USED 29 | InterruptTable const stm32f4xx_interrupt_table = { 30 | #define ETL_STM32F4XX_IRQ(name) etl_stm32f4xx_ ## name ## _handler, 31 | #include "etl/stm32f4xx/interrupts.def" 32 | #undef ETL_STM32F4XX_IRQ 33 | }; 34 | 35 | extern "C" { 36 | void unexpected_irq(); // hack 37 | void unexpected_irq() { while (1); } 38 | #define ETL_STM32F4XX_IRQ(name) void etl_stm32f4xx_ ## name ## _handler() \ 39 | ETL_WEAK ETL_ALIAS("unexpected_irq"); 40 | #include "etl/stm32f4xx/interrupts.def" 41 | #undef ETL_STM32F4XX_IRQ 42 | } 43 | 44 | } // namespace stm32f4xx 45 | } // namespace etl 46 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/interrupt_table.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_INTERRUPT_TABLE_H_INCLUDED 2 | #define _ETL_STM32F4XX_INTERRUPT_TABLE_H_INCLUDED 3 | 4 | extern "C" { 5 | #define ETL_STM32F4XX_IRQ(name) void etl_stm32f4xx_ ## name ## _handler(); 6 | #include "etl/stm32f4xx/interrupts.def" 7 | #undef ETL_STM32F4XX_IRQ 8 | } 9 | 10 | #endif // _ETL_STM32F4XX_INTERRUPT_TABLE_H_INCLUDED 11 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/interrupts.cc: -------------------------------------------------------------------------------- 1 | #include "etl/stm32f4xx/interrupts.h" 2 | 3 | #include "etl/armv7m/nvic.h" 4 | 5 | #include "etl/stm32f4xx/types.h" 6 | 7 | using etl::armv7m::nvic; 8 | 9 | namespace etl { 10 | namespace stm32f4xx { 11 | 12 | void enable_irq(Interrupt irq) { 13 | nvic.enable_irq(static_cast(irq)); 14 | } 15 | 16 | void disable_irq(Interrupt irq) { 17 | nvic.disable_irq(static_cast(irq)); 18 | } 19 | 20 | void clear_pending_irq(Interrupt irq) { 21 | nvic.clear_pending_irq(static_cast(irq)); 22 | } 23 | 24 | void set_irq_priority(Interrupt irq, unsigned priority) { 25 | unsigned shifted_priority = (priority << 4) & 0xFF; 26 | nvic.set_irq_priority(static_cast(irq), 27 | static_cast(shifted_priority)); 28 | } 29 | 30 | } // namespace stm32f4xx 31 | } // namespace etl 32 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/interrupts.def: -------------------------------------------------------------------------------- 1 | // vim:syntax=cpp: 2 | // Unified STM32F4xx series interrupt table 3 | // Different 4xx chips implement different subsets of these interrupts, but 4 | // thankfully they all use the same numbers. This file unifies the sets of 5 | // interrupts in each chip into a single enumeration. 6 | // 7 | // Of course, the chip you're using may not implement all of these, but the 8 | // vector table shape is the same across all parts. 9 | // 10 | 11 | ETL_STM32F4XX_IRQ(wwdg) 12 | ETL_STM32F4XX_IRQ(pvd) 13 | ETL_STM32F4XX_IRQ(tamp_stamp) 14 | ETL_STM32F4XX_IRQ(rtc_wkup) 15 | ETL_STM32F4XX_IRQ(flash) 16 | ETL_STM32F4XX_IRQ(rcc) 17 | ETL_STM32F4XX_IRQ(exti0) 18 | ETL_STM32F4XX_IRQ(exti1) 19 | ETL_STM32F4XX_IRQ(exti2) 20 | ETL_STM32F4XX_IRQ(exti3) 21 | ETL_STM32F4XX_IRQ(exti4) 22 | ETL_STM32F4XX_IRQ(dma1_stream0) 23 | ETL_STM32F4XX_IRQ(dma1_stream1) 24 | ETL_STM32F4XX_IRQ(dma1_stream2) 25 | ETL_STM32F4XX_IRQ(dma1_stream3) 26 | ETL_STM32F4XX_IRQ(dma1_stream4) 27 | ETL_STM32F4XX_IRQ(dma1_stream5) 28 | ETL_STM32F4XX_IRQ(dma1_stream6) 29 | ETL_STM32F4XX_IRQ(adc) 30 | 31 | ETL_STM32F4XX_IRQ(can1_tx) 32 | ETL_STM32F4XX_IRQ(can1_rx0) 33 | ETL_STM32F4XX_IRQ(can1_rx1) 34 | ETL_STM32F4XX_IRQ(can1_sce) 35 | ETL_STM32F4XX_IRQ(exti9_5) 36 | ETL_STM32F4XX_IRQ(tim1_brk_tim9) 37 | ETL_STM32F4XX_IRQ(tim1_up_tim10) 38 | ETL_STM32F4XX_IRQ(tim1_trg_com_tim11) 39 | ETL_STM32F4XX_IRQ(tim1_cc) 40 | ETL_STM32F4XX_IRQ(tim2) 41 | ETL_STM32F4XX_IRQ(tim3) 42 | ETL_STM32F4XX_IRQ(tim4) 43 | ETL_STM32F4XX_IRQ(i2c1_ev) 44 | ETL_STM32F4XX_IRQ(i2c1_er) 45 | ETL_STM32F4XX_IRQ(i2c2_ev) 46 | ETL_STM32F4XX_IRQ(i2c2_er) 47 | ETL_STM32F4XX_IRQ(spi1) 48 | ETL_STM32F4XX_IRQ(spi2) 49 | ETL_STM32F4XX_IRQ(usart1) 50 | ETL_STM32F4XX_IRQ(usart2) 51 | ETL_STM32F4XX_IRQ(usart3) 52 | ETL_STM32F4XX_IRQ(exti15_10) 53 | ETL_STM32F4XX_IRQ(rtc_alarm) 54 | ETL_STM32F4XX_IRQ(otg_fs_wkup) 55 | ETL_STM32F4XX_IRQ(tim8_brk_tim12) 56 | ETL_STM32F4XX_IRQ(tim8_up_tim13) 57 | ETL_STM32F4XX_IRQ(tim8_trg_com_tim14) 58 | ETL_STM32F4XX_IRQ(tim8_cc) 59 | ETL_STM32F4XX_IRQ(dma1_stream7) 60 | ETL_STM32F4XX_IRQ(fsmc) 61 | ETL_STM32F4XX_IRQ(sdio) 62 | ETL_STM32F4XX_IRQ(tim5) 63 | ETL_STM32F4XX_IRQ(spi3) 64 | ETL_STM32F4XX_IRQ(uart4) 65 | ETL_STM32F4XX_IRQ(uart5) 66 | ETL_STM32F4XX_IRQ(tim6_dac) 67 | ETL_STM32F4XX_IRQ(tim7) 68 | ETL_STM32F4XX_IRQ(dma2_stream0) 69 | ETL_STM32F4XX_IRQ(dma2_stream1) 70 | ETL_STM32F4XX_IRQ(dma2_stream2) 71 | ETL_STM32F4XX_IRQ(dma2_stream3) 72 | ETL_STM32F4XX_IRQ(dma2_stream4) 73 | ETL_STM32F4XX_IRQ(eth) 74 | ETL_STM32F4XX_IRQ(eth_wkup) 75 | ETL_STM32F4XX_IRQ(can2_tx) 76 | ETL_STM32F4XX_IRQ(can2_rx0) 77 | ETL_STM32F4XX_IRQ(can2_rx1) 78 | ETL_STM32F4XX_IRQ(can2_sce) 79 | ETL_STM32F4XX_IRQ(otg_fs) 80 | ETL_STM32F4XX_IRQ(dma2_stream5) 81 | ETL_STM32F4XX_IRQ(dma2_stream6) 82 | ETL_STM32F4XX_IRQ(dma2_stream7) 83 | ETL_STM32F4XX_IRQ(usart6) 84 | ETL_STM32F4XX_IRQ(i2c3_ev) 85 | ETL_STM32F4XX_IRQ(i2c3_er) 86 | ETL_STM32F4XX_IRQ(otg_hs_ep1_out) 87 | ETL_STM32F4XX_IRQ(otg_hs_ep1_in) 88 | ETL_STM32F4XX_IRQ(otg_hs_wkup) 89 | ETL_STM32F4XX_IRQ(otg_hs) 90 | ETL_STM32F4XX_IRQ(dcmi) 91 | ETL_STM32F4XX_IRQ(cryp) 92 | ETL_STM32F4XX_IRQ(hash_rng) 93 | ETL_STM32F4XX_IRQ(fpu) 94 | 95 | ETL_STM32F4XX_IRQ(uart7) 96 | ETL_STM32F4XX_IRQ(uart8) 97 | ETL_STM32F4XX_IRQ(spi4) 98 | ETL_STM32F4XX_IRQ(spi5) 99 | ETL_STM32F4XX_IRQ(spi6) 100 | ETL_STM32F4XX_IRQ(sai1) 101 | ETL_STM32F4XX_IRQ(ltdc) 102 | ETL_STM32F4XX_IRQ(ltdc_er) 103 | ETL_STM32F4XX_IRQ(dma2d) 104 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/interrupts.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_INTERRUPTS_H_INCLUDED 2 | #define _ETL_STM32F4XX_INTERRUPTS_H_INCLUDED 3 | 4 | namespace etl { 5 | namespace stm32f4xx { 6 | 7 | /* 8 | * A convenient enumeration of all STM32F4xx interrupts. 9 | */ 10 | enum class Interrupt : unsigned { 11 | #define ETL_STM32F4XX_IRQ(name) name, 12 | #include "etl/stm32f4xx/interrupts.def" 13 | #undef ETL_STM32F4XX_IRQ 14 | }; 15 | 16 | /* 17 | * Facade for armv7m::nvic.enable_irq using the Interrupt enum. 18 | */ 19 | void enable_irq(Interrupt); 20 | 21 | /* 22 | * Facade for armv7m::nvic.disable_irq using the Interrupt enum. 23 | */ 24 | void disable_irq(Interrupt); 25 | 26 | /* 27 | * Facade for armv7m::nvic.clear_pending_irq using the Interrupt enum. 28 | */ 29 | void clear_pending_irq(Interrupt); 30 | 31 | /* 32 | * Facade for armv7m::nvic.disable_irq using the Interrupt enum *and* STM32F4xx 33 | * priorities. 34 | * 35 | * The STM32F4xx only implements four bits of priority, so valid priorities 36 | * range from 0 - 15. 37 | * 38 | * Precondition: priority is valid. 39 | */ 40 | void set_irq_priority(Interrupt, unsigned priority); 41 | 42 | } // namespace stm32f4xx 43 | } // namespace etl 44 | 45 | #endif // _ETL_STM32F4XX_INTERRUPTS_H_INCLUDED 46 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/peripherals.ld: -------------------------------------------------------------------------------- 1 | _ZN3etl9stm32f4xx4tim2E = 0x40000000; 2 | _ZN3etl9stm32f4xx4tim3E = 0x40000400; 3 | _ZN3etl9stm32f4xx4tim4E = 0x40000800; 4 | _ZN3etl9stm32f4xx4tim5E = 0x40000c00; 5 | 6 | _ZN3etl9stm32f4xx4tim6E = 0x40001000; 7 | _ZN3etl9stm32f4xx4tim7E = 0x40001400; 8 | 9 | _ZN3etl9stm32f4xx4spi3E = 0x40003C00; 10 | 11 | _ZN3etl9stm32f4xx6usart2E = 0x40004400; 12 | _ZN3etl9stm32f4xx6usart3E = 0x40004800; 13 | 14 | _ZN3etl9stm32f4xx4iic1E = 0x40005400; 15 | 16 | _ZN3etl9stm32f4xx3pwrE = 0x40007000; 17 | 18 | _ZN3etl9stm32f4xx3dacE = 0x40007400; 19 | 20 | _ZN3etl9stm32f4xx4tim1E = 0x40010000; 21 | _ZN3etl9stm32f4xx4tim8E = 0x40010400; 22 | 23 | _ZN3etl9stm32f4xx6usart1E = 0x40011000; 24 | _ZN3etl9stm32f4xx6usart6E = 0x40011400; 25 | 26 | _ZN3etl9stm32f4xx6syscfgE = 0x40013800; 27 | 28 | _ZN3etl9stm32f4xx5gpioaE = 0x40020000; 29 | _ZN3etl9stm32f4xx5gpiobE = 0x40020400; 30 | _ZN3etl9stm32f4xx5gpiocE = 0x40020800; 31 | _ZN3etl9stm32f4xx5gpiodE = 0x40020c00; 32 | _ZN3etl9stm32f4xx5gpioeE = 0x40021000; 33 | _ZN3etl9stm32f4xx5gpiofE = 0x40021400; 34 | _ZN3etl9stm32f4xx5gpiogE = 0x40021800; 35 | _ZN3etl9stm32f4xx5gpiohE = 0x40021c00; 36 | _ZN3etl9stm32f4xx5gpioiE = 0x40022000; 37 | _ZN3etl9stm32f4xx5gpiojE = 0x40022400; 38 | _ZN3etl9stm32f4xx5gpiokE = 0x40022800; 39 | 40 | _ZN3etl9stm32f4xx3rccE = 0x40023800; 41 | _ZN3etl9stm32f4xx5flashE = 0x40023c00; 42 | 43 | _ZN3etl9stm32f4xx4dma1E = 0x40026000; 44 | _ZN3etl9stm32f4xx4dma2E = 0x40026400; 45 | 46 | _ZN3etl9stm32f4xx3dbgE = 0xE0042000; 47 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/pwr.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_PWR_H_INCLUDED 2 | #define _ETL_STM32F4XX_PWR_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | 6 | namespace etl { 7 | namespace stm32f4xx { 8 | 9 | struct Pwr { 10 | #define ETL_BFF_DEFINITION_FILE "etl/stm32f4xx/pwr.reg" 11 | #include "etl/biffield/generate.h" 12 | #undef ETL_BFF_DEFINITION_FILE 13 | }; 14 | 15 | extern Pwr pwr; 16 | 17 | } // namespace stm32f4xx 18 | } // namespace etl 19 | 20 | #endif // _ETL_STM32F4XX_PWR_H_INCLUDED 21 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/pwr.reg: -------------------------------------------------------------------------------- 1 | ETL_BFF_REG_RW(Word, cr, 2 | ETL_BFF_FIELD_E(14:14, unsigned, vos, 3 | ETL_BFF_ENUM(0b0, scale_2_mode) 4 | ETL_BFF_ENUM(0b1, scale_1_mode) 5 | ) 6 | ETL_BFF_FIELD( 9: 9, bool, fpds) 7 | ETL_BFF_FIELD( 8: 8, bool, dbp) 8 | ETL_BFF_FIELD_E( 7: 5, unsigned, pls, 9 | ETL_BFF_ENUM(0b000, _2v0) 10 | ETL_BFF_ENUM(0b001, _2v1) 11 | ETL_BFF_ENUM(0b010, _2v3) 12 | ETL_BFF_ENUM(0b011, _2v5) 13 | ETL_BFF_ENUM(0b100, _2v6) 14 | ETL_BFF_ENUM(0b101, _2v7) 15 | ETL_BFF_ENUM(0b110, _2v8) 16 | ETL_BFF_ENUM(0b111, _2v9) 17 | ) 18 | ETL_BFF_FIELD( 4: 4, bool, pvde) 19 | ETL_BFF_FIELD( 3: 3, bool, csbf) 20 | ETL_BFF_FIELD( 2: 2, bool, cwuf) 21 | ETL_BFF_FIELD( 1: 1, bool, pdds) 22 | ETL_BFF_FIELD( 0: 0, bool, lpds) 23 | ) 24 | ETL_BFF_REG_RW(Word, csr, 25 | ETL_BFF_FIELD(15:15, bool, vosrdy) 26 | ETL_BFF_FIELD( 9: 9, bool, bre) 27 | ETL_BFF_FIELD( 8: 8, bool, ewup) 28 | ETL_BFF_FIELD( 3: 3, bool, brr) 29 | ETL_BFF_FIELD_E( 2: 2, bool, pvdo, 30 | ETL_BFF_ENUM(false, vdd_above_threshold) 31 | ETL_BFF_ENUM(true, vdd_below_threshold) 32 | ) 33 | ETL_BFF_FIELD( 1: 1, bool, sbf) 34 | ETL_BFF_FIELD( 0: 0, bool, wuf) 35 | ) 36 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/rcc.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_RCC_H_INCLUDED 2 | #define _ETL_STM32F4XX_RCC_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | #include "etl/stm32f4xx/ahb.h" 6 | #include "etl/stm32f4xx/apb.h" 7 | 8 | namespace etl { 9 | namespace stm32f4xx { 10 | 11 | struct ClockConfig; 12 | 13 | struct Rcc { 14 | enum class pprex_t : unsigned { 15 | div1 = 0b000, 16 | div2 = 0b100, 17 | div4 = 0b101, 18 | div8 = 0b110, 19 | div16 = 0b111, 20 | }; 21 | 22 | #define ETL_BFF_DEFINITION_FILE "etl/stm32f4xx/rcc.reg" 23 | #include "etl/biffield/generate.h" 24 | #undef ETL_BFF_DEFINITION_FILE 25 | 26 | void enter_reset(AhbPeripheral); 27 | void enter_reset(ApbPeripheral); 28 | 29 | void leave_reset(AhbPeripheral); 30 | void leave_reset(ApbPeripheral); 31 | 32 | void enable_clock(AhbPeripheral); 33 | void enable_clock(ApbPeripheral); 34 | 35 | void disable_clock(AhbPeripheral); 36 | void disable_clock(ApbPeripheral); 37 | 38 | void configure_clocks(ClockConfig const &); 39 | 40 | float get_cpu_clock_hz() const; 41 | float get_ahb_clock_hz() const; 42 | float get_apb1_clock_hz() const; 43 | float get_apb2_clock_hz() const; 44 | float get_pll48_clock_hz() const; 45 | 46 | float get_clock_hz(ApbPeripheral) const; 47 | }; 48 | 49 | extern Rcc rcc; 50 | 51 | struct ClockSpeeds { 52 | float cpu; 53 | float ahb; 54 | float apb1; 55 | float apb2; 56 | float pll48; 57 | }; 58 | 59 | struct ClockConfig { 60 | float crystal_hz; 61 | unsigned crystal_divisor; 62 | unsigned vco_multiplier; 63 | unsigned general_divisor; 64 | unsigned pll48_divisor; 65 | 66 | unsigned ahb_divisor; 67 | unsigned apb1_divisor; 68 | unsigned apb2_divisor; 69 | 70 | unsigned flash_latency; 71 | 72 | void compute_speeds(ClockSpeeds *) const; 73 | }; 74 | 75 | } // namespace stm32f4xx 76 | } // namespace etl 77 | 78 | #endif // _ETL_STM32F4XX_RCC_H_INCLUDED 79 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/spi.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_SPI_H_INCLUDED 2 | #define _ETL_STM32F4XX_SPI_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | 6 | namespace etl { 7 | namespace stm32f4xx { 8 | 9 | struct Spi { 10 | #define ETL_BFF_DEFINITION_FILE "etl/stm32f4xx/spi.reg" 11 | #include "etl/biffield/generate.h" 12 | #undef ETL_BFF_DEFINITION_FILE 13 | }; 14 | 15 | extern Spi spi3; 16 | 17 | } // namespace stm32f4xx 18 | } // namespace etl 19 | 20 | #endif // _ETL_STM32F4XX_SPI_H_INCLUDED 21 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/spi.reg: -------------------------------------------------------------------------------- 1 | ETL_BFF_REG_RW(Word, cr1, 2 | ETL_BFF_FIELD(15:15, bool, bidimode) 3 | ETL_BFF_FIELD(14:14, bool, bidioe) 4 | ETL_BFF_FIELD(13:13, bool, crcen) 5 | ETL_BFF_FIELD(12:12, bool, crcnext) 6 | ETL_BFF_FIELD_E(11:11, bool, dff, 7 | ETL_BFF_ENUM(false, frame8) 8 | ETL_BFF_ENUM(true, frame16) 9 | ) 10 | ETL_BFF_FIELD(10:10, bool, rxonly) 11 | ETL_BFF_FIELD( 9: 9, bool, ssm) 12 | ETL_BFF_FIELD( 8: 8, bool, ssi) 13 | ETL_BFF_FIELD( 7: 7, bool, lsbfirst) 14 | ETL_BFF_FIELD( 6: 6, bool, spe) 15 | 16 | ETL_BFF_FIELD_E( 5: 3, unsigned, br, 17 | ETL_BFF_ENUM(0b000, div2) 18 | ETL_BFF_ENUM(0b001, div4) 19 | ETL_BFF_ENUM(0b010, div8) 20 | ETL_BFF_ENUM(0b011, div16) 21 | ETL_BFF_ENUM(0b100, div32) 22 | ETL_BFF_ENUM(0b101, div64) 23 | ETL_BFF_ENUM(0b110, div128) 24 | ETL_BFF_ENUM(0b111, div256) 25 | ) 26 | 27 | ETL_BFF_FIELD( 2: 2, bool, mstr) 28 | ETL_BFF_FIELD_E( 1: 1, unsigned, cpol, 29 | ETL_BFF_ENUM(false, idle_low) 30 | ETL_BFF_ENUM(true, idle_high) 31 | ) 32 | ETL_BFF_FIELD_E( 0: 0, unsigned, cpha, 33 | ETL_BFF_ENUM(false, capture_on_first_edge) 34 | ETL_BFF_ENUM(true, capture_on_second_edge) 35 | ) 36 | ) 37 | ETL_BFF_REG_RW(Word, cr2, ) 38 | ETL_BFF_REG_RW(Word, sr, 39 | ETL_BFF_FIELD( 8: 8, bool, fre) 40 | ETL_BFF_FIELD( 7: 7, bool, bsy) 41 | ETL_BFF_FIELD( 6: 6, bool, ovr) 42 | ETL_BFF_FIELD( 5: 5, bool, modf) 43 | ETL_BFF_FIELD( 4: 4, bool, crcerr) 44 | ETL_BFF_FIELD( 3: 3, bool, udr) 45 | ETL_BFF_FIELD( 2: 2, bool, chside) 46 | ETL_BFF_FIELD( 1: 1, bool, txe) 47 | ETL_BFF_FIELD( 0: 0, bool, rxne) 48 | ) 49 | ETL_BFF_REG_RW(Word, dr, ) 50 | ETL_BFF_REG_RW(Word, crcpr, ) 51 | ETL_BFF_REG_RW(Word, rxcrcr, ) 52 | ETL_BFF_REG_RW(Word, txcrcr, ) 53 | ETL_BFF_REG_RW(Word, i2scfgr, 54 | ETL_BFF_FIELD (11:11, bool, i2smod) 55 | ETL_BFF_FIELD (10:10, bool, i2se) 56 | ETL_BFF_FIELD_E( 9: 8, unsigned, i2scfg, 57 | ETL_BFF_ENUM(0b00, slave_tx) 58 | ETL_BFF_ENUM(0b01, slave_rx) 59 | ETL_BFF_ENUM(0b10, master_tx) 60 | ETL_BFF_ENUM(0b11, master_rx) 61 | ) 62 | ETL_BFF_FIELD ( 7: 7, bool, pcmsync) 63 | ETL_BFF_FIELD_E( 5: 4, unsigned, i2sstd, 64 | ETL_BFF_ENUM(0b00, i2s) 65 | ETL_BFF_ENUM(0b01, left_justified) 66 | ETL_BFF_ENUM(0b10, right_justified) 67 | ETL_BFF_ENUM(0b11, pcm) 68 | ) 69 | ETL_BFF_FIELD ( 3: 3, bool, ckpol) 70 | ETL_BFF_FIELD_E( 2: 1, unsigned, datlen, 71 | ETL_BFF_ENUM(0b00, bits_16) 72 | ETL_BFF_ENUM(0b01, bits_24) 73 | ETL_BFF_ENUM(0b10, bits_32) 74 | ) 75 | ETL_BFF_FIELD_E( 0: 0, bool, chlen, 76 | ETL_BFF_ENUM(false, bits_16) 77 | ETL_BFF_ENUM(true, bits_32) 78 | ) 79 | ) 80 | ETL_BFF_REG_RW(Word, i2spr, 81 | ETL_BFF_FIELD( 9: 9, bool, mckoe) 82 | ETL_BFF_FIELD( 8: 8, bool, odd) 83 | ETL_BFF_FIELD( 7: 0, unsigned, i2sdiv) 84 | ) 85 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/syscfg.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_SYSCFG_H_INCLUDED 2 | #define _ETL_STM32F4XX_SYSCFG_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | 6 | namespace etl { 7 | namespace stm32f4xx { 8 | 9 | struct SysCfg { 10 | #define ETL_BFF_DEFINITION_FILE "etl/stm32f4xx/syscfg.reg" 11 | #include "etl/biffield/generate.h" 12 | #undef ETL_BFF_DEFINITION_FILE 13 | }; 14 | 15 | extern SysCfg syscfg; 16 | 17 | } // namespace stm32f4xx 18 | } // namespace etl 19 | 20 | #endif // _ETL_STM32F4XX_SYSCFG_H_INCLUDED 21 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/syscfg.reg: -------------------------------------------------------------------------------- 1 | ETL_BFF_REG_RW(Word, memrmp, 2 | ETL_BFF_FIELD_E( 1: 0, unsigned, mem_mode, 3 | ETL_BFF_ENUM(0b00, main_flash) 4 | ETL_BFF_ENUM(0b01, system_flash) 5 | ETL_BFF_ENUM(0b10, fsmc_bank_1) 6 | ETL_BFF_ENUM(0b11, embedded_sram) 7 | ) 8 | ) 9 | ETL_BFF_REG_RW(Word, pmc, 10 | ETL_BFF_FIELD(23:23, bool, mii_rmii_sel) 11 | ) 12 | ETL_BFF_REG_RW(Word, exticr1, ) 13 | ETL_BFF_REG_RW(Word, exticr2, ) 14 | ETL_BFF_REG_RW(Word, exticr3, ) 15 | ETL_BFF_REG_RW(Word, exticr4, ) 16 | ETL_BFF_REG_RESERVED(Word, 18, 2) 17 | ETL_BFF_REG_RW(Word, cmpcr, 18 | ETL_BFF_FIELD( 8: 8, bool, ready) 19 | ETL_BFF_FIELD( 0: 0, bool, cmp_pd) 20 | ) 21 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/types.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_TYPES_H_INCLUDED 2 | #define _ETL_STM32F4XX_TYPES_H_INCLUDED 3 | 4 | #include "etl/armv7m/types.h" 5 | 6 | /* 7 | * Re-export ARMv7-M types in the stm32f4xx namespace for convenience. 8 | */ 9 | 10 | namespace etl { 11 | namespace stm32f4xx { 12 | 13 | using etl::armv7m::DoubleWord; 14 | using etl::armv7m::Word; 15 | using etl::armv7m::HalfWord; 16 | using etl::armv7m::Byte; 17 | 18 | } // namespace stm32f4xx 19 | } // namespace etl 20 | 21 | #endif // _ETL_STM32F4XX_TYPES_H_INCLUDED 22 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/usart.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_STM32F4XX_USART_H_INCLUDED 2 | #define _ETL_STM32F4XX_USART_H_INCLUDED 3 | 4 | #include "etl/stm32f4xx/types.h" 5 | 6 | namespace etl { 7 | namespace stm32f4xx { 8 | 9 | struct Usart { 10 | #define ETL_BFF_DEFINITION_FILE "etl/stm32f4xx/usart.reg" 11 | #include "etl/biffield/generate.h" 12 | #undef ETL_BFF_DEFINITION_FILE 13 | }; 14 | 15 | extern Usart usart1; 16 | extern Usart usart2; 17 | extern Usart usart3; 18 | extern Usart usart6; 19 | 20 | } // namespace stm32f4xx 21 | } // namespace etl 22 | 23 | #endif // _ETL_STM32F4XX_USART_H_INCLUDED 24 | -------------------------------------------------------------------------------- /Main/etl/stm32f4xx/usart.reg: -------------------------------------------------------------------------------- 1 | ETL_BFF_REG_RW(Word, sr, 2 | ETL_BFF_FIELD( 9: 9, bool, cts) 3 | ETL_BFF_FIELD( 8: 8, bool, lbd) 4 | ETL_BFF_FIELD( 7: 7, bool, txe) 5 | ETL_BFF_FIELD( 6: 6, bool, tc) 6 | ETL_BFF_FIELD( 5: 5, bool, rxne) 7 | ETL_BFF_FIELD( 4: 4, bool, idle) 8 | ETL_BFF_FIELD( 3: 3, bool, ore) 9 | ETL_BFF_FIELD( 2: 2, bool, nf) 10 | ETL_BFF_FIELD( 1: 1, bool, fe) 11 | ETL_BFF_FIELD( 0: 0, bool, pe) 12 | ) 13 | ETL_BFF_REG_RW(Word, dr, 14 | ETL_BFF_FIELD( 8: 0, unsigned, dr) 15 | ) 16 | ETL_BFF_REG_RW(Word, brr, 17 | ETL_BFF_FIELD(15: 4, unsigned, div_mantissa) 18 | ETL_BFF_FIELD( 3: 0, unsigned, div_fraction) 19 | ) 20 | ETL_BFF_REG_RW(Word, cr1, 21 | ETL_BFF_FIELD (15:15, bool, over8) 22 | ETL_BFF_FIELD (13:13, bool, ue) 23 | ETL_BFF_FIELD (12:12, bool, m) 24 | ETL_BFF_FIELD_E(11:11, bool, wake, 25 | ETL_BFF_ENUM(0, idle_line) 26 | ETL_BFF_ENUM(1, address_mark) 27 | ) 28 | ETL_BFF_FIELD (10:10, bool, pce) 29 | ETL_BFF_FIELD_E( 9: 9, bool, ps, 30 | ETL_BFF_ENUM(0, even) 31 | ETL_BFF_ENUM(1, odd) 32 | ) 33 | ETL_BFF_FIELD ( 8: 8, bool, peie) 34 | ETL_BFF_FIELD ( 7: 7, bool, txeie) 35 | ETL_BFF_FIELD ( 6: 6, bool, tcie) 36 | ETL_BFF_FIELD ( 5: 5, bool, rxneie) 37 | ETL_BFF_FIELD ( 4: 4, bool, idleie) 38 | ETL_BFF_FIELD ( 3: 3, bool, te) 39 | ETL_BFF_FIELD ( 2: 2, bool, re) 40 | ETL_BFF_FIELD_E( 1: 1, bool, rwu, 41 | ETL_BFF_ENUM(0, active) 42 | ETL_BFF_ENUM(1, mute) 43 | ) 44 | ETL_BFF_FIELD ( 0: 0, bool, sbk) 45 | ) 46 | ETL_BFF_REG_RW(Word, cr2, 47 | ETL_BFF_FIELD (14:14, bool, linen) 48 | ETL_BFF_FIELD_E(13:12, unsigned, stop, 49 | ETL_BFF_ENUM(0b00, one) 50 | ETL_BFF_ENUM(0b01, half) 51 | ETL_BFF_ENUM(0b10, two) 52 | ETL_BFF_ENUM(0b11, one_and_one_half) 53 | ) 54 | ETL_BFF_FIELD (11:11, bool, clken) 55 | ETL_BFF_FIELD_E(10:10, bool, cpol, 56 | ETL_BFF_ENUM(0, idle_low) 57 | ETL_BFF_ENUM(1, idle_high) 58 | ) 59 | ETL_BFF_FIELD_E( 9: 9, bool, cpha, 60 | ETL_BFF_ENUM(0, capture_on_first_edge) 61 | ETL_BFF_ENUM(1, capture_on_second_edge) 62 | ) 63 | ETL_BFF_FIELD ( 8: 8, bool, lbcl) 64 | ETL_BFF_FIELD ( 6: 6, bool, lbdie) 65 | ETL_BFF_FIELD ( 3: 0, unsigned, add) 66 | ) 67 | ETL_BFF_REG_RW(Word, cr3, 68 | ETL_BFF_FIELD_E(11:11, bool, onebit, 69 | ETL_BFF_ENUM(0, three_sample) 70 | ETL_BFF_ENUM(1, one_sample) 71 | ) 72 | ETL_BFF_FIELD (10:10, bool, ctsie) 73 | ETL_BFF_FIELD ( 9: 9, bool, ctse) 74 | ETL_BFF_FIELD ( 8: 8, bool, rtse) 75 | ETL_BFF_FIELD ( 7: 7, bool, dmat) 76 | ETL_BFF_FIELD ( 6: 6, bool, dmar) 77 | ETL_BFF_FIELD ( 5: 5, bool, scen) 78 | ETL_BFF_FIELD ( 4: 4, bool, nack) 79 | ETL_BFF_FIELD ( 3: 3, bool, hdsel) 80 | ETL_BFF_FIELD ( 2: 2, bool, irlp) 81 | ETL_BFF_FIELD ( 1: 1, bool, iren) 82 | ETL_BFF_FIELD ( 0: 0, bool, eie) 83 | ) 84 | ETL_BFF_REG_RW(Word, gtpr, ) 85 | -------------------------------------------------------------------------------- /Main/etl/type_constant.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_TYPE_CONSTANT_H_INCLUDED 2 | #define _ETL_TYPE_CONSTANT_H_INCLUDED 3 | 4 | namespace etl { 5 | 6 | /* 7 | * TypeConstant creates a type of trivial values associated with a given type. 8 | * This can be used to pass a placeholder for a type in a value context, 9 | * without any overhead that might be associated with creating an actual 10 | * instance of the type (or even a pointer). 11 | * 12 | * A TypeConstant is also a type-metafunction returning T, for use with 13 | * things like std::conditional. 14 | * 15 | * For compatibility, this exposes both std-style and etl-style names. 16 | */ 17 | template 18 | struct TypeConstant { 19 | using Type = T; 20 | using type = T; 21 | }; 22 | 23 | } // namespace etl 24 | 25 | #endif // _ETL_TYPE_CONSTANT_H_INCLUDED 26 | -------------------------------------------------------------------------------- /Main/etl/type_traits.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_TYPE_TRAITS_H_INCLUDED 2 | #define _ETL_TYPE_TRAITS_H_INCLUDED 3 | 4 | /* 5 | * Trait templates describing properties of types and providing basic 6 | * operations over types. 7 | * 8 | * Provides extensions to C++ . 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "etl/attribute_macros.h" 16 | #include "etl/invoke.h" 17 | #include "etl/type_constant.h" 18 | 19 | namespace etl { 20 | 21 | /******************************************************************************* 22 | * Promoting values to types 23 | */ 24 | 25 | // Shorthand for the common case of std::integral_constant 26 | template 27 | using BoolConstant = std::integral_constant; 28 | 29 | 30 | /******************************************************************************* 31 | * Obtaining (fake) values from types. 32 | */ 33 | 34 | /* 35 | * Stands in for operations that produce a value of type T (rvalue reference). 36 | * This function is never defined, and cannot be actually called. It's 37 | * intended for use in unevaluated contexts, like sizeof and decltype. 38 | * 39 | * Equivalent to std::declval, which is unfortunately in . We define 40 | * it here, rather than in , after libstdc++. 41 | */ 42 | template 43 | auto declval() -> typename std::add_rvalue_reference::type; 44 | 45 | 46 | /******************************************************************************* 47 | * Compile-time conditional behavior. 48 | */ 49 | 50 | /* 51 | * ConditionalT is a backport of C++14's conditional_t. 52 | */ 53 | template 54 | using ConditionalT = Invoke>; 55 | 56 | 57 | /******************************************************************************* 58 | * Operations on qualifiers. 59 | */ 60 | 61 | /* 62 | * MatchConst and MatchVolatile copy the const/volatile qualifiers from one 63 | * type onto another. MatchQualifiers does both. 64 | */ 65 | template 66 | struct MatchConst : public TypeConstant {}; 67 | 68 | template 69 | struct MatchConst : public TypeConstant {}; 70 | 71 | 72 | template 73 | struct MatchVolatile : public TypeConstant {}; 74 | 75 | template 76 | struct MatchVolatile 77 | : public TypeConstant {}; 78 | 79 | 80 | template 81 | using MatchQualifiers = 82 | MatchConst::Type>; 83 | 84 | 85 | /******************************************************************************* 86 | * Template metafunction versions of sizeof, alignof. 87 | */ 88 | 89 | template 90 | using SizeOf = std::integral_constant; 91 | 92 | template 93 | using AlignOf = std::integral_constant; 94 | 95 | /******************************************************************************* 96 | * Reasoning about type relations. 97 | */ 98 | 99 | /* 100 | * Type alias version of std::result_of. 101 | */ 102 | template 103 | using ResultOf = typename std::result_of::type; 104 | 105 | /* 106 | * Type alias version of std::common_type. 107 | */ 108 | template 109 | using CommonType = typename std::common_type::type; 110 | 111 | } // namespace etl 112 | 113 | #endif // _ETL_TYPE_TRAITS_H_INCLUDED 114 | -------------------------------------------------------------------------------- /Main/etl/utility.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETL_UTILITY_H_INCLUDED 2 | #define _ETL_UTILITY_H_INCLUDED 3 | 4 | /* 5 | * Type and scope manipulation operators that weren't interesting enough 6 | * to merit their own headers. 7 | * 8 | * Analog of C++ , which is not available in a freestanding 9 | * implementation (see discussion in n3256). 10 | */ 11 | 12 | #include 13 | 14 | #include "etl/attribute_macros.h" 15 | 16 | namespace etl { 17 | 18 | template 19 | ETL_INLINE 20 | constexpr T && forward(typename std::remove_reference::type & value) { 21 | return static_cast(value); 22 | } 23 | 24 | template 25 | ETL_INLINE 26 | constexpr T && forward(typename std::remove_reference::type && value) { 27 | return static_cast(value); 28 | } 29 | 30 | template 31 | ETL_INLINE 32 | constexpr typename std::remove_reference::type && move(T && value) { 33 | return static_cast::type &&>(value); 34 | } 35 | 36 | template 37 | void swap(T & a, T & b) { 38 | T intermediate = move(a); 39 | a = move(b); 40 | b = move(intermediate); 41 | } 42 | 43 | template 44 | void swap(T (&a)[count], T (&b)[count]) { 45 | for (std::size_t i = 0; i < count; ++i) { 46 | swap(a[i], b[i]); 47 | } 48 | } 49 | 50 | } // namespace etl 51 | 52 | #endif // _ETL_UTILITY_H_INCLUDED 53 | -------------------------------------------------------------------------------- /Main/m4vgalib/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 - 2014, Cliff L. Biffle 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /Main/m4vgalib/README.mkdn: -------------------------------------------------------------------------------- 1 | This library provides high-quality, high-resolution color graphics output from 2 | STM32F40x/1x microcontrollers, using very few external components. 3 | 4 | This repository contains only the reusable library bits. To try it out, or just 5 | see an example of how it's used, see the [m4vgalib-demos] repository. 6 | 7 | 8 | Brief Overview 9 | ============== 10 | 11 | The STM32F407 is a Cortex-M4 microcontroller that has neither a video 12 | controller, nor enough RAM for a framebuffer at any reasonable resolution. 13 | 14 | m4vgalib works around this to produce stable 800x600 (or 640x480) video with 15 | 256 colors. Instead of a video controller, m4vgalib uses two timers, one 16 | DMA controller, and a GPIO port. Instead of a framebuffer, m4vgalib uses a 17 | modular rasterization system that lets applications "race the beam" -- prepare 18 | video output on the fly from some compact representation. 19 | 20 | Out of the box, m4vgalib includes canned rasterizers for both palettized pixel 21 | graphics and attributed text graphics, with various formats and depths. 22 | Applications can change rasterizers at any scanline to achieve split-screen or 23 | raster effects. 24 | 25 | Even though m4vgalib is maintaining a 320Mb/s data stream on a processor not 26 | designed for anything of the sort, most of the CPU and hardware resources are 27 | left available to applications. To avoid introducing jitter, applications must 28 | only agree to keep their filthy hands off AHB1 during certain phases of 29 | execution. (Interrupts are available to notify the application of this.) 30 | 31 | The application runs as a "thread" parallel to m4vgalib, and it's even possible 32 | to run an application using an RTOS with a bit of porting effort. (Hint: the 33 | RTOS must coordinate with m4vgalib on the use of the PendSV handler.) 34 | 35 | 36 | [m4vgalib-demos]: https://github.com/cbiffle/m4vgalib-demos 37 | -------------------------------------------------------------------------------- /Main/m4vgalib/copy_words.S: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | 3 | #ifdef __ARM_PCS_VFP 4 | 5 | @ High-throughput block transfer using the FPU register set as a 128-byte 6 | @ buffer. 7 | @ 8 | @ This implementation exploits the IT Folding feature of the Cortex-M4. 9 | @ An IT instruction following a 16-bit Thumb instruction, when both are 10 | @ aligned into a 32-bit memory word, takes no additional cycles to issue. 11 | @ 12 | @ Arguments: 13 | @ r0 source address 14 | @ r1 destination address 15 | @ r2 number of words to transfer. 16 | .section .ramcode,"ax",%progbits 17 | .balign 4 18 | .global _Z10copy_wordsPKmPmm 19 | .thumb_func 20 | _Z10copy_wordsPKmPmm: 21 | @ Name our registers. 22 | src .req r0 23 | dst .req r1 24 | count .req r2 25 | 26 | @ The caller may have been using floating point. 27 | @ Save the callee-save portion of the register file. 28 | vpush {s16 - s31} @ 17 29 | 30 | @ "Warm up" the transfer engine, which wants to operate in units of 31 | @ 128 bytes, by making smaller transfers until count a multiple of 128. 32 | 33 | @ Special-case the single word transfer; the macro below won't work. 34 | lsrs.n count, #1 @ 1 35 | itt cs @ 0 (aligned) 36 | vldmcs.32 src!, {s0} @ 2 37 | vstmcs.32 dst!, {s0} @ 2 38 | 39 | @ Transfer n+1 words. 40 | .macro XFER n @ 5 + 2*n 41 | lsrs.n count, #1 @ 1 42 | itt cs @ 0 (aligned) 43 | vldmcs.32 src!, {s0 - s\n} @ 1+1+n 44 | vstmcs.32 dst!, {s0 - s\n} @ 1+1+n 45 | .endm 46 | 47 | XFER 1 @ 7 48 | XFER 3 @ 11 49 | XFER 7 @ 19 50 | XFER 15 @ 35 51 | 52 | @ Handle the case where we've been asked to transfer <32 words. 53 | @ In such a case, count will now be zero, and the Z flag will still 54 | @ be set from the last XFER. 55 | @ 56 | @ Force the branch to use a 32-bit instruction to preserve alignment 57 | @ of the loop branch below; this saves a cycle per time that branch 58 | @ is taken. 59 | @ 60 | @ Note that the target of this branch (at 1 below) is also aligned, 61 | @ saving a cycle on the rare escape path. 62 | beq.w 1f @ 1 (n.t.) 63 | 64 | @ All warmed up, transfer in units of 128 bytes. 65 | 0: vldm.32 src!, {s0 - s31} @ 33 66 | vstm.32 dst!, {s0 - s31} @ 33 67 | subs.n count, #1 @ 1 68 | bne.n 0b @ ~3 (taken) 69 | 70 | @ Restore FPU state. 71 | 1: vpop {s16 - s31} @ 17 72 | bx lr @ 1-3?? 73 | 74 | #else 75 | #error copy_words is not available for your architecture. 76 | #endif 77 | -------------------------------------------------------------------------------- /Main/m4vgalib/copy_words.h: -------------------------------------------------------------------------------- 1 | #ifndef COPY_WORDS_H 2 | #define COPY_WORDS_H 3 | 4 | #include "etl/armv7m/types.h" 5 | 6 | /* 7 | * Moves some number of aligned words using the fastest method I could think up. 8 | */ 9 | void copy_words(etl::armv7m::Word const *source, 10 | etl::armv7m::Word *dest, 11 | etl::armv7m::Word count); 12 | 13 | #endif // COPY_WORDS_H 14 | -------------------------------------------------------------------------------- /Main/m4vgalib/rasterizer.h: -------------------------------------------------------------------------------- 1 | #ifndef VGA_RASTERIZER_H 2 | #define VGA_RASTERIZER_H 3 | 4 | #include 5 | 6 | namespace vga { 7 | 8 | struct Timing; 9 | 10 | /* 11 | * A producer of pixels, one scanline at a time. Some rasterizers may 12 | * generate pixels procedurally; others may use a backing framebuffer or 13 | * other store. Either way, the rasterizer is responsible for either containing 14 | * the resources it needs or allocating them from the arena. 15 | */ 16 | class Rasterizer { 17 | public: 18 | typedef std::uint8_t Pixel; 19 | 20 | /* 21 | * Implementations of rasterize return RasterInfo describing how they 22 | * expect their output to be displayed. 23 | */ 24 | struct RasterInfo { 25 | // Number of black pixels to left of line. Negative offsets shift the 26 | // start of active video earlier than anticipated (closer to the hsync) 27 | // and may impinge on code running during hblank. 28 | int offset; 29 | 30 | // Number of valid pixels generated in render target. 31 | unsigned length; 32 | 33 | // Number of AHB cycles per pixel. The default value for this in the 34 | // current mode is given to the rasterizer; the rasterizer may alter it 35 | // in the result if desired. 36 | unsigned cycles_per_pixel; 37 | 38 | // How many times to repeat this line of raster output, after the first. 39 | unsigned repeat_lines; 40 | }; 41 | 42 | /* 43 | * Produces a single scanline of pixels into a scan buffer. Returns a 44 | * RasterInfo instance describing what was done. 45 | * 46 | * The line_number is relative to the first displayed line in the current 47 | * mode, not necessarily the first line handled by this Rasterizer! 48 | */ 49 | virtual RasterInfo rasterize(unsigned cycles_per_pixel, 50 | unsigned line_number, 51 | Pixel *raster_target) = 0; 52 | 53 | protected: 54 | ~Rasterizer() = default; 55 | }; 56 | 57 | } // namespace vga 58 | 59 | #endif // VGA_RASTERIZER_H 60 | -------------------------------------------------------------------------------- /Main/m4vgalib/timing.cc: -------------------------------------------------------------------------------- 1 | #include "timing.h" 2 | 3 | namespace vga { 4 | 5 | Timing const timing_vesa_640x480_60hz = { 6 | .clock_config = { 7 | .crystal_hz = 8000000, // 8 MHz 8 | .crystal_divisor = 4, // divide down to 2Mhz 9 | .vco_multiplier = 151, // multiply up to 302MHz VCO 10 | .general_divisor = 2, // divide VCO by 2 for 151MHz CPU clock 11 | .pll48_divisor = 7, // divide VCO by 7 for 48MHz-ish SDIO clock 12 | 13 | .ahb_divisor = 1, // run AHB at CPU rate. 14 | .apb1_divisor = 4, // divide CPU clock by 4 for 37.75MHz APB1 clock. 15 | .apb2_divisor = 2, // divide CPU clock by 2 for 75.5MHz APB2 clock. 16 | 17 | .flash_latency = 5, // 5 wait states for 151MHz at 3.3V. 18 | }, 19 | 20 | .cycles_per_pixel = 6, 21 | 22 | .line_pixels = 800, 23 | .sync_pixels = 96, 24 | .back_porch_pixels = 48, //48, 25 | .video_lead = 25, // 25, 26 | .video_pixels = 640, 27 | .hsync_polarity = Timing::Polarity::negative, 28 | 29 | .vsync_start_line = 10, 30 | .vsync_end_line = 10 + 2, 31 | .video_start_line = 10 + 2 + 33, 32 | .video_end_line = 10 + 2 + 33 + 480, 33 | .vsync_polarity = Timing::Polarity::negative, 34 | }; 35 | 36 | Timing const timing_vesa_800x600_60hz = { 37 | .clock_config = { 38 | .crystal_hz = 8000000, // external crystal Hz 39 | .crystal_divisor = 4, // divide down to 2Mhz 40 | .vco_multiplier = 160, // multiply up to 320MHz VCO 41 | .general_divisor = 2, // divide by 2 for 160MHz CPU clock 42 | .pll48_divisor = 7, // divide by 7 for 48MHz-ish SDIO clock 43 | .ahb_divisor = 1, // divide CPU clock by 1 for 160MHz AHB clock 44 | .apb1_divisor = 4, // divide CPU clock by 4 for 40MHz APB1 clock. 45 | .apb2_divisor = 2, // divide CPU clock by 2 for 80MHz APB2 clock. 46 | 47 | .flash_latency = 5, // 5 wait states for 160MHz at 3.3V. 48 | }, 49 | 50 | .cycles_per_pixel = 4, 51 | 52 | .line_pixels = 1056, 53 | .sync_pixels = 128, 54 | .back_porch_pixels = 88, // 88, 55 | .video_lead = 19, // 19, 56 | .video_pixels = 800, 57 | .hsync_polarity = Timing::Polarity::positive, 58 | 59 | .vsync_start_line = 1, 60 | .vsync_end_line = 1 + 4, 61 | .video_start_line = 1 + 4 + 23, 62 | .video_end_line = 1 + 4 + 23 + 600, 63 | .vsync_polarity = Timing::Polarity::positive, 64 | }; 65 | 66 | Timing const timing_800x600_56hz = { 67 | .clock_config = { 68 | .crystal_hz = 8000000, // external crystal Hz 69 | .crystal_divisor = 4, // divide down to 2Mhz 70 | .vco_multiplier = 144, // multiply up to 288MHz VCO 71 | .general_divisor = 2, // divide by 2 for 144MHz CPU clock 72 | .pll48_divisor = 6, // divide by 6 for 48MHz SDIO clock 73 | .ahb_divisor = 1, // divide CPU clock by 1 for 144MHz AHB clock 74 | .apb1_divisor = 4, // divide CPU clock by 4 for 36MHz APB1 clock. 75 | .apb2_divisor = 2, // divide CPU clock by 2 for 72MHz APB2 clock. 76 | 77 | .flash_latency = 4, // 4 wait states for 144MHz at 3.3V. 78 | }, 79 | 80 | .cycles_per_pixel = 4, 81 | 82 | .line_pixels = 1024, 83 | .sync_pixels = 72, 84 | .back_porch_pixels = 128, 85 | .video_lead = 22, 86 | .video_pixels = 800, 87 | .hsync_polarity = Timing::Polarity::positive, 88 | 89 | .vsync_start_line = 1, 90 | .vsync_end_line = 1 + 2, 91 | .video_start_line = 1 + 2 + 22, 92 | .video_end_line = 1 + 2 + 22 + 600, 93 | .vsync_polarity = Timing::Polarity::positive, 94 | }; 95 | 96 | } // namespace vga 97 | -------------------------------------------------------------------------------- /Main/m4vgalib/timing.h: -------------------------------------------------------------------------------- 1 | #ifndef VGA_TIMING_H 2 | #define VGA_TIMING_H 3 | 4 | #include 5 | 6 | #include "etl/stm32f4xx/rcc.h" 7 | 8 | namespace vga { 9 | 10 | /* 11 | * Describes the horizontal and vertical timing for a display mode, including 12 | * the outer bounds of active video. 13 | */ 14 | struct Timing { 15 | enum class Polarity { 16 | positive = 0, 17 | negative = 1, 18 | }; 19 | 20 | /* 21 | * The pixel clock is derived from the CPU clock by a fixed multiplier 22 | * (below), making the CPU clock configuration an integral part of the video 23 | * timing. 24 | */ 25 | etl::stm32f4xx::ClockConfig clock_config; 26 | 27 | /* 28 | * Number of AHB cycles per pixel clock cycle. Different scanout strategies 29 | * are invoked depending on this value. Historically this was assumed to be 30 | * 4, but if you want a higher CPU : pixel clock ratio, go for it. 31 | * 32 | * Note that no current scanout strategy can achieve fewer than 4 AHB cycles 33 | * per pixel clock; attempt this and you'll hit an assert in configure_timing. 34 | */ 35 | std::uint16_t cycles_per_pixel; 36 | 37 | /* 38 | * Horizontal timing, expressed in pixels. 39 | * 40 | * The horizontal sync pulse implicitly starts at pixel zero of the line. 41 | * 42 | * Some of this information is redundant; it's stored this way to avoid 43 | * having to rederive it in the driver. 44 | */ 45 | std::uint16_t line_pixels; // Total, including blanking. 46 | std::uint16_t sync_pixels; // Length of pulse. 47 | std::uint16_t back_porch_pixels; // Between end of sync and start of video. 48 | std::uint16_t video_lead; // Fudge factor: nudge DMA back in time. 49 | std::uint16_t video_pixels; // Maximum pixels in active video. 50 | Polarity hsync_polarity; // Polarity of hsync pulse. 51 | 52 | /* 53 | * Vertical timing, expressed in lines. 54 | * 55 | * Because vertical timing is done in software, it's a little more flexible 56 | * than horizontal timing. 57 | */ 58 | std::uint16_t vsync_start_line; // Top edge of sync pulse. 59 | std::uint16_t vsync_end_line; // Bottom edge of sync pulse. 60 | std::uint16_t video_start_line; // Top edge of active video. 61 | std::uint16_t video_end_line; // Bottom edge of active video. 62 | Polarity vsync_polarity; // Polarity of vsync pulse. 63 | }; 64 | 65 | /* 66 | * Canned timings for common modes at the assumed 8MHz crystal frequency. 67 | * 68 | * These use the highest CPU frequency at which we can reasonably approximate 69 | * the standard pixel clock (to within about 0.05%). 70 | */ 71 | extern Timing const timing_vesa_640x480_60hz; 72 | extern Timing const timing_vesa_800x600_60hz; 73 | 74 | // This non-standard mode is useful if you need exactly 48 MHz for USB clock 75 | extern Timing const timing_800x600_56hz; 76 | 77 | } // namespace vga 78 | 79 | #endif // VGA_TIMING_H 80 | -------------------------------------------------------------------------------- /Main/m4vgalib/vgaConfig.h: -------------------------------------------------------------------------------- 1 | #ifndef VGA_VGACONFIG_H 2 | #define VGA_VGACONFIG_H 3 | 4 | #include 5 | #include "stm32f4xx_hal.h" 6 | 7 | #ifdef BOARD2 8 | 9 | // PD0 Red 1 10 | // PD1 Red 2 11 | // PD2 Green 1 12 | // PD3 Green 2 13 | // PD4 Blue 1 14 | // PD5 Blue 2 15 | // PB6 HSync // TIM4CH1 16 | // PB7 VSync 17 | #define VIDEO_GPIO gpiod 18 | #define VIDEO_GPIO_MASK 0x003F 19 | #define VIDEO_GPIO_ODR (GPIOD_BASE+20) 20 | #define SYNC_GPIO gpiob 21 | #define HSYNC_PIN Gpio::p6 22 | #define VSYNC_PIN Gpio::p7 23 | 24 | #else 25 | 26 | // PE8 Red 1 27 | // PE9 Red 2 28 | // PE10 Green 1 29 | // PE11 Green 2 30 | // PE12 Blue 1 31 | // PE13 Blue 2 32 | // PD15 HSync // TIM4CH4 33 | // PD14 VSync 34 | #define VIDEO_GPIO gpioe 35 | #define VIDEO_GPIO_MASK 0x3F00 36 | #define VIDEO_GPIO_ODR (GPIOE_BASE+21) 37 | #define SYNC_GPIO gpiod 38 | #define HSYNC_PIN Gpio::p15 39 | #define VSYNC_PIN Gpio::p14 40 | 41 | #endif 42 | 43 | #define IRQ extern "C" 44 | #define etl_stm32f4xx_tim3_handler TIM3_IRQHandler 45 | #define etl_stm32f4xx_tim4_handler TIM4_IRQHandler 46 | #define etl_armv7m_pend_sv_handler PendSV_Handler 47 | #define arena_reset() 48 | 49 | #endif // VGA_VGA_H 50 | -------------------------------------------------------------------------------- /Main/sdCard/bsp_driver_sd.h: -------------------------------------------------------------------------------- 1 | /* Define to prevent recursive inclusion -------------------------------------*/ 2 | #ifndef __STM32F4_SD_H 3 | #define __STM32F4_SD_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" 7 | { 8 | #endif 9 | 10 | /* Includes ------------------------------------------------------------------*/ 11 | #include "stm32f4xx_hal.h" 12 | #include "ff_gen_drv.h" 13 | 14 | /* Exported types --------------------------------------------------------*/ 15 | /** 16 | * @brief SD Card information structure 17 | */ 18 | #define BSP_SD_CardInfo HAL_SD_CardInfoTypeDef 19 | 20 | /* Exported constants --------------------------------------------------------*/ 21 | /** 22 | * @brief SD status structure definition 23 | */ 24 | #define MSD_OK ((uint8_t)0x00) 25 | #define MSD_ERROR ((uint8_t)0x01) 26 | 27 | /** 28 | * @brief SD transfer state definition 29 | */ 30 | #define SD_TRANSFER_OK ((uint8_t)0x00) 31 | #define SD_TRANSFER_BUSY ((uint8_t)0x01) 32 | 33 | #define SD_PRESENT ((uint8_t)0x01) 34 | #define SD_NOT_PRESENT ((uint8_t)0x00) 35 | #define SD_DATATIMEOUT ((uint32_t)100000000) 36 | 37 | /* Exported functions --------------------------------------------------------*/ 38 | uint8_t BSP_SD_Init(void); 39 | uint8_t BSP_SD_ITConfig(void); 40 | void BSP_SD_DetectIT(void); 41 | void BSP_SD_DetectCallback(void); 42 | uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, 43 | uint32_t NumOfBlocks, uint32_t Timeout); 44 | uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, 45 | uint32_t NumOfBlocks, uint32_t Timeout); 46 | uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, 47 | uint32_t NumOfBlocks); 48 | uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, 49 | uint32_t NumOfBlocks); 50 | uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr); 51 | void BSP_SD_IRQHandler(void); 52 | void BSP_SD_DMA_Tx_IRQHandler(void); 53 | void BSP_SD_DMA_Rx_IRQHandler(void); 54 | uint8_t BSP_SD_GetCardState(void); 55 | void BSP_SD_GetCardInfo(HAL_SD_CardInfoTypeDef *CardInfo); 56 | uint8_t BSP_SD_IsDetected(void); 57 | 58 | /* These functions can be modified in case the current settings (e.g. DMA stream) 59 | need to be changed for specific application needs */ 60 | void BSP_SD_AbortCallback(void); 61 | void BSP_SD_WriteCpltCallback(void); 62 | void BSP_SD_ReadCpltCallback(void); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif /* __STM32F4_SD_H */ 69 | -------------------------------------------------------------------------------- /Main/sdCard/fatFS/diskio.h: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------/ 2 | / Low level disk interface modlue include file (C)ChaN, 2014 / 3 | /-----------------------------------------------------------------------*/ 4 | 5 | #ifndef _DISKIO_DEFINED 6 | #define _DISKIO_DEFINED 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include "ff.h" 13 | 14 | /* Status of Disk Functions */ 15 | typedef BYTE DSTATUS; 16 | 17 | /* Results of Disk Functions */ 18 | typedef enum { 19 | RES_OK = 0, /* 0: Successful */ 20 | RES_ERROR, /* 1: R/W Error */ 21 | RES_WRPRT, /* 2: Write Protected */ 22 | RES_NOTRDY, /* 3: Not Ready */ 23 | RES_PARERR /* 4: Invalid Parameter */ 24 | } DRESULT; 25 | 26 | 27 | /*---------------------------------------*/ 28 | /* Prototypes for disk control functions */ 29 | 30 | 31 | DSTATUS disk_initialize (BYTE pdrv); 32 | DSTATUS disk_status (BYTE pdrv); 33 | DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count); 34 | DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); 35 | DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); 36 | 37 | 38 | /* Disk Status Bits (DSTATUS) */ 39 | 40 | #define STA_NOINIT 0x01 /* Drive not initialized */ 41 | #define STA_NODISK 0x02 /* No medium in the drive */ 42 | #define STA_PROTECT 0x04 /* Write protected */ 43 | 44 | 45 | /* Command code for disk_ioctrl fucntion */ 46 | 47 | /* Generic command (Used by FatFs) */ 48 | #define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */ 49 | #define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */ 50 | #define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */ 51 | #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */ 52 | #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */ 53 | 54 | /* Generic command (Not used by FatFs) */ 55 | #define CTRL_POWER 5 /* Get/Set power status */ 56 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */ 57 | #define CTRL_EJECT 7 /* Eject media */ 58 | #define CTRL_FORMAT 8 /* Create physical format on the media */ 59 | 60 | /* MMC/SDC specific ioctl command */ 61 | #define MMC_GET_TYPE 10 /* Get card type */ 62 | #define MMC_GET_CSD 11 /* Get CSD */ 63 | #define MMC_GET_CID 12 /* Get CID */ 64 | #define MMC_GET_OCR 13 /* Get OCR */ 65 | #define MMC_GET_SDSTAT 14 /* Get SD status */ 66 | #define ISDIO_READ 55 /* Read data form SD iSDIO register */ 67 | #define ISDIO_WRITE 56 /* Write data to SD iSDIO register */ 68 | #define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */ 69 | 70 | /* ATA/CF specific ioctl command */ 71 | #define ATA_GET_REV 20 /* Get F/W revision */ 72 | #define ATA_GET_MODEL 21 /* Get model name */ 73 | #define ATA_GET_SN 22 /* Get serial number */ 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /Main/sdCard/fatFS/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef FF_INTEGER 6 | #define FF_INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | typedef unsigned __int64 QWORD; 12 | 13 | #else /* Embedded platform */ 14 | 15 | /* These types MUST be 16-bit or 32-bit */ 16 | typedef int INT; 17 | typedef unsigned int UINT; 18 | 19 | /* This type MUST be 8-bit */ 20 | typedef unsigned char BYTE; 21 | 22 | /* These types MUST be 16-bit */ 23 | typedef short SHORT; 24 | typedef unsigned short WORD; 25 | typedef unsigned short WCHAR; 26 | 27 | /* These types MUST be 32-bit */ 28 | typedef long LONG; 29 | typedef unsigned long DWORD; 30 | 31 | /* This type MUST be 64-bit (Remove this for ANSI C (C89) compatibility) */ 32 | typedef unsigned long long QWORD; 33 | 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Main/sdCard/fatfs.c: -------------------------------------------------------------------------------- 1 | #include "fatfs.h" 2 | 3 | uint8_t retSD; /* Return value for SD */ 4 | char SDPath[4]; /* SD logical drive path */ 5 | FATFS SDFatFS; /* File system object for SD logical drive */ 6 | FIL SDFile; /* File object for SD */ 7 | extern RTC_HandleTypeDef hrtc; 8 | 9 | void MX_FATFS_Init(void) 10 | { 11 | #ifdef BOARD2 12 | retSD = FATFS_LinkDriver(&FlashDriver, SDPath); 13 | #else 14 | /*## FatFS: Link the SD driver ###########################*/ 15 | retSD = FATFS_LinkDriver(&SD_Driver, SDPath); 16 | #endif 17 | } 18 | 19 | /** 20 | * @brief Gets Time from RTC 21 | * @param None 22 | * @retval Time in DWORD 23 | */ 24 | DWORD get_fattime(void) 25 | { 26 | RTC_TimeTypeDef time; 27 | RTC_DateTypeDef date; 28 | HAL_RTC_GetTime(&hrtc, &time, RTC_FORMAT_BIN); 29 | HAL_RTC_GetDate(&hrtc, &date, RTC_FORMAT_BIN); 30 | 31 | return ((DWORD)(date.Year + 20) << 25) 32 | | ((DWORD)date.Month << 21) 33 | | ((DWORD)date.Date << 16) 34 | | ((DWORD)time.Hours << 11) 35 | | ((DWORD)time.Minutes << 5) 36 | | ((DWORD)time.Seconds >> 1); 37 | } 38 | -------------------------------------------------------------------------------- /Main/sdCard/fatfs.h: -------------------------------------------------------------------------------- 1 | /* Define to prevent recursive inclusion -------------------------------------*/ 2 | #ifndef __fatfs_H 3 | #define __fatfs_H 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | #include "fatFS/ff.h" 10 | #include "ff_gen_drv.h" 11 | #include "sd_diskio.h" /* defines SD_Driver as external */ 12 | #include "flash_diskio.h" /* defines FlashDriver as external */ 13 | 14 | extern uint8_t retSD; /* Return value for SD */ 15 | extern char SDPath[4]; /* SD logical drive path */ 16 | extern FATFS SDFatFS; /* File system object for SD logical drive */ 17 | extern FIL SDFile; /* File object for SD */ 18 | 19 | void MX_FATFS_Init(void); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | #endif /*__fatfs_H */ 25 | -------------------------------------------------------------------------------- /Main/sdCard/ff_gen_drv.c: -------------------------------------------------------------------------------- 1 | /* Includes ------------------------------------------------------------------*/ 2 | #include "ff_gen_drv.h" 3 | 4 | /* Private typedef -----------------------------------------------------------*/ 5 | /* Private define ------------------------------------------------------------*/ 6 | /* Private variables ---------------------------------------------------------*/ 7 | Disk_drvTypeDef disk = 8 | { 9 | { 0 }, 10 | { 0 }, 11 | { 0 }, 0 }; 12 | 13 | /* Private function prototypes -----------------------------------------------*/ 14 | /* Private functions ---------------------------------------------------------*/ 15 | 16 | /** 17 | * @brief Links a compatible diskio driver/lun id and increments the number of active 18 | * linked drivers. 19 | * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits. 20 | * @param drv: pointer to the disk IO Driver structure 21 | * @param path: pointer to the logical drive path 22 | * @param lun : only used for USB Key Disk to add multi-lun management 23 | else the parameter must be equal to 0 24 | * @retval Returns 0 in case of success, otherwise 1. 25 | */ 26 | uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path, 27 | uint8_t lun) 28 | { 29 | uint8_t ret = 1; 30 | uint8_t DiskNum = 0; 31 | 32 | if (disk.nbr < FF_VOLUMES) 33 | { 34 | disk.is_initialized[disk.nbr] = 0; 35 | disk.drv[disk.nbr] = drv; 36 | disk.lun[disk.nbr] = lun; 37 | DiskNum = disk.nbr++; 38 | path[0] = DiskNum + '0'; 39 | path[1] = ':'; 40 | path[2] = '/'; 41 | path[3] = 0; 42 | ret = 0; 43 | } 44 | 45 | return ret; 46 | } 47 | 48 | /** 49 | * @brief Links a compatible diskio driver and increments the number of active 50 | * linked drivers. 51 | * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits 52 | * @param drv: pointer to the disk IO Driver structure 53 | * @param path: pointer to the logical drive path 54 | * @retval Returns 0 in case of success, otherwise 1. 55 | */ 56 | uint8_t FATFS_LinkDriver(const Diskio_drvTypeDef *drv, char *path) 57 | { 58 | return FATFS_LinkDriverEx(drv, path, 0); 59 | } 60 | 61 | /** 62 | * @brief Unlinks a diskio driver and decrements the number of active linked 63 | * drivers. 64 | * @param path: pointer to the logical drive path 65 | * @param lun : not used 66 | * @retval Returns 0 in case of success, otherwise 1. 67 | */ 68 | uint8_t FATFS_UnLinkDriverEx(char *path, uint8_t lun) 69 | { 70 | uint8_t DiskNum = 0; 71 | uint8_t ret = 1; 72 | 73 | if (disk.nbr >= 1) 74 | { 75 | DiskNum = path[0] - '0'; 76 | if (disk.drv[DiskNum] != 0) 77 | { 78 | disk.drv[DiskNum] = 0; 79 | disk.lun[DiskNum] = 0; 80 | disk.nbr--; 81 | ret = 0; 82 | } 83 | } 84 | 85 | return ret; 86 | } 87 | 88 | /** 89 | * @brief Unlinks a diskio driver and decrements the number of active linked 90 | * drivers. 91 | * @param path: pointer to the logical drive path 92 | * @retval Returns 0 in case of success, otherwise 1. 93 | */ 94 | uint8_t FATFS_UnLinkDriver(char *path) 95 | { 96 | return FATFS_UnLinkDriverEx(path, 0); 97 | } 98 | 99 | /** 100 | * @brief Gets number of linked drivers to the FatFs module. 101 | * @param None 102 | * @retval Number of attached drivers. 103 | */ 104 | uint8_t FATFS_GetAttachedDriversNbr(void) 105 | { 106 | return disk.nbr; 107 | } 108 | -------------------------------------------------------------------------------- /Main/sdCard/ff_gen_drv.h: -------------------------------------------------------------------------------- 1 | /* Define to prevent recursive inclusion -------------------------------------*/ 2 | #ifndef __FF_GEN_DRV_H 3 | #define __FF_GEN_DRV_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" 7 | { 8 | #endif 9 | 10 | /* Includes ------------------------------------------------------------------*/ 11 | #include 12 | #include "fatFS/diskio.h" 13 | #include "fatFS/ff.h" 14 | 15 | #define _USE_WRITE 1 /* 1: Enable disk_write function */ 16 | #define _USE_IOCTL 1 /* 1: Enable disk_ioctl function */ 17 | 18 | /* Exported types ------------------------------------------------------------*/ 19 | 20 | /** 21 | * @brief Disk IO Driver structure definition 22 | */ 23 | typedef struct 24 | { 25 | DSTATUS (*disk_initialize)(BYTE); /*!< Initialize Disk Drive */ 26 | DSTATUS (*disk_status)(BYTE); /*!< Get Disk Status */ 27 | DRESULT (*disk_read)(BYTE, BYTE*, DWORD, UINT); /*!< Read Sector(s) */ 28 | #if _USE_WRITE == 1 29 | DRESULT (*disk_write)(BYTE, const BYTE*, DWORD, UINT); /*!< Write Sector(s) when _USE_WRITE = 0 */ 30 | #endif /* _USE_WRITE == 1 */ 31 | #if _USE_IOCTL == 1 32 | DRESULT (*disk_ioctl)(BYTE, BYTE, void*); /*!< I/O control operation when _USE_IOCTL = 1 */ 33 | #endif /* _USE_IOCTL == 1 */ 34 | 35 | } Diskio_drvTypeDef; 36 | 37 | /** 38 | * @brief Global Disk IO Drivers structure definition 39 | */ 40 | typedef struct 41 | { 42 | uint8_t is_initialized[FF_VOLUMES]; 43 | const Diskio_drvTypeDef *drv[FF_VOLUMES]; 44 | uint8_t lun[FF_VOLUMES]; 45 | volatile uint8_t nbr; 46 | } Disk_drvTypeDef; 47 | 48 | /* Exported constants --------------------------------------------------------*/ 49 | /* Exported macro ------------------------------------------------------------*/ 50 | /* Exported functions ------------------------------------------------------- */ 51 | uint8_t FATFS_LinkDriver(const Diskio_drvTypeDef *drv, char *path); 52 | uint8_t FATFS_UnLinkDriver(char *path); 53 | uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path, BYTE lun); 54 | uint8_t FATFS_UnLinkDriverEx(char *path, BYTE lun); 55 | uint8_t FATFS_GetAttachedDriversNbr(void); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* __FF_GEN_DRV_H */ 62 | 63 | -------------------------------------------------------------------------------- /Main/sdCard/flash_diskio.c: -------------------------------------------------------------------------------- 1 | /* Includes ------------------------------------------------------------------*/ 2 | #include 3 | #include "ff_gen_drv.h" 4 | #include "sd_diskio.h" 5 | 6 | #define START_ADDRESS (FLASH_BASE+0x80000) 7 | #define SIZE_IN_SECTORS 1024 8 | #define SECTOR_SIZE 512 9 | 10 | /* Private variables ---------------------------------------------------------*/ 11 | /* Disk status */ 12 | static volatile DSTATUS Stat = STA_NOINIT; 13 | 14 | DSTATUS FlashInitialize(BYTE); 15 | DSTATUS FlashStatus(BYTE); 16 | DRESULT FlashRead(BYTE, BYTE*, DWORD, UINT); 17 | 18 | const Diskio_drvTypeDef FlashDriver = 19 | { FlashInitialize, FlashStatus, FlashRead }; 20 | 21 | /** 22 | * @brief Initializes a Drive 23 | * @param lun : not used 24 | * @retval DSTATUS: Operation status 25 | */ 26 | DSTATUS FlashInitialize(BYTE lun) 27 | { 28 | Stat = ~STA_NOINIT; 29 | return Stat; 30 | } 31 | 32 | /** 33 | * @brief Gets Disk Status 34 | * @param lun : not used 35 | * @retval DSTATUS: Operation status 36 | */ 37 | DSTATUS FlashStatus(BYTE lun) 38 | { 39 | return Stat; 40 | } 41 | 42 | /** 43 | * @brief Reads Sector(s) 44 | * @param lun : not used 45 | * @param *buff: Data buffer to store read data 46 | * @param sector: Sector address (LBA) 47 | * @param count: Number of sectors to read (1..128) 48 | * @retval DRESULT: Operation result 49 | */ 50 | DRESULT FlashRead(BYTE lun, BYTE *buff, DWORD sector, UINT count) 51 | { 52 | if (sector + count > SIZE_IN_SECTORS) 53 | { 54 | return RES_ERROR; 55 | } 56 | 57 | memcpy(buff, (const void *)(START_ADDRESS + sector * SECTOR_SIZE), count * SECTOR_SIZE); 58 | 59 | return RES_OK; 60 | } 61 | -------------------------------------------------------------------------------- /Main/sdCard/flash_diskio.h: -------------------------------------------------------------------------------- 1 | #ifndef __FLASH_DISKIO_H 2 | #define __FLASH_DISKIO_H 3 | 4 | /* Includes ------------------------------------------------------------------*/ 5 | #include "bsp_driver_sd.h" 6 | /* Exported types ------------------------------------------------------------*/ 7 | /* Exported constants --------------------------------------------------------*/ 8 | /* Exported functions ------------------------------------------------------- */ 9 | extern const Diskio_drvTypeDef FlashDriver; 10 | 11 | #endif /* __FLASH_DISKIO_H */ 12 | -------------------------------------------------------------------------------- /Main/sdCard/sd_diskio.h: -------------------------------------------------------------------------------- 1 | /* Define to prevent recursive inclusion -------------------------------------*/ 2 | #ifndef __SD_DISKIO_H 3 | #define __SD_DISKIO_H 4 | 5 | /* Includes ------------------------------------------------------------------*/ 6 | #include "bsp_driver_sd.h" 7 | /* Exported types ------------------------------------------------------------*/ 8 | /* Exported constants --------------------------------------------------------*/ 9 | /* Exported functions ------------------------------------------------------- */ 10 | extern const Diskio_drvTypeDef SD_Driver; 11 | 12 | #endif /* __SD_DISKIO_H */ 13 | -------------------------------------------------------------------------------- /Main/startup.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "startup.h" 5 | #include "Emulator.h" 6 | #include "SDCard.h" 7 | #include "Emulator/z80main.h" 8 | #include "Keyboard/ps2Keyboard.h" 9 | 10 | extern "C" void initialize() 11 | { 12 | initializeVideo(); 13 | 14 | // SD card read / write LED 15 | GPIO_InitTypeDef GPIO_InitStruct; 16 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 17 | GPIO_InitStruct.Pull = GPIO_PULLUP; 18 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 19 | #ifdef BOARD2 20 | __HAL_RCC_GPIOE_CLK_ENABLE(); 21 | GPIO_InitStruct.Pin = GPIO_PIN_0; 22 | HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); 23 | HAL_GPIO_WritePin(GPIOE, GPIO_PIN_0, GPIO_PIN_SET); 24 | #else 25 | __HAL_RCC_GPIOA_CLK_ENABLE(); 26 | GPIO_InitStruct.Pin = GPIO_PIN_6; 27 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 28 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET); 29 | #endif 30 | } 31 | 32 | extern "C" void setup() 33 | { 34 | startVideo(); 35 | 36 | // Initialize PS2 Keyboard 37 | Ps2_Initialize(); 38 | 39 | // Initialize Spectrum emulator 40 | zx_setup(&MainScreen); 41 | 42 | showHelp(); 43 | } 44 | 45 | extern "C" void loop() 46 | { 47 | if (loadSnapshotLoop()) 48 | { 49 | return; 50 | } 51 | 52 | if (saveSnapshotLoop()) 53 | { 54 | return; 55 | } 56 | 57 | if (showKeyboardLoop()) 58 | { 59 | return; 60 | } 61 | 62 | if (setDateTimeLoop()) 63 | { 64 | return; 65 | } 66 | 67 | int32_t result = zx_loop(); 68 | switch (result) 69 | { 70 | case KEY_ESC: 71 | clearHelp(); 72 | break; 73 | 74 | case KEY_F1: 75 | toggleHelp(); 76 | break; 77 | 78 | #ifndef BOARD2 79 | case KEY_F2: 80 | if (!saveSnapshotSetup()) 81 | { 82 | showErrorMessage("Cannot initialize SD card"); 83 | } 84 | break; 85 | #endif 86 | 87 | case KEY_F3: 88 | if (!loadSnapshotSetup()) 89 | { 90 | showErrorMessage("Error when loading from SD card"); 91 | } 92 | break; 93 | 94 | case KEY_F5: 95 | zx_reset(); 96 | showHelp(); 97 | break; 98 | 99 | #ifndef BOARD2 100 | case KEY_F6: 101 | setDateTimeSetup(); 102 | break; 103 | #endif 104 | 105 | case KEY_F10: 106 | showKeyboardSetup(); 107 | break; 108 | 109 | case KEY_F12: 110 | showRegisters(); 111 | break; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Main/startup.h: -------------------------------------------------------------------------------- 1 | #ifndef __STARTUP_H__ 2 | #define __STARTUP_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | void initialize(); 10 | void setup(); 11 | void loop(); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif /* __STARTUP_H__ */ 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # stm32f407-z80emu 2 | Spectrum ZX 48K emulator (using STM32F407 microcontroller) 3 | 4 | ![Breadboard](https://raw.githubusercontent.com/abelykh0/stm32f407-z80emu/master/doc/stm32f407-z80emu.jpg) 5 | 6 | ## What it can do 7 | * Emulate Spectrum ZX 48K 8 | * Load snapshot in .Z80 format from SD card 9 | * Save snapshot in .Z80 format to SD card 10 | * Output some sounds to USB MIDI 11 | 12 | ZX Spectrum Emulator on STM32F407 15 | 16 | Video 17 | 18 | ## Installation 19 | If you want to try my project, this is the only part that you need. 20 | 21 | | Hardware | Qty| 22 | | ------------- | -----:| 23 | | [Black F407VET6](https://stm32-base.org/boards/STM32F407VET6-STM32-F4VE-V2.0) board | 1 24 | | VGA connector | 1 25 | | PS/2 Keyboard | 1 26 | | Power supply 5V DC for keyboard | 1 27 | | Resistors 470 Ohm | 3 28 | | Resistors 680 Ohm | 3 29 | | Resistors 2.2 KOhm | 2 30 | | Resistors 3.3 KOhm | 2 31 | | Breadboard | 1 32 | | Jumper wires | 18 33 | | ST-Link v2 or clone | 1 34 | 35 | Software: Install free IDE [STM32CubeIDE](https://www.st.com/en/development-tools/stm32cubeide.html/). I am using Windows 10, however STMicroelectronics claims that it also supports Linux and Mac. 36 | 37 | How to connect wires: 38 | 39 | | PIN | Description | Connect To | Output | 40 | | --- | ----------- | ---------- | ------ | 41 | | PE8 | Red 1 | Resistor 470 Ohm | VGA red (1) 42 | | PE9 | Red 2 | Resistor 680 Ohm | VGA red (1) 43 | | PE10 | Green 1 | Resistor 470 Ohm | VGA green (2) 44 | | PE11 | Green 2 | Resistor 680 Ohm | VGA green (2) 45 | | PE12 | Blue 1 | Resistor 470 Ohm | VGA blue (3) 46 | | PE13 | Blue 2 | Resistor 680 Ohm | VGA blue (3) 47 | | PD15 | HSync | | VGA HSync (13) 48 | | PD14 | VSync | | VGA VSync (14) 49 | | PB14 | CLK | Resistor 2K2 to keyboard CLK and resistor 3K3 to GND 50 | | PB13 | DATA | Resistor 2K2 to keyboard DATA and resistor 3K3 to GND 51 | | G | Ground | | VGA Ground (5,6,7,8,10), '-' of passive speaker 52 | 53 | ## Third party software 54 | This project uses several libraries (in addition to HAL drivers from STMicroelectronics): 55 | * To display video using VGA: https://github.com/cbiffle/m4vgalib (which requires https://github.com/cbiffle/etl) 56 | * Z80 emulator: https://github.com/anotherlin/z80emu 57 | * FATFS for SD card: http://elm-chan.org/fsw/ff/00index_e.html 58 | 59 | ## Plans for the future / issues 60 | * Interference when using SD card or playing sound 61 | * Flickering in some games 62 | * The speed is 12% faster than it is supposed to be 63 | -------------------------------------------------------------------------------- /Src/syscalls.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abelykh0/stm32f407-z80emu/525ece1317c3773a217a04076449e51df7ee8fc7/Src/syscalls.c -------------------------------------------------------------------------------- /doc/Board2_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abelykh0/stm32f407-z80emu/525ece1317c3773a217a04076449e51df7ee8fc7/doc/Board2_1.jpg -------------------------------------------------------------------------------- /doc/Board2_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abelykh0/stm32f407-z80emu/525ece1317c3773a217a04076449e51df7ee8fc7/doc/Board2_2.jpg -------------------------------------------------------------------------------- /doc/DIY-More-STM32F407VGT6-pinout.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abelykh0/stm32f407-z80emu/525ece1317c3773a217a04076449e51df7ee8fc7/doc/DIY-More-STM32F407VGT6-pinout.xlsx -------------------------------------------------------------------------------- /doc/STM32F407VET6-pinout.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abelykh0/stm32f407-z80emu/525ece1317c3773a217a04076449e51df7ee8fc7/doc/STM32F407VET6-pinout.xlsx -------------------------------------------------------------------------------- /doc/stm32f407-z80emu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abelykh0/stm32f407-z80emu/525ece1317c3773a217a04076449e51df7ee8fc7/doc/stm32f407-z80emu.jpg -------------------------------------------------------------------------------- /readme-BOARD2.md: -------------------------------------------------------------------------------- 1 | 2 | # Alternative pinout and read-only file system on high 512K of 1M flash 3 | 4 | ## Pictures 5 | ![Picture 1](https://raw.githubusercontent.com/abelykh0/stm32f407-z80emu/master/doc/Board2_1.jpg) 6 | ![Picture 2](https://raw.githubusercontent.com/abelykh0/stm32f407-z80emu/master/doc/Board2_2.jpg) 7 | 8 | ## Pinout 9 | 10 | | PIN | Description | Connect To | Output | 11 | | --- | ----------- | ---------- | ------ | 12 | | PD0 | Red 1 | Resistor 470 Ohm | VGA red (1) 13 | | PD1 | Red 2 | Resistor 680 Ohm | VGA red (1) 14 | | PD2 | Green 1 | Resistor 470 Ohm | VGA green (2) 15 | | PD3 | Green 2 | Resistor 680 Ohm | VGA green (2) 16 | | PD4 | Blue 1 | Resistor 470 Ohm | VGA blue (3) 17 | | PD5 | Blue 2 | Resistor 680 Ohm | VGA blue (3) 18 | | PB6 | HSync | | VGA HSync (13) 19 | | PB7 | VSync | | VGA VSync (14) 20 | | PB4 | CLK | Resistor 2K2 to keyboard CLK and resistor 3K3 to GND 21 | | PB5 | DATA | Resistor 2K2 to keyboard DATA and resistor 3K3 to GND 22 | | G | Ground | | VGA Ground (5,6,7,8,10), '-' of passive speaker 23 | -------------------------------------------------------------------------------- /stm32f407-z80emu Debug.cfg: -------------------------------------------------------------------------------- 1 | # This is an stm32f407-z80emu board with a single STM32F407VETx chip 2 | # 3 | # Generated by System Workbench for STM32 4 | # Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s) 5 | 6 | source [find interface/stlink.cfg] 7 | 8 | set WORKAREASIZE 0x8000 9 | 10 | transport select "hla_swd" 11 | 12 | set CHIPNAME STM32F407VETx 13 | set BOARDNAME stm32f407-z80emu 14 | 15 | # CHIPNAMES state 16 | set CHIPNAME_CPU0_ACTIVATED 1 17 | 18 | # Enable debug when in low power modes 19 | set ENABLE_LOW_POWER 1 20 | 21 | # Stop Watchdog counters when halt 22 | set STOP_WATCHDOG 1 23 | 24 | # STlink Debug clock frequency 25 | set CLOCK_FREQ 4000 26 | 27 | # use software system reset 28 | reset_config none 29 | set CONNECT_UNDER_RESET 0 30 | 31 | # BCTM CPU variables 32 | 33 | 34 | 35 | source [find target/stm32f4x.cfg] 36 | -------------------------------------------------------------------------------- /stm32f407-z80emu Release.cfg: -------------------------------------------------------------------------------- 1 | # This is an stm32f407-z80emu board with a single STM32F407VETx chip 2 | # 3 | # Generated by System Workbench for STM32 4 | # Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s) 5 | 6 | source [find interface/stlink.cfg] 7 | 8 | set WORKAREASIZE 0x8000 9 | 10 | transport select "hla_swd" 11 | 12 | set CHIPNAME STM32F407VETx 13 | set BOARDNAME stm32f407-z80emu 14 | 15 | # CHIPNAMES state 16 | set CHIPNAME_CPU0_ACTIVATED 1 17 | 18 | # Enable debug when in low power modes 19 | set ENABLE_LOW_POWER 1 20 | 21 | # Stop Watchdog counters when halt 22 | set STOP_WATCHDOG 1 23 | 24 | # STlink Debug clock frequency 25 | set CLOCK_FREQ 4000 26 | 27 | # use software system reset 28 | reset_config none 29 | set CONNECT_UNDER_RESET 0 30 | 31 | # BCTM CPU variables 32 | 33 | 34 | 35 | source [find target/stm32f4x.cfg] 36 | -------------------------------------------------------------------------------- /stm32f407-z80emu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ]> 11 | 12 | 13 | stm32f407-z80emu 14 | SWD 15 | ST-Link 16 | stm32f407vetx 17 | 18 | 19 | -------------------------------------------------------------------------------- /stm32f407-z80emu_converter.log: -------------------------------------------------------------------------------- 1 | Project: stm32f407-z80emu 2 | Converter: ST System Workbench for STM32 project converter 3 | Date: 20241105 4 | 5 | Unrecognized tool command 'g++ ' for tool id fr.ac6.managedbuild.tool.gnu.cross.cpp.compiler 6 | Unknown value type "" for id gnu.c.link.option.libs on tool fr.ac6.managedbuild.tool.gnu.cross.c.linker 7 | Unknown value type "" for id gnu.c.link.option.paths on tool fr.ac6.managedbuild.tool.gnu.cross.c.linker 8 | Unrecognized tool command 'g++' for tool id fr.ac6.managedbuild.tool.gnu.cross.cpp.linker 9 | Unknown value type "" for id gnu.cpp.link.option.libs on tool fr.ac6.managedbuild.tool.gnu.cross.cpp.linker 10 | Unknown value type "" for id gnu.cpp.link.option.paths on tool fr.ac6.managedbuild.tool.gnu.cross.cpp.linker 11 | Option fr.ac6.managedbuild.tool.gnu.cross.cpp.linker.noexceptions is no longer supported 12 | Option fr.ac6.managedbuild.tool.gnu.cross.cpp.linker.nortti is no longer supported 13 | Value type err, id: gnu.cpp.link.option.flags 14 | Unknown value type "" for id gnu.both.asm.option.include.paths on tool fr.ac6.managedbuild.tool.gnu.cross.assembler 15 | Unrecognized tool command 'g++' for tool id fr.ac6.managedbuild.tool.gnu.cross.cpp.compiler 16 | Unknown value type "" for id gnu.c.link.option.libs on tool fr.ac6.managedbuild.tool.gnu.cross.c.linker 17 | Unknown value type "" for id gnu.c.link.option.paths on tool fr.ac6.managedbuild.tool.gnu.cross.c.linker 18 | Unknown value type "" for id gnu.cpp.link.option.libs on tool fr.ac6.managedbuild.tool.gnu.cross.cpp.linker 19 | Unknown value type "" for id gnu.cpp.link.option.paths on tool fr.ac6.managedbuild.tool.gnu.cross.cpp.linker 20 | Option fr.ac6.managedbuild.tool.gnu.cross.cpp.linker.noexceptions is no longer supported 21 | Option fr.ac6.managedbuild.tool.gnu.cross.cpp.linker.nortti is no longer supported 22 | Value type err, id: gnu.cpp.link.option.flags 23 | Unknown value type "" for id gnu.both.asm.option.include.paths on tool fr.ac6.managedbuild.tool.gnu.cross.assembler.exe.release 24 | No map found for id: 25 | No map found for id: 26 | No map found for id: 27 | Option fr.ac6.managedbuild.tool.gnu.cross.cpp.linker.noexceptions is no longer supported 28 | Option fr.ac6.managedbuild.tool.gnu.cross.cpp.linker.nortti is no longer supported 29 | --------------------------------------------------------------------------------