├── .cproject
├── .github
└── workflows
│ └── build.yaml
├── .gitignore
├── .mxproject
├── .project
├── Core
├── Inc
│ ├── Application.h
│ ├── Audio.h
│ ├── Button.h
│ ├── GpioPin.h
│ ├── GraphicEqualizer.h
│ ├── Led.h
│ ├── LiveLed.h
│ ├── MuteButton.h
│ ├── Program.h
│ ├── VolumeControl.h
│ ├── main.h
│ ├── stm32f4xx_hal_conf.h
│ └── stm32f4xx_it.h
├── Src
│ ├── Audio.cpp
│ ├── UsbMicrophone.cpp
│ ├── main.c
│ ├── stm32f4xx_hal_msp.c
│ ├── stm32f4xx_it.c
│ ├── syscalls.c
│ ├── sysmem.c
│ └── system_stm32f4xx.c
└── Startup
│ └── startup_stm32f446rctx.s
├── Drivers
├── CMSIS
│ ├── Device
│ │ └── ST
│ │ │ └── STM32F4xx
│ │ │ └── Include
│ │ │ ├── stm32f446xx.h
│ │ │ ├── stm32f4xx.h
│ │ │ └── system_stm32f4xx.h
│ └── Include
│ │ ├── cmsis_armcc.h
│ │ ├── cmsis_armclang.h
│ │ ├── cmsis_compiler.h
│ │ ├── cmsis_gcc.h
│ │ ├── cmsis_iccarm.h
│ │ ├── cmsis_version.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_cm4.h
│ │ ├── core_cm7.h
│ │ ├── core_sc000.h
│ │ ├── core_sc300.h
│ │ ├── mpu_armv7.h
│ │ ├── mpu_armv8.h
│ │ └── tz_context.h
└── STM32F4xx_HAL_Driver
│ ├── Inc
│ ├── Legacy
│ │ └── stm32_hal_legacy.h
│ ├── stm32f4xx_hal.h
│ ├── stm32f4xx_hal_cortex.h
│ ├── stm32f4xx_hal_crc.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_i2s.h
│ ├── stm32f4xx_hal_i2s_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_tim.h
│ ├── stm32f4xx_hal_tim_ex.h
│ └── stm32f4xx_ll_usb.h
│ └── Src
│ ├── stm32f4xx_hal.c
│ ├── stm32f4xx_hal_cortex.c
│ ├── stm32f4xx_hal_crc.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_i2s.c
│ ├── stm32f4xx_hal_i2s_ex.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_tim.c
│ ├── stm32f4xx_hal_tim_ex.c
│ └── stm32f4xx_ll_usb.c
├── Makefile
├── Middlewares
└── ST
│ ├── STM32_Audio
│ └── Addons
│ │ ├── Common
│ │ └── Inc
│ │ │ ├── Release_Notes.html
│ │ │ └── audio_fw_glo.h
│ │ ├── GREQ
│ │ ├── Inc
│ │ │ └── greq_glo.h
│ │ ├── Lib
│ │ │ └── libGREQ.a
│ │ └── Release_Notes.html
│ │ └── SVC
│ │ ├── Inc
│ │ └── svc_glo.h
│ │ ├── Lib
│ │ └── libSVC.a
│ │ └── Release_Notes.html
│ └── STM32_USB_Device_Library
│ ├── Class
│ └── AUDIO
│ │ ├── Inc
│ │ └── usbd_audio_in.h
│ │ └── Src
│ │ └── usbd_audio_in.c
│ └── Core
│ ├── Inc
│ ├── usbd_core.h
│ ├── usbd_ctlreq.h
│ ├── usbd_def.h
│ └── usbd_ioreq.h
│ └── Src
│ ├── usbd_core.c
│ ├── usbd_ctlreq.c
│ └── usbd_ioreq.c
├── README.md
├── STM32F446RCTX_FLASH.ld
├── USB_DEVICE
├── App
│ ├── usb_device.c
│ ├── usb_device.h
│ ├── usbd_audio_if.cpp
│ ├── usbd_audio_if.h
│ ├── usbd_desc.c
│ └── usbd_desc.h
└── Target
│ ├── usbd_conf.c
│ └── usbd_conf.h
├── board-running.jpg
├── usb-microphone Debug.launch
├── usb-microphone Debug_Semihosting.cfg
├── usb-microphone Debug_Semihosting.launch
├── usb-microphone.ioc
└── wav-samples
├── 1-direct-no-transforms.wav
├── 2-svc-36db-amplification.wav
├── 3-svc-greq.wav
└── mute-button-click-fix
├── after.mp3
└── before.mp3
/.github/workflows/build.yaml:
--------------------------------------------------------------------------------
1 | name: release build
2 | on: [ push, pull_request ]
3 |
4 | jobs:
5 | release:
6 | name: Build the release configuration
7 | runs-on: ubuntu-20.04
8 | steps:
9 | - name: Install compiler
10 | run: |
11 | wget -q -O /tmp/gcc.tar.bz2 https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
12 | tar xfj /tmp/gcc.tar.bz2 -C /tmp
13 | - name: Checkout the source code
14 | uses: actions/checkout@v2
15 | with:
16 | ref: ${{ github.ref }}
17 | - name: Execute the Makefile
18 | run: |
19 | PATH=/tmp/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH make -j release
20 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /Debug
2 | /.settings
3 | /Debug_Semihosting/
4 | /build/
5 |
--------------------------------------------------------------------------------
/.mxproject:
--------------------------------------------------------------------------------
1 | [PreviousLibFiles]
2 | LibFiles=Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usb.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim_ex.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h;Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc/usbd_audio.h;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c;Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src/usbd_audio.c;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usb.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim_ex.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h;Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc/usbd_audio.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f446xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Drivers/CMSIS/Include/cmsis_iccarm.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/cmsis_armclang.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_armv8mbl.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/core_cm33.h;Drivers/CMSIS/Include/core_sc300.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/cmsis_compiler.h;Drivers/CMSIS/Include/cmsis_version.h;Drivers/CMSIS/Include/tz_context.h;Drivers/CMSIS/Include/core_cm23.h;Drivers/CMSIS/Include/core_cm1.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_armv8mml.h;Drivers/CMSIS/Include/mpu_armv8.h;Drivers/CMSIS/Include/mpu_armv7.h;
3 |
4 | [PreviousUsedCubeIDEFiles]
5 | SourceFiles=Core/Src/main.c;USB_DEVICE/App/usb_device.c;USB_DEVICE/Target/usbd_conf.c;USB_DEVICE/App/usbd_desc.c;USB_DEVICE/App/usbd_audio_if.c;Core/Src/stm32f4xx_it.c;Core/Src/stm32f4xx_hal_msp.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c;Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src/usbd_audio.c;Core/Src/system_stm32f4xx.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c;Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src/usbd_audio.c;Core/Src/system_stm32f4xx.c;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c;Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src/usbd_audio.c;
6 | HeaderPath=Drivers/STM32F4xx_HAL_Driver/Inc;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy;Middlewares/ST/STM32_USB_Device_Library/Core/Inc;Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc;Drivers/CMSIS/Device/ST/STM32F4xx/Include;Drivers/CMSIS/Include;USB_DEVICE/App;USB_DEVICE/Target;Core/Inc;
7 | CDefines=USE_HAL_DRIVER;STM32F446xx;USE_HAL_DRIVER;USE_HAL_DRIVER;
8 |
9 | [PreviousGenFiles]
10 | AdvancedFolderStructure=true
11 | HeaderFileListSize=7
12 | HeaderFiles#0=/home/andy/src/usb-microphone/USB_DEVICE/App/usb_device.h
13 | HeaderFiles#1=/home/andy/src/usb-microphone/USB_DEVICE/Target/usbd_conf.h
14 | HeaderFiles#2=/home/andy/src/usb-microphone/USB_DEVICE/App/usbd_desc.h
15 | HeaderFiles#3=/home/andy/src/usb-microphone/USB_DEVICE/App/usbd_audio_if.h
16 | HeaderFiles#4=/home/andy/src/usb-microphone/Core/Inc/stm32f4xx_it.h
17 | HeaderFiles#5=/home/andy/src/usb-microphone/Core/Inc/stm32f4xx_hal_conf.h
18 | HeaderFiles#6=/home/andy/src/usb-microphone/Core/Inc/main.h
19 | HeaderFolderListSize=3
20 | HeaderPath#0=/home/andy/src/usb-microphone/USB_DEVICE/App
21 | HeaderPath#1=/home/andy/src/usb-microphone/USB_DEVICE/Target
22 | HeaderPath#2=/home/andy/src/usb-microphone/Core/Inc
23 | HeaderFiles=;
24 | SourceFileListSize=7
25 | SourceFiles#0=/home/andy/src/usb-microphone/USB_DEVICE/App/usb_device.c
26 | SourceFiles#1=/home/andy/src/usb-microphone/USB_DEVICE/Target/usbd_conf.c
27 | SourceFiles#2=/home/andy/src/usb-microphone/USB_DEVICE/App/usbd_desc.c
28 | SourceFiles#3=/home/andy/src/usb-microphone/USB_DEVICE/App/usbd_audio_if.c
29 | SourceFiles#4=/home/andy/src/usb-microphone/Core/Src/stm32f4xx_it.c
30 | SourceFiles#5=/home/andy/src/usb-microphone/Core/Src/stm32f4xx_hal_msp.c
31 | SourceFiles#6=/home/andy/src/usb-microphone/Core/Src/main.c
32 | SourceFolderListSize=3
33 | SourcePath#0=/home/andy/src/usb-microphone/USB_DEVICE/App
34 | SourcePath#1=/home/andy/src/usb-microphone/USB_DEVICE/Target
35 | SourcePath#2=/home/andy/src/usb-microphone/Core/Src
36 | SourceFiles=;
37 |
38 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | usb-microphone
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 | com.st.stm32cube.ide.mcu.MCUProjectNature
23 | org.eclipse.cdt.core.cnature
24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAev2ProjectNature
25 | com.st.stm32cube.ide.mcu.MCUCubeProjectNature
26 | com.st.stm32cube.ide.mcu.MCUAdvancedStructureProjectNature
27 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature
28 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature
29 | com.st.stm32cube.ide.mcu.MCURootProjectNature
30 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
31 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
32 | org.eclipse.cdt.core.ccnature
33 |
34 |
35 |
--------------------------------------------------------------------------------
/Core/Inc/Application.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #pragma once
8 |
9 | extern "C" {
10 | #include "main.h"
11 | #include "usbd_audio_if.h"
12 | #include "greq_glo.h"
13 | #include "svc_glo.h"
14 |
15 | extern USBD_HandleTypeDef hUsbDeviceFS;
16 | extern I2S_HandleTypeDef hi2s1;
17 | }
18 |
19 | // include our classes
20 |
21 | #include "GpioPin.h"
22 | #include "Led.h"
23 | #include "LiveLed.h"
24 | #include "Button.h"
25 | #include "MuteButton.h"
26 | #include "VolumeControl.h"
27 | #include
28 | #include "Audio.h"
29 | #include "Program.h"
30 |
31 | // for the Debug_Semihosting configuration
32 |
33 | #ifdef SEMIHOSTING
34 | #include
35 | #endif
36 |
--------------------------------------------------------------------------------
/Core/Inc/Audio.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #pragma once
8 |
9 | /**
10 | * Audio management functionality. Many of the methods in here are called from the
11 | * usbd_audio_if.cpp file.
12 | */
13 |
14 | class Audio {
15 |
16 | private:
17 | // 20ms of 64 bit samples
18 |
19 | volatile int32_t *_sampleBuffer;
20 | int16_t *_processBuffer;
21 | int16_t *_sendBuffer;
22 |
23 | const MuteButton &_muteButton;
24 | const LiveLed &_liveLed;
25 | GraphicEqualizer &_graphicEqualiser;
26 | VolumeControl &_volumeControl;
27 | bool _running;
28 | uint8_t _zeroCounter;
29 |
30 | public:
31 | static Audio *_instance;
32 |
33 | public:
34 | Audio(const MuteButton &muteButton, const LiveLed &liveLed, GraphicEqualizer &graphicEqualiser,
35 | VolumeControl &volumeControl);
36 |
37 | void setLed() const;
38 | void setVolume(int16_t volume);
39 |
40 | void i2s_halfComplete();
41 | void i2s_complete();
42 |
43 | int8_t start();
44 | int8_t stop();
45 | int8_t pause();
46 | int8_t resume();
47 |
48 | const GraphicEqualizer& getGraphicEqualizer() const;
49 |
50 | private:
51 | void sendData(volatile int32_t *data_in, int16_t *data_out);
52 | };
53 |
54 | /**
55 | * Constructor
56 | */
57 |
58 | inline Audio::Audio(const MuteButton &muteButton, const LiveLed &liveLed, GraphicEqualizer &graphicEqualiser,
59 | VolumeControl &volumeControl) :
60 | _muteButton(muteButton), _liveLed(liveLed), _graphicEqualiser(graphicEqualiser), _volumeControl(volumeControl) {
61 |
62 | // initialise variables
63 |
64 | Audio::_instance = this;
65 | _running = false;
66 | _zeroCounter = 0;
67 |
68 | // allocate buffers
69 |
70 | _sampleBuffer = new int32_t[MIC_SAMPLES_PER_PACKET * 2]; // 7680 bytes (*2 because samples are 64 bit)
71 | _processBuffer = new int16_t[MIC_SAMPLES_PER_PACKET]; // 1920 bytes
72 | _sendBuffer = new int16_t[MIC_SAMPLES_PER_PACKET]; // 1920 bytes
73 |
74 | // set LR to low (it's pulled low anyway)
75 |
76 | HAL_GPIO_WritePin(LR_GPIO_Port, LR_Pin, GPIO_PIN_RESET);
77 | }
78 |
79 | /**
80 | * Start the I2S DMA transfer (called from usbd_audio_if.cpp)
81 | */
82 |
83 | inline int8_t Audio::start() {
84 |
85 | HAL_StatusTypeDef status;
86 |
87 | // HAL_I2S_Receive_DMA will multiply the size by 2 because the standard is 24 bit Philips.
88 |
89 | if ((status = HAL_I2S_Receive_DMA(&hi2s1, (uint16_t*) _sampleBuffer, MIC_SAMPLES_PER_PACKET * 2)) == HAL_OK) {
90 | _running = true;
91 | }
92 |
93 | return status;
94 | }
95 |
96 | /**
97 | * Stop the I2S DMA transfer
98 | */
99 |
100 | inline int8_t Audio::stop() {
101 |
102 | HAL_StatusTypeDef status;
103 |
104 | if ((status = HAL_I2S_DMAStop(&hi2s1)) == HAL_OK) {
105 | _running = false;
106 | }
107 | return status;
108 | }
109 |
110 | /**
111 | * Pause I2S DMA transfer (soft-mute)
112 | */
113 |
114 | inline int8_t Audio::pause() {
115 |
116 | HAL_StatusTypeDef status;
117 |
118 | if ((status = HAL_I2S_DMAPause(&hi2s1)) == HAL_OK) {
119 | _running = false;
120 | }
121 |
122 | return status;
123 | }
124 |
125 | /**
126 | * Resume I2S DMA transfer
127 | */
128 |
129 | inline int8_t Audio::resume() {
130 |
131 | HAL_StatusTypeDef status;
132 |
133 | if ((status = HAL_I2S_DMAResume(&hi2s1)) == HAL_OK) {
134 | _running = true;
135 | }
136 | return status;
137 | }
138 |
139 | /**
140 | * Light the live LED if we are unmuted (hard and soft)
141 | */
142 |
143 | inline void Audio::setLed() const {
144 | _liveLed.setState(_running && !_muteButton.isMuted());
145 | }
146 |
147 | /**
148 | * Set the volume gain: the mute state is preserved
149 | */
150 |
151 | inline void Audio::setVolume(int16_t volume) {
152 |
153 | // reduce resolution from 1/256dB to 1/2dB
154 |
155 | volume /= 128;
156 |
157 | // ensure SVC library limits are respected
158 |
159 | if (volume < -160) {
160 | volume = -160;
161 | } else if (volume > 72) {
162 | volume = 72;
163 | }
164 |
165 | _volumeControl.setVolume(volume);
166 | }
167 |
168 | /**
169 | * Get a reference to the graphic equalizer
170 | */
171 |
172 | inline const GraphicEqualizer& Audio::getGraphicEqualizer() const {
173 | return _graphicEqualiser;
174 | }
175 |
176 | /**
177 | * 1. Transform the I2S data into 16 bit PCM samples in a holding buffer
178 | * 2. Use the ST GREQ library to apply a graphic equaliser filter
179 | * 3. Use the ST SVC library to adjust the gain (volume)
180 | * 4. Transmit over USB to the host
181 | *
182 | * We've got 10ms to complete this method before the next DMA transfer will be ready.
183 | */
184 |
185 | inline void Audio::sendData(volatile int32_t *data_in, int16_t *data_out) {
186 |
187 | // only do anything at all if we're connected
188 |
189 | if (_running) {
190 |
191 | // ensure that the mute state in the smart volume control library matches the mute
192 | // state of the hardware button. we do this here to ensure that we only call SVC
193 | // methods from inside an IRQ context.
194 |
195 | if (_muteButton.isMuted()) {
196 | if (!_volumeControl.isMuted()) {
197 | _volumeControl.setMute(true);
198 |
199 | // the next 50 frames (500ms) will be zero'd - this seems to do a better job of catching the
200 | // mute button 'pop' than the SVC filter mute when going into a mute
201 |
202 | _zeroCounter = 50;
203 | }
204 | }
205 | else {
206 | if (_volumeControl.isMuted()) {
207 |
208 | // coming out of a mute is handled well by the SVC filter
209 |
210 | _volumeControl.setMute(false);
211 | }
212 | }
213 |
214 | if (_zeroCounter) {
215 | memset(data_out, 0, (MIC_SAMPLES_PER_PACKET * sizeof(uint16_t)) / 2);
216 | _zeroCounter--;
217 | }
218 | else {
219 |
220 | // transform the I2S samples from the 64 bit L/R (32 bits per side) of which we
221 | // only have data in the L side. Take the most significant 16 bits, being careful
222 | // to respect the sign bit.
223 |
224 | int16_t *dest = _processBuffer;
225 |
226 | for (uint16_t i = 0; i < MIC_SAMPLES_PER_PACKET / 2; i++) {
227 |
228 | // dither the LSB with a random bit
229 |
230 | int16_t sample = (data_in[0] & 0xfffffffe) | (rand() & 1);
231 |
232 | *dest++ = sample; // left channel has data
233 | *dest++ = sample; // right channel is duplicated from the left
234 | data_in += 2;
235 | }
236 |
237 | // apply the graphic equaliser filters using the ST GREQ library then
238 | // adjust the gain (volume) using the ST SVC library
239 |
240 | _graphicEqualiser.process(_processBuffer, MIC_SAMPLES_PER_PACKET / 2);
241 | _volumeControl.process(_processBuffer, MIC_SAMPLES_PER_PACKET / 2);
242 |
243 | // we only want the left channel from the processed buffer
244 |
245 | int16_t *src = _processBuffer;
246 | dest = data_out;
247 |
248 | for (uint16_t i = 0; i < MIC_SAMPLES_PER_PACKET / 2; i++) {
249 | *dest++ = *src;
250 | src += 2;
251 | }
252 | }
253 |
254 | // send the adjusted data to the host
255 |
256 | if (USBD_AUDIO_Data_Transfer(&hUsbDeviceFS, data_out, MIC_SAMPLES_PER_PACKET / 2) != USBD_OK) {
257 | Error_Handler();
258 | }
259 | }
260 | }
261 |
262 | /**
263 | * Override the I2S DMA half-complete HAL callback to process the first MIC_MS_PER_PACKET/2 milliseconds
264 | * of the data while the DMA device continues to run onward to fill the second half of the buffer.
265 | */
266 |
267 | inline void Audio::i2s_halfComplete() {
268 | sendData(_sampleBuffer, _sendBuffer);
269 | }
270 |
271 | /**
272 | * Override the I2S DMA complete HAL callback to process the second MIC_MS_PER_PACKET/2 milliseconds
273 | * of the data while the DMA in circular mode wraps back to the start of the buffer
274 | */
275 |
276 | inline void Audio::i2s_complete() {
277 | sendData(&_sampleBuffer[MIC_SAMPLES_PER_PACKET], &_sendBuffer[MIC_SAMPLES_PER_PACKET / 2]);
278 | }
279 |
--------------------------------------------------------------------------------
/Core/Inc/Button.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #pragma once
8 |
9 | /**
10 | * A debounced button class
11 | */
12 |
13 | class Button: public GpioPin {
14 |
15 | public:
16 | enum CurrentState {
17 | None,
18 | Up,
19 | Down
20 | };
21 |
22 | private:
23 |
24 | static const uint32_t DEBOUNCE_UP_DELAY_MILLIS = 100;
25 | static const uint32_t DEBOUNCE_DOWN_DELAY_MILLIS = 1;
26 |
27 | enum InternalState {
28 | Idle, // nothing happening
29 | DebounceUpDelay, // delaying...
30 | DebounceDownDelay
31 | };
32 |
33 | bool _pressedIsHigh; // The button is electrically HIGH when pressed?
34 | InternalState _internalState; // Internal state of the class
35 |
36 | bool _lastButtonReading; // the last state we sampled
37 | uint32_t _transitionTime; // the time of the last transition
38 |
39 | public:
40 | Button(const GpioPin &pin, bool pressedIsHigh);
41 | CurrentState getAndClearCurrentState(); // retrieve current state and reset to idle
42 | };
43 |
44 | inline Button::Button(const GpioPin &pin, bool pressedIsHigh) :
45 | GpioPin(pin) {
46 |
47 | _transitionTime = 0;
48 | _lastButtonReading = false;
49 | _pressedIsHigh = pressedIsHigh;
50 | _internalState = Idle;
51 | }
52 |
53 | /**
54 | * Get and reset the current state. This should be called in the main application loop.
55 | * @return The current state. If the current state is one of the up/down pressed states
56 | * then that state is returned and then internally reset to none so the application only
57 | * gets one 'notification' that the button is pressed/released.
58 | */
59 |
60 | inline Button::CurrentState Button::getAndClearCurrentState() {
61 |
62 | // read the pin and flip it if this switch reads high when open
63 |
64 | bool buttonReading = getState();
65 | if (!_pressedIsHigh) {
66 | buttonReading ^= true;
67 | }
68 |
69 | const uint32_t now = HAL_GetTick();
70 |
71 | if (_lastButtonReading == buttonReading) {
72 |
73 | // no change in the button reading, we could be exiting the debounce delay
74 |
75 | switch (_internalState) {
76 |
77 | case DebounceUpDelay:
78 | if (now - _transitionTime > DEBOUNCE_UP_DELAY_MILLIS) {
79 | _internalState = Idle;
80 | return Up;
81 | }
82 | break;
83 |
84 | case DebounceDownDelay:
85 | if (now - _transitionTime > DEBOUNCE_DOWN_DELAY_MILLIS) {
86 | _internalState = Idle;
87 | return Down;
88 | }
89 | break;
90 |
91 | case Idle:
92 | break;
93 | }
94 |
95 | return None;
96 |
97 | } else {
98 |
99 | // button reading has changed, this always causes the state to enter the debounce delay
100 |
101 | _transitionTime = now;
102 | _lastButtonReading = buttonReading;
103 | _internalState = buttonReading ? DebounceDownDelay : DebounceUpDelay;
104 |
105 | return None;
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/Core/Inc/GpioPin.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #pragma once
8 |
9 | class GpioPin {
10 |
11 | private:
12 | GPIO_TypeDef *_port;
13 | uint16_t _pin;
14 |
15 | private:
16 | void assign(const GpioPin &src);
17 |
18 | public:
19 | GpioPin(GPIO_TypeDef *port, uint16_t pin);
20 | GpioPin(const GpioPin &src);
21 |
22 | void set() const;
23 | void reset() const;
24 | void setState(bool state) const;
25 | bool getState() const;
26 |
27 | GpioPin& operator=(const GpioPin &src);
28 | };
29 |
30 | inline GpioPin::GpioPin(GPIO_TypeDef *port, uint16_t pin) {
31 | _port = port;
32 | _pin = pin;
33 | }
34 |
35 | inline GpioPin::GpioPin(const GpioPin &src) {
36 | assign(src);
37 | }
38 |
39 | inline void GpioPin::set() const {
40 | HAL_GPIO_WritePin(_port, _pin, GPIO_PIN_SET);
41 | }
42 |
43 | inline void GpioPin::reset() const {
44 | HAL_GPIO_WritePin(_port, _pin, GPIO_PIN_RESET);
45 | }
46 |
47 | inline bool GpioPin::getState() const {
48 | return HAL_GPIO_ReadPin(_port, _pin) == GPIO_PIN_SET;
49 | }
50 |
51 | inline void GpioPin::setState(bool state) const {
52 | HAL_GPIO_WritePin(_port, _pin, state ? GPIO_PIN_SET : GPIO_PIN_RESET);
53 | }
54 |
55 | inline GpioPin& GpioPin::operator=(const GpioPin &src) {
56 | assign(src);
57 | return *this;
58 | }
59 |
60 | inline void GpioPin::assign(const GpioPin &src) {
61 | _port = src._port;
62 | _pin = src._pin;
63 | }
64 |
--------------------------------------------------------------------------------
/Core/Inc/GraphicEqualizer.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #pragma once
8 |
9 | /**
10 | * Service class to manage the API to the ST GREQ library. This is provided as a closed source
11 | * but free-to-use library by ST Micro. See UM1798 for details.
12 | */
13 |
14 | class GraphicEqualizer {
15 |
16 | private:
17 | uint8_t *_greqPersistent;
18 | uint8_t *_greqScratch;
19 |
20 | buffer_t _greqInput;
21 | buffer_t _greqOutput;
22 |
23 | // the range of the 10 bands is -12..+12 in 1dB steps
24 | greq_dynamic_param_t _dynamicParam;
25 |
26 | public:
27 | GraphicEqualizer();
28 |
29 | void setBand(int8_t index, int8_t value);
30 | const int16_t* getGainsPerBand() const;
31 |
32 | void process(int16_t *iobuffer, int32_t nSamples);
33 | };
34 |
35 | /**
36 | * Constructor
37 | */
38 |
39 | extern "C" {
40 | extern greq_dynamic_param_t *pEqualizerParams;
41 | }
42 |
43 | inline GraphicEqualizer::GraphicEqualizer() {
44 |
45 | // the USB 'C' interface needs access to this
46 |
47 | pEqualizerParams = &_dynamicParam;
48 |
49 | // allocate space required by the SVC library
50 |
51 | _greqPersistent = new uint8_t[greq_persistent_mem_size]; // 548
52 | _greqScratch = new uint8_t[greq_scratch_mem_size]; // 3840
53 |
54 | // reset the library
55 |
56 | if (greq_reset(_greqPersistent, _greqScratch) != GREQ_ERROR_NONE) {
57 | Error_Handler();
58 | }
59 |
60 | greq_static_param_t staticParam;
61 |
62 | // set the number of bands to 10
63 |
64 | staticParam.nb_bands = 10;
65 |
66 | if (greq_setParam(&staticParam, _greqPersistent) != SVC_ERROR_NONE) {
67 | Error_Handler();
68 | }
69 |
70 | // buffer constants
71 |
72 | _greqInput.nb_channels = _greqOutput.nb_channels = 2;
73 | _greqInput.nb_bytes_per_Sample = _greqOutput.nb_bytes_per_Sample = 2;
74 | _greqInput.mode = _greqOutput.mode = INTERLEAVED;
75 |
76 | // set the bands
77 |
78 | _dynamicParam.enable = 1;
79 | _dynamicParam.user_gain_per_band_dB[0] = -3; // 62
80 | _dynamicParam.user_gain_per_band_dB[1] = -3; // 115
81 | _dynamicParam.user_gain_per_band_dB[2] = -3; // 214
82 | _dynamicParam.user_gain_per_band_dB[3] = 3; // 399
83 | _dynamicParam.user_gain_per_band_dB[4] = 3; // 742
84 | _dynamicParam.user_gain_per_band_dB[5] = 3; // 1380
85 | _dynamicParam.user_gain_per_band_dB[6] = 3; // 2567
86 | _dynamicParam.user_gain_per_band_dB[7] = 3; // 4775
87 | _dynamicParam.user_gain_per_band_dB[8] = 3; // 8882
88 | _dynamicParam.user_gain_per_band_dB[9] = 3; // 16520
89 | _dynamicParam.gain_preset_idx = 0;
90 |
91 | greq_setConfig(&_dynamicParam, _greqPersistent);
92 | }
93 |
94 | /**
95 | * Get a pointer to the gains per band
96 | */
97 |
98 | inline const int16_t* GraphicEqualizer::getGainsPerBand() const {
99 | return _dynamicParam.user_gain_per_band_dB;
100 | }
101 |
102 | /**
103 | * Update the value of a band
104 | */
105 |
106 | inline void GraphicEqualizer::setBand(int8_t index, int8_t value) {
107 | _dynamicParam.user_gain_per_band_dB[index] = value;
108 | greq_setConfig(&_dynamicParam, _greqPersistent);
109 | }
110 |
111 | /**
112 | * Process a sample buffer
113 | */
114 |
115 | inline void GraphicEqualizer::process(int16_t *iobuffer, int32_t nSamples) {
116 |
117 | // initialise the buffer parameters
118 |
119 | _greqInput.buffer_size = _greqOutput.buffer_size = nSamples;
120 |
121 | _greqInput.data_ptr = iobuffer;
122 | _greqOutput.data_ptr = iobuffer;
123 |
124 | // call the library method
125 |
126 | int32_t error = greq_process(&_greqInput, &_greqOutput, _greqPersistent);
127 | if (error != GREQ_ERROR_NONE) {
128 | Error_Handler();
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/Core/Inc/Led.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #pragma once
8 |
9 | struct Led: GpioPin {
10 | Led(const GpioPin &pin) :
11 | GpioPin(pin) {
12 | }
13 |
14 | void on() const {
15 | set();
16 | }
17 | void off() const {
18 | reset();
19 | }
20 | };
21 |
--------------------------------------------------------------------------------
/Core/Inc/LiveLed.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #pragma once
8 |
9 | struct LiveLed: Led {
10 | LiveLed() :
11 | Led(GpioPin(LIVE_LED_GPIO_Port, LIVE_LED_Pin)) {
12 |
13 | off();
14 | }
15 | };
16 |
--------------------------------------------------------------------------------
/Core/Inc/MuteButton.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #pragma once
8 |
9 | class MuteButton: public Button {
10 |
11 | private:
12 | volatile bool _muted;
13 | bool _ignoreNextUp;
14 |
15 | public:
16 | MuteButton();
17 |
18 | void run();
19 | bool isMuted() const;
20 | };
21 |
22 | inline MuteButton::MuteButton() :
23 | Button(GpioPin(MUTE_GPIO_Port, MUTE_Pin), false) {
24 |
25 | _muted = false;
26 | _ignoreNextUp = false;
27 | }
28 |
29 | inline void MuteButton::run() {
30 |
31 | Button::CurrentState state = getAndClearCurrentState();
32 |
33 | // check for idle
34 |
35 | if (state == Button::CurrentState::None) {
36 | return;
37 | }
38 |
39 | if (state == Down) {
40 |
41 | if (!_muted) {
42 | _muted = true;
43 | _ignoreNextUp = true; // the lifting of the button shouldn't exit mute
44 | }
45 | }
46 | else {
47 |
48 | if (_muted) {
49 |
50 | if (_ignoreNextUp) {
51 |
52 | // this is the lifting of the button that went into mute
53 |
54 | _ignoreNextUp = false;
55 | }
56 | else {
57 | _muted = false;
58 | }
59 | }
60 | }
61 | }
62 |
63 | inline bool MuteButton::isMuted() const {
64 | return _muted;
65 | }
66 |
--------------------------------------------------------------------------------
/Core/Inc/Program.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #pragma once
8 |
9 | /**
10 | * Main program class
11 | */
12 |
13 | class Program {
14 |
15 | private:
16 |
17 | MuteButton _muteButton;
18 | LiveLed _liveLed;
19 | Audio _audio;
20 | GraphicEqualizer _graphicEqualiser;
21 | VolumeControl _volumeControl;
22 |
23 | public:
24 | Program();
25 |
26 | void run();
27 | };
28 |
29 | inline Program::Program() :
30 | _audio(_muteButton, _liveLed, _graphicEqualiser, _volumeControl) {
31 | }
32 |
33 | inline void Program::run() {
34 |
35 | // infinite loop
36 |
37 | for (;;) {
38 |
39 | // process the mute button
40 |
41 | _muteButton.run();
42 | _audio.setLed();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Core/Inc/VolumeControl.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #pragma once
8 |
9 | /**
10 | * Service class to manage the API to the ST SVC library. This is provided as a closed source
11 | * but free-to-use library by ST Micro. See UM1642 for details.
12 | */
13 |
14 | class VolumeControl {
15 |
16 | private:
17 | uint8_t *_svcPersistent;
18 | uint8_t *_svcScratch;
19 |
20 | buffer_t _svcInput;
21 | buffer_t _svcOutput;
22 |
23 | svc_dynamic_param_t _dynamicParams;
24 |
25 | public:
26 | VolumeControl();
27 |
28 | void setMute(bool mute);
29 | void setVolume(int16_t volume);
30 | bool isMuted() const;
31 |
32 | void process(int16_t *iobuffer, int32_t nSamples);
33 | };
34 |
35 | /**
36 | * Constructor
37 | */
38 |
39 | inline VolumeControl::VolumeControl() {
40 |
41 | // allocate space required by the SVC library
42 |
43 | _svcPersistent = new uint8_t[svc_persistent_mem_size]; // 1368
44 | _svcScratch = new uint8_t[svc_scratch_mem_size]; // 2880
45 |
46 | // reset the library
47 |
48 | if (svc_reset(_svcPersistent, _svcScratch) != SVC_ERROR_NONE) {
49 | Error_Handler();
50 | }
51 |
52 | // set the static parameters. These defaults are from ST's recommendations.
53 |
54 | svc_static_param_t param;
55 |
56 | param.delay_len = 100;
57 | param.joint_stereo = 1;
58 |
59 | if (svc_setParam(¶m, _svcPersistent) != SVC_ERROR_NONE) {
60 | Error_Handler();
61 | }
62 |
63 | // initialise default dynamic params
64 |
65 | _dynamicParams.mute = 0;
66 | _dynamicParams.target_volume_dB = 72; // max volume
67 |
68 | // enable compression, high quality, use timings from ST's sample application
69 |
70 | _dynamicParams.enable_compr = 1;
71 | _dynamicParams.quality = 1;
72 | _dynamicParams.attack_time = 2103207220;
73 | _dynamicParams.release_time = 2146924480;
74 |
75 | // buffer constants
76 |
77 | _svcInput.nb_channels = _svcOutput.nb_channels = 2;
78 | _svcInput.nb_bytes_per_Sample = _svcOutput.nb_bytes_per_Sample = 2;
79 | _svcInput.mode = _svcOutput.mode = INTERLEAVED;
80 |
81 | // set the initial volume
82 |
83 | setVolume(1);
84 | }
85 |
86 | /**
87 | * Set the volume level. The range is -80db to +36db. Positive values amplify, negative
88 | * values attenuate. The range is in 0.5dB steps therefore volume parameter range is -160..72
89 | */
90 |
91 | inline void VolumeControl::setVolume(int16_t volume) {
92 |
93 | _dynamicParams.target_volume_dB = volume;
94 |
95 | int32_t error = svc_setConfig(&_dynamicParams, _svcPersistent);
96 | if (error != SVC_ERROR_NONE) {
97 | Error_Handler();
98 | }
99 | }
100 |
101 | /**
102 | * Set the muted state
103 | */
104 |
105 | inline void VolumeControl::setMute(bool mute) {
106 |
107 | _dynamicParams.mute = mute ? 1 : 0;
108 |
109 | int32_t error = svc_setConfig(&_dynamicParams, _svcPersistent);
110 | if (error != SVC_ERROR_NONE) {
111 | Error_Handler();
112 | }
113 | }
114 |
115 | /**
116 | * Get the mute state
117 | */
118 |
119 | inline bool VolumeControl::isMuted() const {
120 | return _dynamicParams.mute == 1;
121 | }
122 |
123 | /**
124 | * Process a sample buffer
125 | */
126 |
127 | inline void VolumeControl::process(int16_t *iobuffer, int32_t nSamples) {
128 |
129 | // initialise the buffer parameters
130 |
131 | _svcInput.buffer_size = _svcOutput.buffer_size = nSamples;
132 |
133 | _svcInput.data_ptr = iobuffer;
134 | _svcOutput.data_ptr = iobuffer;
135 |
136 | // call the library method
137 |
138 | int32_t error = svc_process(&_svcInput, &_svcOutput, _svcPersistent);
139 | if (error != SVC_ERROR_NONE) {
140 | Error_Handler();
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/Core/Inc/main.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #pragma once
8 |
9 | #include "stm32f4xx_hal.h"
10 |
11 | void Error_Handler();
12 |
13 | #define MUTE_Pin GPIO_PIN_2
14 | #define MUTE_GPIO_Port GPIOA
15 | #define LINK_LED_Pin GPIO_PIN_12
16 | #define LINK_LED_GPIO_Port GPIOB
17 | #define LIVE_LED_Pin GPIO_PIN_13
18 | #define LIVE_LED_GPIO_Port GPIOB
19 | #define LR_GPIO_Port GPIOB
20 | #define LR_Pin GPIO_PIN_1
21 |
--------------------------------------------------------------------------------
/Core/Inc/stm32f4xx_it.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #pragma once
8 |
9 | void NMI_Handler();
10 | void HardFault_Handler();
11 | void MemManage_Handler();
12 | void BusFault_Handler();
13 | void UsageFault_Handler();
14 | void SVC_Handler();
15 | void DebugMon_Handler();
16 | void PendSV_Handler();
17 | void SysTick_Handler();
18 | void DMA2_Stream0_IRQHandler();
19 | void OTG_FS_IRQHandler();
20 |
--------------------------------------------------------------------------------
/Core/Src/Audio.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #include "Application.h"
8 |
9 | Audio *Audio::_instance = nullptr;
10 |
--------------------------------------------------------------------------------
/Core/Src/UsbMicrophone.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #include "Application.h"
8 |
9 | extern "C" {
10 |
11 | void myMain() {
12 |
13 | Program program;
14 | program.run();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Core/Src/main.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the firmware for the Andy's Workshop USB Microphone.
3 | * Copyright 2021 Andy Brown. See https://andybrown.me.uk for project details.
4 | * This project is open source subject to the license published on https://andybrown.me.uk.
5 | */
6 |
7 | #include "main.h"
8 | #include "usb_device.h"
9 |
10 | I2S_HandleTypeDef hi2s1;
11 | DMA_HandleTypeDef hdma_spi1_rx;
12 | CRC_HandleTypeDef hcrc;
13 |
14 | extern void myMain();
15 |
16 | void SystemClock_Config();
17 | static void MX_GPIO_Init();
18 | static void MX_DMA_Init();
19 | static void MX_I2S1_Init();
20 | static void MX_CRC_Init();
21 |
22 | int main() {
23 |
24 | #ifdef SEMIHOSTING
25 | extern void initialise_monitor_handles(void);
26 | initialise_monitor_handles();
27 | setbuf(stdout, NULL);
28 | #endif
29 |
30 | // Reset of all peripherals, Initializes the Flash interface and the Systick.
31 | HAL_Init();
32 |
33 | // Configure the system clock */
34 | SystemClock_Config();
35 |
36 | // initialise the CRC unit for the SVC and GREQ audio modules
37 | MX_CRC_Init();
38 |
39 | // Initialize all configured peripherals
40 | MX_GPIO_Init();
41 | MX_DMA_Init();
42 | MX_I2S1_Init();
43 | MX_USB_DEVICE_Init();
44 |
45 | // Jump to the C++ implementation
46 |
47 | myMain();
48 | }
49 |
50 | void SystemClock_Config() {
51 | RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
52 | RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
53 | RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = { 0 };
54 |
55 | /** Configure the main internal regulator output voltage */
56 |
57 | __HAL_RCC_PWR_CLK_ENABLE();
58 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
59 |
60 | /** Initializes the RCC Oscillators according to the specified parameters in the RCC_OscInitTypeDef structure. */
61 |
62 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
63 | RCC_OscInitStruct.HSEState = RCC_HSE_ON;
64 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
65 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
66 | RCC_OscInitStruct.PLL.PLLM = 8;
67 | RCC_OscInitStruct.PLL.PLLN = 360;
68 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
69 | RCC_OscInitStruct.PLL.PLLQ = 7;
70 | RCC_OscInitStruct.PLL.PLLR = 2;
71 |
72 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
73 | Error_Handler();
74 | }
75 | /** Activate the Over-Drive mode */
76 |
77 | if (HAL_PWREx_EnableOverDrive() != HAL_OK) {
78 | Error_Handler();
79 | }
80 |
81 | /** Initializes the CPU, AHB and APB buses clocks */
82 |
83 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
84 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
85 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
86 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
87 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
88 |
89 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) {
90 | Error_Handler();
91 | }
92 |
93 | PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S_APB2 | RCC_PERIPHCLK_CLK48;
94 | PeriphClkInitStruct.PLLSAI.PLLSAIM = 4;
95 | PeriphClkInitStruct.PLLSAI.PLLSAIN = 96;
96 | PeriphClkInitStruct.PLLSAI.PLLSAIQ = 2;
97 | PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV4;
98 | PeriphClkInitStruct.PLLSAIDivQ = 1;
99 | PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48CLKSOURCE_PLLSAIP;
100 | PeriphClkInitStruct.I2sApb2ClockSelection = RCC_I2SAPB2CLKSOURCE_EXT;
101 |
102 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
103 | Error_Handler();
104 | }
105 | }
106 |
107 | static void MX_CRC_Init() {
108 |
109 | hcrc.Instance = CRC;
110 | if (HAL_CRC_Init(&hcrc) != HAL_OK) {
111 | Error_Handler();
112 | }
113 | __HAL_CRC_DR_RESET(&hcrc);
114 | }
115 |
116 | static void MX_I2S1_Init() {
117 |
118 | hi2s1.Instance = SPI1;
119 | hi2s1.Init.Mode = I2S_MODE_MASTER_RX;
120 | hi2s1.Init.Standard = I2S_STANDARD_PHILIPS;
121 | hi2s1.Init.DataFormat = I2S_DATAFORMAT_24B;
122 | hi2s1.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE;
123 | hi2s1.Init.AudioFreq = I2S_AUDIOFREQ_48K;
124 | hi2s1.Init.CPOL = I2S_CPOL_HIGH;
125 | hi2s1.Init.ClockSource = I2S_CLOCK_EXTERNAL;
126 | hi2s1.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_DISABLE;
127 |
128 | if (HAL_I2S_Init(&hi2s1) != HAL_OK) {
129 | Error_Handler();
130 | }
131 | }
132 |
133 | static void MX_DMA_Init() {
134 |
135 | /* DMA controller clock enable */
136 | __HAL_RCC_DMA2_CLK_ENABLE();
137 |
138 | /* DMA interrupt init */
139 | /* DMA2_Stream0_IRQn interrupt configuration */
140 |
141 | HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 0, 0);
142 | HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);
143 | }
144 |
145 | static void MX_GPIO_Init() {
146 | GPIO_InitTypeDef GPIO_InitStruct = { 0 };
147 |
148 | /* GPIO Ports Clock Enable */
149 | __HAL_RCC_GPIOH_CLK_ENABLE();
150 | __HAL_RCC_GPIOA_CLK_ENABLE();
151 | __HAL_RCC_GPIOB_CLK_ENABLE();
152 | __HAL_RCC_GPIOC_CLK_ENABLE();
153 |
154 | /*Configure GPIO pin Output Level */
155 | HAL_GPIO_WritePin(GPIOB, LINK_LED_Pin | LIVE_LED_Pin | LR_Pin, GPIO_PIN_RESET);
156 |
157 | /*Configure GPIO pin : MUTE_Pin */
158 | GPIO_InitStruct.Pin = MUTE_Pin;
159 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
160 | GPIO_InitStruct.Pull = GPIO_PULLUP;
161 | HAL_GPIO_Init(MUTE_GPIO_Port, &GPIO_InitStruct);
162 |
163 | /*Configure GPIO pins : LINK_LED_Pin LIVE_LED_Pin LR_Pin */
164 | GPIO_InitStruct.Pin = LINK_LED_Pin | LIVE_LED_Pin | LR_Pin;
165 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
166 | GPIO_InitStruct.Pull = GPIO_NOPULL;
167 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
168 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
169 |
170 | /*Configure GPIO pin : PC9 */
171 | GPIO_InitStruct.Pin = GPIO_PIN_9;
172 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
173 | GPIO_InitStruct.Pull = GPIO_NOPULL;
174 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
175 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
176 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
177 |
178 | }
179 |
180 | __attribute__((optimize("O0"))) void Error_Handler() {
181 |
182 | __disable_irq();
183 |
184 | /* Flash the LINK LED at 1Hz if there's a fatal error */
185 |
186 | for (;;) {
187 | HAL_GPIO_WritePin(LINK_LED_GPIO_Port, LINK_LED_Pin, GPIO_PIN_SET);
188 | for (uint32_t i = 0; i < 1000000; i++)
189 | ;
190 | HAL_GPIO_WritePin(LINK_LED_GPIO_Port, LINK_LED_Pin, GPIO_PIN_RESET);
191 | for (uint32_t i = 0; i < 1000000; i++)
192 | ;
193 | }
194 | }
195 |
196 | void HAL_I2S_ErrorCallback(I2S_HandleTypeDef *hi2s) {
197 | Error_Handler();
198 | }
199 |
200 | #ifdef USE_FULL_ASSERT
201 | /**
202 | * @brief Reports the name of the source file and the source line number
203 | * where the assert_param error has occurred.
204 | * @param file: pointer to the source file name
205 | * @param line: assert_param error line source number
206 | * @retval None
207 | */
208 | void assert_failed(uint8_t *file, uint32_t line)
209 | {
210 | /* USER CODE BEGIN 6 */
211 | /* User can add his own implementation to report the file name and line number,
212 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
213 | /* USER CODE END 6 */
214 | }
215 | #endif /* USE_FULL_ASSERT */
216 |
--------------------------------------------------------------------------------
/Core/Src/stm32f4xx_hal_msp.c:
--------------------------------------------------------------------------------
1 | #include "main.h"
2 |
3 | extern DMA_HandleTypeDef hdma_spi1_rx;
4 |
5 | void HAL_MspInit() {
6 | __HAL_RCC_SYSCFG_CLK_ENABLE();
7 | __HAL_RCC_PWR_CLK_ENABLE();
8 | }
9 |
10 | /**
11 | * @brief I2S MSP Initialization
12 | * This function configures the hardware resources used in this example
13 | * @param hi2s: I2S handle pointer
14 | * @retval None
15 | */
16 |
17 | void HAL_I2S_MspInit(I2S_HandleTypeDef *hi2s) {
18 |
19 | GPIO_InitTypeDef GPIO_InitStruct = { 0 };
20 |
21 | if (hi2s->Instance == SPI1) {
22 |
23 | /* Peripheral clock enable */
24 | __HAL_RCC_SPI1_CLK_ENABLE();
25 | __HAL_RCC_GPIOA_CLK_ENABLE();
26 |
27 | /**I2S1 GPIO Configuration
28 | PA4 ------> I2S1_WS
29 | PA5 ------> I2S1_CK
30 | PA7 ------> I2S1_SD
31 | */
32 |
33 | GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7;
34 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
35 | GPIO_InitStruct.Pull = GPIO_NOPULL;
36 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
37 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
38 |
39 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
40 |
41 | /* I2S1 DMA Init */
42 | /* SPI1_RX Init */
43 |
44 | hdma_spi1_rx.Instance = DMA2_Stream0;
45 | hdma_spi1_rx.Init.Channel = DMA_CHANNEL_3;
46 | hdma_spi1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
47 | hdma_spi1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
48 | hdma_spi1_rx.Init.MemInc = DMA_MINC_ENABLE;
49 | hdma_spi1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
50 | hdma_spi1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
51 | hdma_spi1_rx.Init.Mode = DMA_CIRCULAR;
52 | hdma_spi1_rx.Init.Priority = DMA_PRIORITY_LOW;
53 | hdma_spi1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
54 |
55 | if (HAL_DMA_Init(&hdma_spi1_rx) != HAL_OK) {
56 | Error_Handler();
57 | }
58 |
59 | __HAL_LINKDMA(hi2s, hdmarx, hdma_spi1_rx);
60 | }
61 | }
62 |
63 | /**
64 | * @brief I2S MSP De-Initialization
65 | * This function freeze the hardware resources used in this example
66 | * @param hi2s: I2S handle pointer
67 | * @retval None
68 | */
69 |
70 | void HAL_I2S_MspDeInit(I2S_HandleTypeDef *hi2s) {
71 | if (hi2s->Instance == SPI1) {
72 |
73 | /* Peripheral clock disable */
74 | __HAL_RCC_SPI1_CLK_DISABLE();
75 |
76 | /**I2S1 GPIO Configuration
77 | PA4 ------> I2S1_WS
78 | PA5 ------> I2S1_CK
79 | PA7 ------> I2S1_SD
80 | */
81 |
82 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7);
83 |
84 | /* I2S1 DMA DeInit */
85 |
86 | HAL_DMA_DeInit(hi2s->hdmarx);
87 | }
88 | }
89 |
90 | /**
91 | * @brief CRC MSP Initialization
92 | * This function configures the hardware resources used in this example
93 | * @param hcrc: CRC handle pointer
94 | * @retval None
95 | */
96 | void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc) {
97 | if (hcrc->Instance == CRC) {
98 | /* USER CODE BEGIN CRC_MspInit 0 */
99 |
100 | /* USER CODE END CRC_MspInit 0 */
101 | /* Peripheral clock enable */
102 | __HAL_RCC_CRC_CLK_ENABLE();
103 | /* USER CODE BEGIN CRC_MspInit 1 */
104 |
105 | /* USER CODE END CRC_MspInit 1 */
106 | }
107 |
108 | }
109 |
110 | /**
111 | * @brief CRC MSP De-Initialization
112 | * This function freeze the hardware resources used in this example
113 | * @param hcrc: CRC handle pointer
114 | * @retval None
115 | */
116 | void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc) {
117 | if (hcrc->Instance == CRC) {
118 | /* USER CODE BEGIN CRC_MspDeInit 0 */
119 |
120 | /* USER CODE END CRC_MspDeInit 0 */
121 | /* Peripheral clock disable */
122 | __HAL_RCC_CRC_CLK_DISABLE();
123 | /* USER CODE BEGIN CRC_MspDeInit 1 */
124 |
125 | /* USER CODE END CRC_MspDeInit 1 */
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/Core/Src/stm32f4xx_it.c:
--------------------------------------------------------------------------------
1 | #include "main.h"
2 | #include "stm32f4xx_it.h"
3 |
4 | extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
5 | extern DMA_HandleTypeDef hdma_spi1_rx;
6 |
7 | /**
8 | * @brief This function handles Non maskable interrupt.
9 | */
10 |
11 | void NMI_Handler() {
12 | while (1);
13 | }
14 |
15 | /**
16 | * @brief This function handles Hard fault interrupt.
17 | */
18 |
19 | void HardFault_Handler() {
20 | while (1);
21 | }
22 |
23 | /**
24 | * @brief This function handles Memory management fault.
25 | */
26 |
27 | void MemManage_Handler() {
28 | while (1);
29 | }
30 |
31 | /**
32 | * @brief This function handles Pre-fetch fault, memory access fault.
33 | */
34 |
35 | void BusFault_Handler() {
36 | while (1);
37 | }
38 |
39 | /**
40 | * @brief This function handles Undefined instruction or illegal state.
41 | */
42 |
43 | void UsageFault_Handler() {
44 | while (1);
45 | }
46 |
47 | /**
48 | * @brief This function handles System service call via SWI instruction.
49 | */
50 |
51 | void SVC_Handler() {
52 | }
53 |
54 | /**
55 | * @brief This function handles Debug monitor.
56 | */
57 |
58 | void DebugMon_Handler() {
59 | }
60 |
61 | /**
62 | * @brief This function handles Pendable request for system service.
63 | */
64 |
65 | void PendSV_Handler() {
66 | }
67 |
68 | /**
69 | * @brief This function handles System tick timer.
70 | */
71 |
72 | void SysTick_Handler() {
73 | HAL_IncTick();
74 | }
75 |
76 | /******************************************************************************/
77 | /* STM32F4xx Peripheral Interrupt Handlers */
78 | /* Add here the Interrupt Handlers for the used peripherals. */
79 | /* For the available peripheral interrupt handler names, */
80 | /* please refer to the startup file (startup_stm32f4xx.s). */
81 | /******************************************************************************/
82 |
83 | /**
84 | * @brief This function handles DMA2 stream0 global interrupt.
85 | */
86 | void DMA2_Stream0_IRQHandler() {
87 | HAL_DMA_IRQHandler(&hdma_spi1_rx);
88 | }
89 |
90 | /**
91 | * @brief This function handles USB On The Go FS global interrupt.
92 | */
93 |
94 | void OTG_FS_IRQHandler() {
95 | HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
96 | }
97 |
--------------------------------------------------------------------------------
/Core/Src/syscalls.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file syscalls.c
4 | * @author Auto-generated by STM32CubeIDE
5 | * @brief STM32CubeIDE Minimal System calls file
6 | *
7 | * For more information about which c-functions
8 | * need which of these lowlevel functions
9 | * please consult the Newlib libc-manual
10 | ******************************************************************************
11 | * @attention
12 | *
13 | * © Copyright (c) 2020 STMicroelectronics.
14 | * All rights reserved.
15 | *
16 | * This software component is licensed by ST under BSD 3-Clause license,
17 | * the "License"; You may not use this file except in compliance with the
18 | * License. You may obtain a copy of the License at:
19 | * opensource.org/licenses/BSD-3-Clause
20 | *
21 | ******************************************************************************
22 | */
23 |
24 | /* Includes */
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 |
34 |
35 | /* Variables */
36 | //#undef errno
37 | extern int errno;
38 | extern int __io_putchar(int ch) __attribute__((weak));
39 | extern int __io_getchar(void) __attribute__((weak));
40 |
41 | register char * stack_ptr asm("sp");
42 |
43 | char *__env[1] = { 0 };
44 | char **environ = __env;
45 |
46 |
47 | /* Functions */
48 | void initialise_monitor_handles()
49 | {
50 | }
51 |
52 | int _getpid(void)
53 | {
54 | return 1;
55 | }
56 |
57 | int _kill(int pid, int sig)
58 | {
59 | errno = EINVAL;
60 | return -1;
61 | }
62 |
63 | void _exit (int status)
64 | {
65 | _kill(status, -1);
66 | while (1) {} /* Make sure we hang here */
67 | }
68 |
69 | __attribute__((weak)) int _read(int file, char *ptr, int len)
70 | {
71 | int DataIdx;
72 |
73 | for (DataIdx = 0; DataIdx < len; DataIdx++)
74 | {
75 | *ptr++ = __io_getchar();
76 | }
77 |
78 | return len;
79 | }
80 |
81 | __attribute__((weak)) int _write(int file, char *ptr, int len)
82 | {
83 | int DataIdx;
84 |
85 | for (DataIdx = 0; DataIdx < len; DataIdx++)
86 | {
87 | __io_putchar(*ptr++);
88 | }
89 | return len;
90 | }
91 |
92 | int _close(int file)
93 | {
94 | return -1;
95 | }
96 |
97 |
98 | int _fstat(int file, struct stat *st)
99 | {
100 | st->st_mode = S_IFCHR;
101 | return 0;
102 | }
103 |
104 | int _isatty(int file)
105 | {
106 | return 1;
107 | }
108 |
109 | int _lseek(int file, int ptr, int dir)
110 | {
111 | return 0;
112 | }
113 |
114 | int _open(char *path, int flags, ...)
115 | {
116 | /* Pretend like we always fail */
117 | return -1;
118 | }
119 |
120 | int _wait(int *status)
121 | {
122 | errno = ECHILD;
123 | return -1;
124 | }
125 |
126 | int _unlink(char *name)
127 | {
128 | errno = ENOENT;
129 | return -1;
130 | }
131 |
132 | int _times(struct tms *buf)
133 | {
134 | return -1;
135 | }
136 |
137 | int _stat(char *file, struct stat *st)
138 | {
139 | st->st_mode = S_IFCHR;
140 | return 0;
141 | }
142 |
143 | int _link(char *old, char *new)
144 | {
145 | errno = EMLINK;
146 | return -1;
147 | }
148 |
149 | int _fork(void)
150 | {
151 | errno = EAGAIN;
152 | return -1;
153 | }
154 |
155 | int _execve(char *name, char **argv, char **env)
156 | {
157 | errno = ENOMEM;
158 | return -1;
159 | }
160 |
--------------------------------------------------------------------------------
/Core/Src/sysmem.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file sysmem.c
4 | * @author Generated by STM32CubeIDE
5 | * @brief STM32CubeIDE System Memory calls file
6 | *
7 | * For more information about which C functions
8 | * need which of these lowlevel functions
9 | * please consult the newlib libc manual
10 | ******************************************************************************
11 | * @attention
12 | *
13 | * © Copyright (c) 2020 STMicroelectronics.
14 | * All rights reserved.
15 | *
16 | * This software component is licensed by ST under BSD 3-Clause license,
17 | * the "License"; You may not use this file except in compliance with the
18 | * License. You may obtain a copy of the License at:
19 | * opensource.org/licenses/BSD-3-Clause
20 | *
21 | ******************************************************************************
22 | */
23 |
24 | /* Includes */
25 | #include
26 | #include
27 |
28 | /**
29 | * Pointer to the current high watermark of the heap usage
30 | */
31 | static uint8_t *__sbrk_heap_end = NULL;
32 |
33 | /**
34 | * @brief _sbrk() allocates memory to the newlib heap and is used by malloc
35 | * and others from the C library
36 | *
37 | * @verbatim
38 | * ############################################################################
39 | * # .data # .bss # newlib heap # MSP stack #
40 | * # # # # Reserved by _Min_Stack_Size #
41 | * ############################################################################
42 | * ^-- RAM start ^-- _end _estack, RAM end --^
43 | * @endverbatim
44 | *
45 | * This implementation starts allocating at the '_end' linker symbol
46 | * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack
47 | * The implementation considers '_estack' linker symbol to be RAM end
48 | * NOTE: If the MSP stack, at any point during execution, grows larger than the
49 | * reserved size, please increase the '_Min_Stack_Size'.
50 | *
51 | * @param incr Memory size
52 | * @return Pointer to allocated memory
53 | */
54 | void *_sbrk(ptrdiff_t incr)
55 | {
56 | extern uint8_t _end; /* Symbol defined in the linker script */
57 | extern uint8_t _estack; /* Symbol defined in the linker script */
58 | extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
59 | const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
60 | const uint8_t *max_heap = (uint8_t *)stack_limit;
61 | uint8_t *prev_heap_end;
62 |
63 | /* Initialize heap end at first call */
64 | if (NULL == __sbrk_heap_end)
65 | {
66 | __sbrk_heap_end = &_end;
67 | }
68 |
69 | /* Protect heap from growing into the reserved MSP stack */
70 | if (__sbrk_heap_end + incr > max_heap)
71 | {
72 | errno = ENOMEM;
73 | return (void *)-1;
74 | }
75 |
76 | prev_heap_end = __sbrk_heap_end;
77 | __sbrk_heap_end += incr;
78 |
79 | return (void *)prev_heap_end;
80 | }
81 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andysworkshop/usb-microphone/5eb348566212141c235f19b99f2e8b577523ca65/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h
--------------------------------------------------------------------------------
/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 | *
11 | * Redistribution and use in source and binary forms, with or without modification,
12 | * are permitted provided that the following conditions are met:
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
19 | * may be used to endorse or promote products derived from this software
20 | * without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | *
33 | ******************************************************************************
34 | */
35 |
36 | /** @addtogroup CMSIS
37 | * @{
38 | */
39 |
40 | /** @addtogroup stm32f4xx_system
41 | * @{
42 | */
43 |
44 | /**
45 | * @brief Define to prevent recursive inclusion
46 | */
47 | #ifndef __SYSTEM_STM32F4XX_H
48 | #define __SYSTEM_STM32F4XX_H
49 |
50 | #ifdef __cplusplus
51 | extern "C" {
52 | #endif
53 |
54 | /** @addtogroup STM32F4xx_System_Includes
55 | * @{
56 | */
57 |
58 | /**
59 | * @}
60 | */
61 |
62 |
63 | /** @addtogroup STM32F4xx_System_Exported_types
64 | * @{
65 | */
66 | /* This variable is updated in three ways:
67 | 1) by calling CMSIS function SystemCoreClockUpdate()
68 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq()
69 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
70 | Note: If you use this function to configure the system clock; then there
71 | is no need to call the 2 first functions listed above, since SystemCoreClock
72 | variable is updated automatically.
73 | */
74 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
75 |
76 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */
77 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */
78 |
79 | /**
80 | * @}
81 | */
82 |
83 | /** @addtogroup STM32F4xx_System_Exported_Constants
84 | * @{
85 | */
86 |
87 | /**
88 | * @}
89 | */
90 |
91 | /** @addtogroup STM32F4xx_System_Exported_Macros
92 | * @{
93 | */
94 |
95 | /**
96 | * @}
97 | */
98 |
99 | /** @addtogroup STM32F4xx_System_Exported_Functions
100 | * @{
101 | */
102 |
103 | extern void SystemInit(void);
104 | extern void SystemCoreClockUpdate(void);
105 | /**
106 | * @}
107 | */
108 |
109 | #ifdef __cplusplus
110 | }
111 | #endif
112 |
113 | #endif /*__SYSTEM_STM32F4XX_H */
114 |
115 | /**
116 | * @}
117 | */
118 |
119 | /**
120 | * @}
121 | */
122 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
123 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Include/cmsis_compiler.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************//**
2 | * @file cmsis_compiler.h
3 | * @brief CMSIS compiler generic header file
4 | * @version V5.0.4
5 | * @date 10. January 2018
6 | ******************************************************************************/
7 | /*
8 | * Copyright (c) 2009-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 | #ifndef __CMSIS_COMPILER_H
26 | #define __CMSIS_COMPILER_H
27 |
28 | #include
29 |
30 | /*
31 | * Arm Compiler 4/5
32 | */
33 | #if defined ( __CC_ARM )
34 | #include "cmsis_armcc.h"
35 |
36 |
37 | /*
38 | * Arm Compiler 6 (armclang)
39 | */
40 | #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
41 | #include "cmsis_armclang.h"
42 |
43 |
44 | /*
45 | * GNU Compiler
46 | */
47 | #elif defined ( __GNUC__ )
48 | #include "cmsis_gcc.h"
49 |
50 |
51 | /*
52 | * IAR Compiler
53 | */
54 | #elif defined ( __ICCARM__ )
55 | #include
56 |
57 |
58 | /*
59 | * TI Arm Compiler
60 | */
61 | #elif defined ( __TI_ARM__ )
62 | #include
63 |
64 | #ifndef __ASM
65 | #define __ASM __asm
66 | #endif
67 | #ifndef __INLINE
68 | #define __INLINE inline
69 | #endif
70 | #ifndef __STATIC_INLINE
71 | #define __STATIC_INLINE static inline
72 | #endif
73 | #ifndef __STATIC_FORCEINLINE
74 | #define __STATIC_FORCEINLINE __STATIC_INLINE
75 | #endif
76 | #ifndef __NO_RETURN
77 | #define __NO_RETURN __attribute__((noreturn))
78 | #endif
79 | #ifndef __USED
80 | #define __USED __attribute__((used))
81 | #endif
82 | #ifndef __WEAK
83 | #define __WEAK __attribute__((weak))
84 | #endif
85 | #ifndef __PACKED
86 | #define __PACKED __attribute__((packed))
87 | #endif
88 | #ifndef __PACKED_STRUCT
89 | #define __PACKED_STRUCT struct __attribute__((packed))
90 | #endif
91 | #ifndef __PACKED_UNION
92 | #define __PACKED_UNION union __attribute__((packed))
93 | #endif
94 | #ifndef __UNALIGNED_UINT32 /* deprecated */
95 | struct __attribute__((packed)) T_UINT32 { uint32_t v; };
96 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
97 | #endif
98 | #ifndef __UNALIGNED_UINT16_WRITE
99 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
100 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
101 | #endif
102 | #ifndef __UNALIGNED_UINT16_READ
103 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
104 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
105 | #endif
106 | #ifndef __UNALIGNED_UINT32_WRITE
107 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
108 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
109 | #endif
110 | #ifndef __UNALIGNED_UINT32_READ
111 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
112 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
113 | #endif
114 | #ifndef __ALIGNED
115 | #define __ALIGNED(x) __attribute__((aligned(x)))
116 | #endif
117 | #ifndef __RESTRICT
118 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
119 | #define __RESTRICT
120 | #endif
121 |
122 |
123 | /*
124 | * TASKING Compiler
125 | */
126 | #elif defined ( __TASKING__ )
127 | /*
128 | * The CMSIS functions have been implemented as intrinsics in the compiler.
129 | * Please use "carm -?i" to get an up to date list of all intrinsics,
130 | * Including the CMSIS ones.
131 | */
132 |
133 | #ifndef __ASM
134 | #define __ASM __asm
135 | #endif
136 | #ifndef __INLINE
137 | #define __INLINE inline
138 | #endif
139 | #ifndef __STATIC_INLINE
140 | #define __STATIC_INLINE static inline
141 | #endif
142 | #ifndef __STATIC_FORCEINLINE
143 | #define __STATIC_FORCEINLINE __STATIC_INLINE
144 | #endif
145 | #ifndef __NO_RETURN
146 | #define __NO_RETURN __attribute__((noreturn))
147 | #endif
148 | #ifndef __USED
149 | #define __USED __attribute__((used))
150 | #endif
151 | #ifndef __WEAK
152 | #define __WEAK __attribute__((weak))
153 | #endif
154 | #ifndef __PACKED
155 | #define __PACKED __packed__
156 | #endif
157 | #ifndef __PACKED_STRUCT
158 | #define __PACKED_STRUCT struct __packed__
159 | #endif
160 | #ifndef __PACKED_UNION
161 | #define __PACKED_UNION union __packed__
162 | #endif
163 | #ifndef __UNALIGNED_UINT32 /* deprecated */
164 | struct __packed__ T_UINT32 { uint32_t v; };
165 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
166 | #endif
167 | #ifndef __UNALIGNED_UINT16_WRITE
168 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
169 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
170 | #endif
171 | #ifndef __UNALIGNED_UINT16_READ
172 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
173 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
174 | #endif
175 | #ifndef __UNALIGNED_UINT32_WRITE
176 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
177 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
178 | #endif
179 | #ifndef __UNALIGNED_UINT32_READ
180 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
181 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
182 | #endif
183 | #ifndef __ALIGNED
184 | #define __ALIGNED(x) __align(x)
185 | #endif
186 | #ifndef __RESTRICT
187 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
188 | #define __RESTRICT
189 | #endif
190 |
191 |
192 | /*
193 | * COSMIC Compiler
194 | */
195 | #elif defined ( __CSMC__ )
196 | #include
197 |
198 | #ifndef __ASM
199 | #define __ASM _asm
200 | #endif
201 | #ifndef __INLINE
202 | #define __INLINE inline
203 | #endif
204 | #ifndef __STATIC_INLINE
205 | #define __STATIC_INLINE static inline
206 | #endif
207 | #ifndef __STATIC_FORCEINLINE
208 | #define __STATIC_FORCEINLINE __STATIC_INLINE
209 | #endif
210 | #ifndef __NO_RETURN
211 | // NO RETURN is automatically detected hence no warning here
212 | #define __NO_RETURN
213 | #endif
214 | #ifndef __USED
215 | #warning No compiler specific solution for __USED. __USED is ignored.
216 | #define __USED
217 | #endif
218 | #ifndef __WEAK
219 | #define __WEAK __weak
220 | #endif
221 | #ifndef __PACKED
222 | #define __PACKED @packed
223 | #endif
224 | #ifndef __PACKED_STRUCT
225 | #define __PACKED_STRUCT @packed struct
226 | #endif
227 | #ifndef __PACKED_UNION
228 | #define __PACKED_UNION @packed union
229 | #endif
230 | #ifndef __UNALIGNED_UINT32 /* deprecated */
231 | @packed struct T_UINT32 { uint32_t v; };
232 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
233 | #endif
234 | #ifndef __UNALIGNED_UINT16_WRITE
235 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
236 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
237 | #endif
238 | #ifndef __UNALIGNED_UINT16_READ
239 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
240 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
241 | #endif
242 | #ifndef __UNALIGNED_UINT32_WRITE
243 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
244 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
245 | #endif
246 | #ifndef __UNALIGNED_UINT32_READ
247 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
248 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
249 | #endif
250 | #ifndef __ALIGNED
251 | #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
252 | #define __ALIGNED(x)
253 | #endif
254 | #ifndef __RESTRICT
255 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
256 | #define __RESTRICT
257 | #endif
258 |
259 |
260 | #else
261 | #error Unknown compiler.
262 | #endif
263 |
264 |
265 | #endif /* __CMSIS_COMPILER_H */
266 |
267 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Include/cmsis_version.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************//**
2 | * @file cmsis_version.h
3 | * @brief CMSIS Core(M) Version definitions
4 | * @version V5.0.2
5 | * @date 19. April 2017
6 | ******************************************************************************/
7 | /*
8 | * Copyright (c) 2009-2017 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 ( 1U) /*!< [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_crc.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_crc.h
4 | * @author MCD Application Team
5 | * @brief Header file of CRC HAL module.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2016 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under BSD 3-Clause license,
13 | * the "License"; You may not use this file except in compliance with the
14 | * License. You may obtain a copy of the License at:
15 | * opensource.org/licenses/BSD-3-Clause
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef STM32F4xx_HAL_CRC_H
22 | #define STM32F4xx_HAL_CRC_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "stm32f4xx_hal_def.h"
30 |
31 | /** @addtogroup STM32F4xx_HAL_Driver
32 | * @{
33 | */
34 |
35 | /** @addtogroup CRC
36 | * @{
37 | */
38 |
39 | /* Exported types ------------------------------------------------------------*/
40 | /** @defgroup CRC_Exported_Types CRC Exported Types
41 | * @{
42 | */
43 |
44 | /**
45 | * @brief CRC HAL State Structure definition
46 | */
47 | typedef enum
48 | {
49 | HAL_CRC_STATE_RESET = 0x00U, /*!< CRC not yet initialized or disabled */
50 | HAL_CRC_STATE_READY = 0x01U, /*!< CRC initialized and ready for use */
51 | HAL_CRC_STATE_BUSY = 0x02U, /*!< CRC internal process is ongoing */
52 | HAL_CRC_STATE_TIMEOUT = 0x03U, /*!< CRC timeout state */
53 | HAL_CRC_STATE_ERROR = 0x04U /*!< CRC error state */
54 | } HAL_CRC_StateTypeDef;
55 |
56 |
57 | /**
58 | * @brief CRC Handle Structure definition
59 | */
60 | typedef struct
61 | {
62 | CRC_TypeDef *Instance; /*!< Register base address */
63 |
64 | HAL_LockTypeDef Lock; /*!< CRC Locking object */
65 |
66 | __IO HAL_CRC_StateTypeDef State; /*!< CRC communication state */
67 |
68 | } CRC_HandleTypeDef;
69 | /**
70 | * @}
71 | */
72 |
73 | /* Exported constants --------------------------------------------------------*/
74 | /** @defgroup CRC_Exported_Constants CRC Exported Constants
75 | * @{
76 | */
77 |
78 | /**
79 | * @}
80 | */
81 |
82 | /* Exported macros -----------------------------------------------------------*/
83 | /** @defgroup CRC_Exported_Macros CRC Exported Macros
84 | * @{
85 | */
86 |
87 | /** @brief Reset CRC handle state.
88 | * @param __HANDLE__ CRC handle.
89 | * @retval None
90 | */
91 | #define __HAL_CRC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRC_STATE_RESET)
92 |
93 | /**
94 | * @brief Reset CRC Data Register.
95 | * @param __HANDLE__ CRC handle
96 | * @retval None
97 | */
98 | #define __HAL_CRC_DR_RESET(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRC_CR_RESET)
99 |
100 | /**
101 | * @brief Store data in the Independent Data (ID) register.
102 | * @param __HANDLE__ CRC handle
103 | * @param __VALUE__ Value to be stored in the ID register
104 | * @note Refer to the Reference Manual to get the authorized __VALUE__ length in bits
105 | * @retval None
106 | */
107 | #define __HAL_CRC_SET_IDR(__HANDLE__, __VALUE__) (WRITE_REG((__HANDLE__)->Instance->IDR, (__VALUE__)))
108 |
109 | /**
110 | * @brief Return the data stored in the Independent Data (ID) register.
111 | * @param __HANDLE__ CRC handle
112 | * @note Refer to the Reference Manual to get the authorized __VALUE__ length in bits
113 | * @retval Value of the ID register
114 | */
115 | #define __HAL_CRC_GET_IDR(__HANDLE__) (((__HANDLE__)->Instance->IDR) & CRC_IDR_IDR)
116 | /**
117 | * @}
118 | */
119 |
120 |
121 | /* Private macros --------------------------------------------------------*/
122 | /** @defgroup CRC_Private_Macros CRC Private Macros
123 | * @{
124 | */
125 |
126 | /**
127 | * @}
128 | */
129 |
130 | /* Exported functions --------------------------------------------------------*/
131 | /** @defgroup CRC_Exported_Functions CRC Exported Functions
132 | * @{
133 | */
134 |
135 | /* Initialization and de-initialization functions ****************************/
136 | /** @defgroup CRC_Exported_Functions_Group1 Initialization and de-initialization functions
137 | * @{
138 | */
139 | HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc);
140 | HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc);
141 | void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc);
142 | void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc);
143 | /**
144 | * @}
145 | */
146 |
147 | /* Peripheral Control functions ***********************************************/
148 | /** @defgroup CRC_Exported_Functions_Group2 Peripheral Control functions
149 | * @{
150 | */
151 | uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength);
152 | uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength);
153 | /**
154 | * @}
155 | */
156 |
157 | /* Peripheral State and Error functions ***************************************/
158 | /** @defgroup CRC_Exported_Functions_Group3 Peripheral State functions
159 | * @{
160 | */
161 | HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc);
162 | /**
163 | * @}
164 | */
165 |
166 | /**
167 | * @}
168 | */
169 |
170 | /**
171 | * @}
172 | */
173 |
174 | /**
175 | * @}
176 | */
177 |
178 | #ifdef __cplusplus
179 | }
180 | #endif
181 |
182 | #endif /* STM32F4xx_HAL_CRC_H */
183 |
184 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
185 |
--------------------------------------------------------------------------------
/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_def.h
4 | * @author MCD Application Team
5 | * @brief This file contains HAL common defines, enumeration, macros and
6 | * structures definitions.
7 | ******************************************************************************
8 | * @attention
9 | *
10 | * © Copyright (c) 2017 STMicroelectronics.
11 | * All rights reserved.
12 | *
13 | * This software component is licensed by ST under BSD 3-Clause license,
14 | * the "License"; You may not use this file except in compliance with the
15 | * License. You may obtain a copy of the License at:
16 | * opensource.org/licenses/BSD-3-Clause
17 | *
18 | ******************************************************************************
19 | */
20 |
21 | /* Define to prevent recursive inclusion -------------------------------------*/
22 | #ifndef __STM32F4xx_HAL_DEF
23 | #define __STM32F4xx_HAL_DEF
24 |
25 | #ifdef __cplusplus
26 | extern "C" {
27 | #endif
28 |
29 | /* Includes ------------------------------------------------------------------*/
30 | #include "stm32f4xx.h"
31 | #include "Legacy/stm32_hal_legacy.h"
32 | #include
33 |
34 | /* Exported types ------------------------------------------------------------*/
35 |
36 | /**
37 | * @brief HAL Status structures definition
38 | */
39 | typedef enum
40 | {
41 | HAL_OK = 0x00U,
42 | HAL_ERROR = 0x01U,
43 | HAL_BUSY = 0x02U,
44 | HAL_TIMEOUT = 0x03U
45 | } HAL_StatusTypeDef;
46 |
47 | /**
48 | * @brief HAL Lock structures definition
49 | */
50 | typedef enum
51 | {
52 | HAL_UNLOCKED = 0x00U,
53 | HAL_LOCKED = 0x01U
54 | } HAL_LockTypeDef;
55 |
56 | /* Exported macro ------------------------------------------------------------*/
57 |
58 | #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */
59 |
60 | #define HAL_MAX_DELAY 0xFFFFFFFFU
61 |
62 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) == (BIT))
63 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U)
64 |
65 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \
66 | do{ \
67 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \
68 | (__DMA_HANDLE__).Parent = (__HANDLE__); \
69 | } while(0U)
70 |
71 | /** @brief Reset the Handle's State field.
72 | * @param __HANDLE__ specifies the Peripheral Handle.
73 | * @note This macro can be used for the following purpose:
74 | * - When the Handle is declared as local variable; before passing it as parameter
75 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro
76 | * to set to 0 the Handle's "State" field.
77 | * Otherwise, "State" field may have any random value and the first time the function
78 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed
79 | * (i.e. HAL_PPP_MspInit() will not be executed).
80 | * - When there is a need to reconfigure the low level hardware: instead of calling
81 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init().
82 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function
83 | * HAL_PPP_MspInit() which will reconfigure the low level hardware.
84 | * @retval None
85 | */
86 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U)
87 |
88 | #if (USE_RTOS == 1U)
89 | /* Reserved for future use */
90 | #error "USE_RTOS should be 0 in the current HAL release"
91 | #else
92 | #define __HAL_LOCK(__HANDLE__) \
93 | do{ \
94 | if((__HANDLE__)->Lock == HAL_LOCKED) \
95 | { \
96 | return HAL_BUSY; \
97 | } \
98 | else \
99 | { \
100 | (__HANDLE__)->Lock = HAL_LOCKED; \
101 | } \
102 | }while (0U)
103 |
104 | #define __HAL_UNLOCK(__HANDLE__) \
105 | do{ \
106 | (__HANDLE__)->Lock = HAL_UNLOCKED; \
107 | }while (0U)
108 | #endif /* USE_RTOS */
109 |
110 | #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
111 | #ifndef __weak
112 | #define __weak __attribute__((weak))
113 | #endif /* __weak */
114 | #ifndef __packed
115 | #define __packed __attribute__((__packed__))
116 | #endif /* __packed */
117 | #endif /* __GNUC__ */
118 |
119 |
120 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */
121 | #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
122 | #ifndef __ALIGN_END
123 | #define __ALIGN_END __attribute__ ((aligned (4)))
124 | #endif /* __ALIGN_END */
125 | #ifndef __ALIGN_BEGIN
126 | #define __ALIGN_BEGIN
127 | #endif /* __ALIGN_BEGIN */
128 | #else
129 | #ifndef __ALIGN_END
130 | #define __ALIGN_END
131 | #endif /* __ALIGN_END */
132 | #ifndef __ALIGN_BEGIN
133 | #if defined (__CC_ARM) /* ARM Compiler */
134 | #define __ALIGN_BEGIN __align(4)
135 | #elif defined (__ICCARM__) /* IAR Compiler */
136 | #define __ALIGN_BEGIN
137 | #endif /* __CC_ARM */
138 | #endif /* __ALIGN_BEGIN */
139 | #endif /* __GNUC__ */
140 |
141 |
142 | /**
143 | * @brief __RAM_FUNC definition
144 | */
145 | #if defined ( __CC_ARM )
146 | /* ARM Compiler
147 | ------------
148 | RAM functions are defined using the toolchain options.
149 | Functions that are executed in RAM should reside in a separate source module.
150 | Using the 'Options for File' dialog you can simply change the 'Code / Const'
151 | area of a module to a memory space in physical RAM.
152 | Available memory areas are declared in the 'Target' tab of the 'Options for Target'
153 | dialog.
154 | */
155 | #define __RAM_FUNC
156 |
157 | #elif defined ( __ICCARM__ )
158 | /* ICCARM Compiler
159 | ---------------
160 | RAM functions are defined using a specific toolchain keyword "__ramfunc".
161 | */
162 | #define __RAM_FUNC __ramfunc
163 |
164 | #elif defined ( __GNUC__ )
165 | /* GNU Compiler
166 | ------------
167 | RAM functions are defined using a specific toolchain attribute
168 | "__attribute__((section(".RamFunc")))".
169 | */
170 | #define __RAM_FUNC __attribute__((section(".RamFunc")))
171 |
172 | #endif
173 |
174 | /**
175 | * @brief __NOINLINE definition
176 | */
177 | #if defined ( __CC_ARM ) || defined ( __GNUC__ )
178 | /* ARM & GNUCompiler
179 | ----------------
180 | */
181 | #define __NOINLINE __attribute__ ( (noinline) )
182 |
183 | #elif defined ( __ICCARM__ )
184 | /* ICCARM Compiler
185 | ---------------
186 | */
187 | #define __NOINLINE _Pragma("optimize = no_inline")
188 |
189 | #endif
190 |
191 | #ifdef __cplusplus
192 | }
193 | #endif
194 |
195 | #endif /* ___STM32F4xx_HAL_DEF */
196 |
197 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
198 |
--------------------------------------------------------------------------------
/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 component is licensed by ST under BSD 3-Clause license,
13 | * the "License"; You may not use this file except in compliance with the
14 | * License. You may obtain a copy of the License at:
15 | * opensource.org/licenses/BSD-3-Clause
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __STM32F4xx_HAL_DMA_EX_H
22 | #define __STM32F4xx_HAL_DMA_EX_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "stm32f4xx_hal_def.h"
30 |
31 | /** @addtogroup STM32F4xx_HAL_Driver
32 | * @{
33 | */
34 |
35 | /** @addtogroup DMAEx
36 | * @{
37 | */
38 |
39 | /* Exported types ------------------------------------------------------------*/
40 | /** @defgroup DMAEx_Exported_Types DMAEx Exported Types
41 | * @brief DMAEx Exported types
42 | * @{
43 | */
44 |
45 | /**
46 | * @brief HAL DMA Memory definition
47 | */
48 | typedef enum
49 | {
50 | MEMORY0 = 0x00U, /*!< Memory 0 */
51 | MEMORY1 = 0x01U /*!< Memory 1 */
52 | }HAL_DMA_MemoryTypeDef;
53 |
54 | /**
55 | * @}
56 | */
57 |
58 | /* Exported functions --------------------------------------------------------*/
59 | /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions
60 | * @brief DMAEx Exported functions
61 | * @{
62 | */
63 |
64 | /** @defgroup DMAEx_Exported_Functions_Group1 Extended features functions
65 | * @brief Extended features functions
66 | * @{
67 | */
68 |
69 | /* IO operation functions *******************************************************/
70 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength);
71 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength);
72 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory);
73 |
74 | /**
75 | * @}
76 | */
77 | /**
78 | * @}
79 | */
80 |
81 | /* Private functions ---------------------------------------------------------*/
82 | /** @defgroup DMAEx_Private_Functions DMAEx Private Functions
83 | * @brief DMAEx Private functions
84 | * @{
85 | */
86 | /**
87 | * @}
88 | */
89 |
90 | /**
91 | * @}
92 | */
93 |
94 | /**
95 | * @}
96 | */
97 |
98 | #ifdef __cplusplus
99 | }
100 | #endif
101 |
102 | #endif /*__STM32F4xx_HAL_DMA_EX_H*/
103 |
104 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
105 |
--------------------------------------------------------------------------------
/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 component is licensed by ST under BSD 3-Clause license,
13 | * the "License"; You may not use this file except in compliance with the
14 | * License. You may obtain a copy of the License at:
15 | * opensource.org/licenses/BSD-3-Clause
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H
22 | #define __STM32F4xx_FLASH_RAMFUNC_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\
28 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx)
29 |
30 | /* Includes ------------------------------------------------------------------*/
31 | #include "stm32f4xx_hal_def.h"
32 |
33 | /** @addtogroup STM32F4xx_HAL_Driver
34 | * @{
35 | */
36 |
37 | /** @addtogroup FLASH_RAMFUNC
38 | * @{
39 | */
40 |
41 | /* Exported types ------------------------------------------------------------*/
42 | /* Exported macro ------------------------------------------------------------*/
43 | /* Exported functions --------------------------------------------------------*/
44 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions
45 | * @{
46 | */
47 |
48 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1
49 | * @{
50 | */
51 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void);
52 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void);
53 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void);
54 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void);
55 | /**
56 | * @}
57 | */
58 |
59 | /**
60 | * @}
61 | */
62 |
63 | /**
64 | * @}
65 | */
66 |
67 | /**
68 | * @}
69 | */
70 |
71 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */
72 | #ifdef __cplusplus
73 | }
74 | #endif
75 |
76 |
77 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */
78 |
79 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
80 |
--------------------------------------------------------------------------------
/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s_ex.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_i2s_ex.h
4 | * @author MCD Application Team
5 | * @brief Header file of I2S HAL module.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2016 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under BSD 3-Clause license,
13 | * the "License"; You may not use this file except in compliance with the
14 | * License. You may obtain a copy of the License at:
15 | * opensource.org/licenses/BSD-3-Clause
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef STM32F4xx_HAL_I2S_EX_H
22 | #define STM32F4xx_HAL_I2S_EX_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "stm32f4xx_hal_def.h"
30 |
31 | /** @addtogroup STM32F4xx_HAL_Driver
32 | * @{
33 | */
34 | #if defined(SPI_I2S_FULLDUPLEX_SUPPORT)
35 | /** @addtogroup I2SEx I2SEx
36 | * @{
37 | */
38 |
39 | /* Exported types ------------------------------------------------------------*/
40 | /* Exported constants --------------------------------------------------------*/
41 | /* Exported macros -----------------------------------------------------------*/
42 | /** @defgroup I2SEx_Exported_Macros I2S Extended Exported Macros
43 | * @{
44 | */
45 |
46 | #define I2SxEXT(__INSTANCE__) ((__INSTANCE__) == (SPI2)? (SPI_TypeDef *)(I2S2ext_BASE): (SPI_TypeDef *)(I2S3ext_BASE))
47 |
48 | /** @brief Enable or disable the specified I2SExt peripheral.
49 | * @param __HANDLE__ specifies the I2S Handle.
50 | * @retval None
51 | */
52 | #define __HAL_I2SEXT_ENABLE(__HANDLE__) (I2SxEXT((__HANDLE__)->Instance)->I2SCFGR |= SPI_I2SCFGR_I2SE)
53 | #define __HAL_I2SEXT_DISABLE(__HANDLE__) (I2SxEXT((__HANDLE__)->Instance)->I2SCFGR &= ~SPI_I2SCFGR_I2SE)
54 |
55 | /** @brief Enable or disable the specified I2SExt interrupts.
56 | * @param __HANDLE__ specifies the I2S Handle.
57 | * @param __INTERRUPT__ specifies the interrupt source to enable or disable.
58 | * This parameter can be one of the following values:
59 | * @arg I2S_IT_TXE: Tx buffer empty interrupt enable
60 | * @arg I2S_IT_RXNE: RX buffer not empty interrupt enable
61 | * @arg I2S_IT_ERR: Error interrupt enable
62 | * @retval None
63 | */
64 | #define __HAL_I2SEXT_ENABLE_IT(__HANDLE__, __INTERRUPT__) (I2SxEXT((__HANDLE__)->Instance)->CR2 |= (__INTERRUPT__))
65 | #define __HAL_I2SEXT_DISABLE_IT(__HANDLE__, __INTERRUPT__) (I2SxEXT((__HANDLE__)->Instance)->CR2 &= ~(__INTERRUPT__))
66 |
67 | /** @brief Checks if the specified I2SExt interrupt source is enabled or disabled.
68 | * @param __HANDLE__ specifies the I2S Handle.
69 | * This parameter can be I2S where x: 1, 2, or 3 to select the I2S peripheral.
70 | * @param __INTERRUPT__ specifies the I2S interrupt source to check.
71 | * This parameter can be one of the following values:
72 | * @arg I2S_IT_TXE: Tx buffer empty interrupt enable
73 | * @arg I2S_IT_RXNE: RX buffer not empty interrupt enable
74 | * @arg I2S_IT_ERR: Error interrupt enable
75 | * @retval The new state of __IT__ (TRUE or FALSE).
76 | */
77 | #define __HAL_I2SEXT_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((I2SxEXT((__HANDLE__)->Instance)->CR2\
78 | & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
79 |
80 | /** @brief Checks whether the specified I2SExt flag is set or not.
81 | * @param __HANDLE__ specifies the I2S Handle.
82 | * @param __FLAG__ specifies the flag to check.
83 | * This parameter can be one of the following values:
84 | * @arg I2S_FLAG_RXNE: Receive buffer not empty flag
85 | * @arg I2S_FLAG_TXE: Transmit buffer empty flag
86 | * @arg I2S_FLAG_UDR: Underrun flag
87 | * @arg I2S_FLAG_OVR: Overrun flag
88 | * @arg I2S_FLAG_FRE: Frame error flag
89 | * @arg I2S_FLAG_CHSIDE: Channel Side flag
90 | * @arg I2S_FLAG_BSY: Busy flag
91 | * @retval The new state of __FLAG__ (TRUE or FALSE).
92 | */
93 | #define __HAL_I2SEXT_GET_FLAG(__HANDLE__, __FLAG__) (((I2SxEXT((__HANDLE__)->Instance)->SR) & (__FLAG__)) == (__FLAG__))
94 |
95 | /** @brief Clears the I2SExt OVR pending flag.
96 | * @param __HANDLE__ specifies the I2S Handle.
97 | * @retval None
98 | */
99 | #define __HAL_I2SEXT_CLEAR_OVRFLAG(__HANDLE__) do{ \
100 | __IO uint32_t tmpreg_ovr = 0x00U; \
101 | tmpreg_ovr = I2SxEXT((__HANDLE__)->Instance)->DR;\
102 | tmpreg_ovr = I2SxEXT((__HANDLE__)->Instance)->SR;\
103 | UNUSED(tmpreg_ovr); \
104 | }while(0U)
105 | /** @brief Clears the I2SExt UDR pending flag.
106 | * @param __HANDLE__ specifies the I2S Handle.
107 | * @retval None
108 | */
109 | #define __HAL_I2SEXT_CLEAR_UDRFLAG(__HANDLE__) do{ \
110 | __IO uint32_t tmpreg_udr = 0x00U; \
111 | tmpreg_udr = I2SxEXT((__HANDLE__)->Instance)->SR;\
112 | UNUSED(tmpreg_udr); \
113 | }while(0U)
114 | /** @brief Flush the I2S and I2SExt DR Registers.
115 | * @param __HANDLE__ specifies the I2S Handle.
116 | * @retval None
117 | */
118 | #define __HAL_I2SEXT_FLUSH_RX_DR(__HANDLE__) do{ \
119 | __IO uint32_t tmpreg_dr = 0x00U; \
120 | tmpreg_dr = I2SxEXT((__HANDLE__)->Instance)->DR; \
121 | tmpreg_dr = ((__HANDLE__)->Instance->DR); \
122 | UNUSED(tmpreg_dr); \
123 | }while(0U)
124 | /**
125 | * @}
126 | */
127 |
128 | /* Exported functions --------------------------------------------------------*/
129 | /** @addtogroup I2SEx_Exported_Functions I2S Extended Exported Functions
130 | * @{
131 | */
132 |
133 | /** @addtogroup I2SEx_Exported_Functions_Group1 I2S Extended IO operation functions
134 | * @{
135 | */
136 |
137 | /* Extended features functions *************************************************/
138 | /* Blocking mode: Polling */
139 | HAL_StatusTypeDef HAL_I2SEx_TransmitReceive(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData,
140 | uint16_t Size, uint32_t Timeout);
141 | /* Non-Blocking mode: Interrupt */
142 | HAL_StatusTypeDef HAL_I2SEx_TransmitReceive_IT(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData,
143 | uint16_t Size);
144 | /* Non-Blocking mode: DMA */
145 | HAL_StatusTypeDef HAL_I2SEx_TransmitReceive_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData,
146 | uint16_t Size);
147 | /* I2S IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
148 | void HAL_I2SEx_FullDuplex_IRQHandler(I2S_HandleTypeDef *hi2s);
149 | void HAL_I2SEx_TxRxHalfCpltCallback(I2S_HandleTypeDef *hi2s);
150 | void HAL_I2SEx_TxRxCpltCallback(I2S_HandleTypeDef *hi2s);
151 | /**
152 | * @}
153 | */
154 |
155 | /**
156 | * @}
157 | */
158 | /* Private types -------------------------------------------------------------*/
159 | /* Private variables ---------------------------------------------------------*/
160 | /* Private constants ---------------------------------------------------------*/
161 | /* Private macros ------------------------------------------------------------*/
162 |
163 | /**
164 | * @}
165 | */
166 |
167 | /* Private functions ---------------------------------------------------------*/
168 |
169 | /**
170 | * @}
171 | */
172 |
173 | #endif /* SPI_I2S_FULLDUPLEX_SUPPORT */
174 | /**
175 | * @}
176 | */
177 |
178 | #ifdef __cplusplus
179 | }
180 | #endif
181 |
182 |
183 | #endif /* STM32F4xx_HAL_I2S_EX_H */
184 |
185 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
186 |
--------------------------------------------------------------------------------
/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 component is licensed by ST under BSD 3-Clause license,
13 | * the "License"; You may not use this file except in compliance with the
14 | * License. You may obtain a copy of the License at:
15 | * opensource.org/licenses/BSD-3-Clause
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef STM32F4xx_HAL_PCD_EX_H
22 | #define STM32F4xx_HAL_PCD_EX_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "stm32f4xx_hal_def.h"
30 |
31 | #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
32 | /** @addtogroup STM32F4xx_HAL_Driver
33 | * @{
34 | */
35 |
36 | /** @addtogroup PCDEx
37 | * @{
38 | */
39 | /* Exported types ------------------------------------------------------------*/
40 | /* Exported constants --------------------------------------------------------*/
41 | /* Exported macros -----------------------------------------------------------*/
42 | /* Exported functions --------------------------------------------------------*/
43 | /** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions
44 | * @{
45 | */
46 | /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
47 | * @{
48 | */
49 |
50 | #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
51 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size);
52 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size);
53 | #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
54 |
55 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || 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) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) */
59 | #if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
60 | HAL_StatusTypeDef HAL_PCDEx_ActivateBCD(PCD_HandleTypeDef *hpcd);
61 | HAL_StatusTypeDef HAL_PCDEx_DeActivateBCD(PCD_HandleTypeDef *hpcd);
62 | void HAL_PCDEx_BCD_VBUSDetect(PCD_HandleTypeDef *hpcd);
63 | #endif /* defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) */
64 | void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg);
65 | void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg);
66 |
67 | /**
68 | * @}
69 | */
70 |
71 | /**
72 | * @}
73 | */
74 |
75 | /**
76 | * @}
77 | */
78 |
79 | /**
80 | * @}
81 | */
82 | #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
83 |
84 | #ifdef __cplusplus
85 | }
86 | #endif
87 |
88 |
89 | #endif /* STM32F4xx_HAL_PCD_EX_H */
90 |
91 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
92 |
--------------------------------------------------------------------------------
/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_crc.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_crc.c
4 | * @author MCD Application Team
5 | * @brief CRC HAL module driver.
6 | * This file provides firmware functions to manage the following
7 | * functionalities of the Cyclic Redundancy Check (CRC) peripheral:
8 | * + Initialization and de-initialization functions
9 | * + Peripheral Control functions
10 | * + Peripheral State functions
11 | *
12 | @verbatim
13 | ===============================================================================
14 | ##### How to use this driver #####
15 | ===============================================================================
16 | [..]
17 | (+) Enable CRC AHB clock using __HAL_RCC_CRC_CLK_ENABLE();
18 | (+) Initialize CRC calculator
19 | (++) specify generating polynomial (peripheral default or non-default one)
20 | (++) specify initialization value (peripheral default or non-default one)
21 | (++) specify input data format
22 | (++) specify input or output data inversion mode if any
23 | (+) Use HAL_CRC_Accumulate() function to compute the CRC value of the
24 | input data buffer starting with the previously computed CRC as
25 | initialization value
26 | (+) Use HAL_CRC_Calculate() function to compute the CRC value of the
27 | input data buffer starting with the defined initialization value
28 | (default or non-default) to initiate CRC calculation
29 |
30 | @endverbatim
31 | ******************************************************************************
32 | * @attention
33 | *
34 | * © Copyright (c) 2016 STMicroelectronics.
35 | * All rights reserved.
36 | *
37 | * This software component is licensed by ST under BSD 3-Clause license,
38 | * the "License"; You may not use this file except in compliance with the
39 | * License. You may obtain a copy of the License at:
40 | * opensource.org/licenses/BSD-3-Clause
41 | *
42 | ******************************************************************************
43 | */
44 |
45 | /* Includes ------------------------------------------------------------------*/
46 | #include "stm32f4xx_hal.h"
47 |
48 | /** @addtogroup STM32F4xx_HAL_Driver
49 | * @{
50 | */
51 |
52 | /** @defgroup CRC CRC
53 | * @brief CRC HAL module driver.
54 | * @{
55 | */
56 |
57 | #ifdef HAL_CRC_MODULE_ENABLED
58 |
59 | /* Private typedef -----------------------------------------------------------*/
60 | /* Private define ------------------------------------------------------------*/
61 | /* Private macro -------------------------------------------------------------*/
62 | /* Private variables ---------------------------------------------------------*/
63 | /* Private function prototypes -----------------------------------------------*/
64 |
65 | /* Exported functions --------------------------------------------------------*/
66 |
67 | /** @defgroup CRC_Exported_Functions CRC Exported Functions
68 | * @{
69 | */
70 |
71 | /** @defgroup CRC_Exported_Functions_Group1 Initialization and de-initialization functions
72 | * @brief Initialization and Configuration functions.
73 | *
74 | @verbatim
75 | ===============================================================================
76 | ##### Initialization and de-initialization functions #####
77 | ===============================================================================
78 | [..] This section provides functions allowing to:
79 | (+) Initialize the CRC according to the specified parameters
80 | in the CRC_InitTypeDef and create the associated handle
81 | (+) DeInitialize the CRC peripheral
82 | (+) Initialize the CRC MSP (MCU Specific Package)
83 | (+) DeInitialize the CRC MSP
84 |
85 | @endverbatim
86 | * @{
87 | */
88 |
89 | /**
90 | * @brief Initialize the CRC according to the specified
91 | * parameters in the CRC_InitTypeDef and create the associated handle.
92 | * @param hcrc CRC handle
93 | * @retval HAL status
94 | */
95 | HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
96 | {
97 | /* Check the CRC handle allocation */
98 | if (hcrc == NULL)
99 | {
100 | return HAL_ERROR;
101 | }
102 |
103 | /* Check the parameters */
104 | assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
105 |
106 | if (hcrc->State == HAL_CRC_STATE_RESET)
107 | {
108 | /* Allocate lock resource and initialize it */
109 | hcrc->Lock = HAL_UNLOCKED;
110 | /* Init the low level hardware */
111 | HAL_CRC_MspInit(hcrc);
112 | }
113 |
114 | /* Change CRC peripheral state */
115 | hcrc->State = HAL_CRC_STATE_READY;
116 |
117 | /* Return function status */
118 | return HAL_OK;
119 | }
120 |
121 | /**
122 | * @brief DeInitialize the CRC peripheral.
123 | * @param hcrc CRC handle
124 | * @retval HAL status
125 | */
126 | HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc)
127 | {
128 | /* Check the CRC handle allocation */
129 | if (hcrc == NULL)
130 | {
131 | return HAL_ERROR;
132 | }
133 |
134 | /* Check the parameters */
135 | assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
136 |
137 | /* Check the CRC peripheral state */
138 | if (hcrc->State == HAL_CRC_STATE_BUSY)
139 | {
140 | return HAL_BUSY;
141 | }
142 |
143 | /* Change CRC peripheral state */
144 | hcrc->State = HAL_CRC_STATE_BUSY;
145 |
146 | /* Reset CRC calculation unit */
147 | __HAL_CRC_DR_RESET(hcrc);
148 |
149 | /* Reset IDR register content */
150 | CLEAR_BIT(hcrc->Instance->IDR, CRC_IDR_IDR);
151 |
152 | /* DeInit the low level hardware */
153 | HAL_CRC_MspDeInit(hcrc);
154 |
155 | /* Change CRC peripheral state */
156 | hcrc->State = HAL_CRC_STATE_RESET;
157 |
158 | /* Process unlocked */
159 | __HAL_UNLOCK(hcrc);
160 |
161 | /* Return function status */
162 | return HAL_OK;
163 | }
164 |
165 | /**
166 | * @brief Initializes the CRC MSP.
167 | * @param hcrc CRC handle
168 | * @retval None
169 | */
170 | __weak void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)
171 | {
172 | /* Prevent unused argument(s) compilation warning */
173 | UNUSED(hcrc);
174 |
175 | /* NOTE : This function should not be modified, when the callback is needed,
176 | the HAL_CRC_MspInit can be implemented in the user file
177 | */
178 | }
179 |
180 | /**
181 | * @brief DeInitialize the CRC MSP.
182 | * @param hcrc CRC handle
183 | * @retval None
184 | */
185 | __weak void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)
186 | {
187 | /* Prevent unused argument(s) compilation warning */
188 | UNUSED(hcrc);
189 |
190 | /* NOTE : This function should not be modified, when the callback is needed,
191 | the HAL_CRC_MspDeInit can be implemented in the user file
192 | */
193 | }
194 |
195 | /**
196 | * @}
197 | */
198 |
199 | /** @defgroup CRC_Exported_Functions_Group2 Peripheral Control functions
200 | * @brief management functions.
201 | *
202 | @verbatim
203 | ===============================================================================
204 | ##### Peripheral Control functions #####
205 | ===============================================================================
206 | [..] This section provides functions allowing to:
207 | (+) compute the 32-bit CRC value of a 32-bit data buffer
208 | using combination of the previous CRC value and the new one.
209 |
210 | [..] or
211 |
212 | (+) compute the 32-bit CRC value of a 32-bit data buffer
213 | independently of the previous CRC value.
214 |
215 | @endverbatim
216 | * @{
217 | */
218 |
219 | /**
220 | * @brief Compute the 32-bit CRC value of a 32-bit data buffer
221 | * starting with the previously computed CRC as initialization value.
222 | * @param hcrc CRC handle
223 | * @param pBuffer pointer to the input data buffer.
224 | * @param BufferLength input data buffer length (number of uint32_t words).
225 | * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
226 | */
227 | uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
228 | {
229 | uint32_t index; /* CRC input data buffer index */
230 | uint32_t temp = 0U; /* CRC output (read from hcrc->Instance->DR register) */
231 |
232 | /* Change CRC peripheral state */
233 | hcrc->State = HAL_CRC_STATE_BUSY;
234 |
235 | /* Enter Data to the CRC calculator */
236 | for (index = 0U; index < BufferLength; index++)
237 | {
238 | hcrc->Instance->DR = pBuffer[index];
239 | }
240 | temp = hcrc->Instance->DR;
241 |
242 | /* Change CRC peripheral state */
243 | hcrc->State = HAL_CRC_STATE_READY;
244 |
245 | /* Return the CRC computed value */
246 | return temp;
247 | }
248 |
249 | /**
250 | * @brief Compute the 32-bit CRC value of a 32-bit data buffer
251 | * starting with hcrc->Instance->INIT as initialization value.
252 | * @param hcrc CRC handle
253 | * @param pBuffer pointer to the input data buffer.
254 | * @param BufferLength input data buffer length (number of uint32_t words).
255 | * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
256 | */
257 | uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
258 | {
259 | uint32_t index; /* CRC input data buffer index */
260 | uint32_t temp = 0U; /* CRC output (read from hcrc->Instance->DR register) */
261 |
262 | /* Change CRC peripheral state */
263 | hcrc->State = HAL_CRC_STATE_BUSY;
264 |
265 | /* Reset CRC Calculation Unit (hcrc->Instance->INIT is
266 | * written in hcrc->Instance->DR) */
267 | __HAL_CRC_DR_RESET(hcrc);
268 |
269 | /* Enter 32-bit input data to the CRC calculator */
270 | for (index = 0U; index < BufferLength; index++)
271 | {
272 | hcrc->Instance->DR = pBuffer[index];
273 | }
274 | temp = hcrc->Instance->DR;
275 |
276 | /* Change CRC peripheral state */
277 | hcrc->State = HAL_CRC_STATE_READY;
278 |
279 | /* Return the CRC computed value */
280 | return temp;
281 | }
282 |
283 | /**
284 | * @}
285 | */
286 |
287 | /** @defgroup CRC_Exported_Functions_Group3 Peripheral State functions
288 | * @brief Peripheral State functions.
289 | *
290 | @verbatim
291 | ===============================================================================
292 | ##### Peripheral State functions #####
293 | ===============================================================================
294 | [..]
295 | This subsection permits to get in run-time the status of the peripheral.
296 |
297 | @endverbatim
298 | * @{
299 | */
300 |
301 | /**
302 | * @brief Return the CRC handle state.
303 | * @param hcrc CRC handle
304 | * @retval HAL state
305 | */
306 | HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc)
307 | {
308 | /* Return CRC handle state */
309 | return hcrc->State;
310 | }
311 |
312 | /**
313 | * @}
314 | */
315 |
316 | /**
317 | * @}
318 | */
319 |
320 |
321 | #endif /* HAL_CRC_MODULE_ENABLED */
322 | /**
323 | * @}
324 | */
325 |
326 | /**
327 | * @}
328 | */
329 |
330 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
331 |
--------------------------------------------------------------------------------
/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_flash_ramfunc.c
4 | * @author MCD Application Team
5 | * @brief FLASH RAMFUNC module driver.
6 | * This file provides a FLASH firmware functions which should be
7 | * executed from internal SRAM
8 | * + Stop/Start the flash interface while System Run
9 | * + Enable/Disable the flash sleep while System Run
10 | @verbatim
11 | ==============================================================================
12 | ##### APIs executed from Internal RAM #####
13 | ==============================================================================
14 | [..]
15 | *** ARM Compiler ***
16 | --------------------
17 | [..] RAM functions are defined using the toolchain options.
18 | Functions that are be executed in RAM should reside in a separate
19 | source module. Using the 'Options for File' dialog you can simply change
20 | the 'Code / Const' area of a module to a memory space in physical RAM.
21 | Available memory areas are declared in the 'Target' tab of the
22 | Options for Target' dialog.
23 |
24 | *** ICCARM Compiler ***
25 | -----------------------
26 | [..] RAM functions are defined using a specific toolchain keyword "__ramfunc".
27 |
28 | *** GNU Compiler ***
29 | --------------------
30 | [..] RAM functions are defined using a specific toolchain attribute
31 | "__attribute__((section(".RamFunc")))".
32 |
33 | @endverbatim
34 | ******************************************************************************
35 | * @attention
36 | *
37 | * © Copyright (c) 2017 STMicroelectronics.
38 | * All rights reserved.
39 | *
40 | * This software component is licensed by ST under BSD 3-Clause license,
41 | * the "License"; You may not use this file except in compliance with the
42 | * License. You may obtain a copy of the License at:
43 | * opensource.org/licenses/BSD-3-Clause
44 | *
45 | ******************************************************************************
46 | */
47 |
48 | /* Includes ------------------------------------------------------------------*/
49 | #include "stm32f4xx_hal.h"
50 |
51 | /** @addtogroup STM32F4xx_HAL_Driver
52 | * @{
53 | */
54 |
55 | /** @defgroup FLASH_RAMFUNC FLASH RAMFUNC
56 | * @brief FLASH functions executed from RAM
57 | * @{
58 | */
59 | #ifdef HAL_FLASH_MODULE_ENABLED
60 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
61 | defined(STM32F412Rx) || defined(STM32F412Cx)
62 |
63 | /* Private typedef -----------------------------------------------------------*/
64 | /* Private define ------------------------------------------------------------*/
65 | /* Private macro -------------------------------------------------------------*/
66 | /* Private variables ---------------------------------------------------------*/
67 | /* Private function prototypes -----------------------------------------------*/
68 | /* Exported functions --------------------------------------------------------*/
69 | /** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH RAMFUNC Exported Functions
70 | * @{
71 | */
72 |
73 | /** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions executed from internal RAM
74 | * @brief Peripheral Extended features functions
75 | *
76 | @verbatim
77 |
78 | ===============================================================================
79 | ##### ramfunc functions #####
80 | ===============================================================================
81 | [..]
82 | This subsection provides a set of functions that should be executed from RAM
83 | transfers.
84 |
85 | @endverbatim
86 | * @{
87 | */
88 |
89 | /**
90 | * @brief Stop the flash interface while System Run
91 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices.
92 | * @note This mode couldn't be set while executing with the flash itself.
93 | * It should be done with specific routine executed from RAM.
94 | * @retval HAL status
95 | */
96 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void)
97 | {
98 | /* Enable Power ctrl clock */
99 | __HAL_RCC_PWR_CLK_ENABLE();
100 | /* Stop the flash interface while System Run */
101 | SET_BIT(PWR->CR, PWR_CR_FISSR);
102 |
103 | return HAL_OK;
104 | }
105 |
106 | /**
107 | * @brief Start the flash interface while System Run
108 | * @note This mode is only available for STM32F411xx/STM32F446xx devices.
109 | * @note This mode couldn't be set while executing with the flash itself.
110 | * It should be done with specific routine executed from RAM.
111 | * @retval HAL status
112 | */
113 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void)
114 | {
115 | /* Enable Power ctrl clock */
116 | __HAL_RCC_PWR_CLK_ENABLE();
117 | /* Start the flash interface while System Run */
118 | CLEAR_BIT(PWR->CR, PWR_CR_FISSR);
119 |
120 | return HAL_OK;
121 | }
122 |
123 | /**
124 | * @brief Enable the flash sleep while System Run
125 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices.
126 | * @note This mode could n't be set while executing with the flash itself.
127 | * It should be done with specific routine executed from RAM.
128 | * @retval HAL status
129 | */
130 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void)
131 | {
132 | /* Enable Power ctrl clock */
133 | __HAL_RCC_PWR_CLK_ENABLE();
134 | /* Enable the flash sleep while System Run */
135 | SET_BIT(PWR->CR, PWR_CR_FMSSR);
136 |
137 | return HAL_OK;
138 | }
139 |
140 | /**
141 | * @brief Disable the flash sleep while System Run
142 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices.
143 | * @note This mode couldn't be set while executing with the flash itself.
144 | * It should be done with specific routine executed from RAM.
145 | * @retval HAL status
146 | */
147 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void)
148 | {
149 | /* Enable Power ctrl clock */
150 | __HAL_RCC_PWR_CLK_ENABLE();
151 | /* Disable the flash sleep while System Run */
152 | CLEAR_BIT(PWR->CR, PWR_CR_FMSSR);
153 |
154 | return HAL_OK;
155 | }
156 |
157 | /**
158 | * @}
159 | */
160 |
161 | /**
162 | * @}
163 | */
164 |
165 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */
166 | #endif /* HAL_FLASH_MODULE_ENABLED */
167 | /**
168 | * @}
169 | */
170 |
171 | /**
172 | * @}
173 | */
174 |
175 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
176 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # tools
2 |
3 | CC = arm-none-eabi-gcc
4 | OBJCOPY = arm-none-eabi-objcopy
5 | OBJDUMP = arm-none-eabi-objdump
6 | SIZE = arm-none-eabi-size
7 |
8 | # this is ST's free STM32CubeProgrammer package. if you installed it under sudo then it should be in the location below
9 |
10 | PROGRAMMER = /usr/local/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer.sh
11 |
12 | # flags for tools
13 |
14 | INCLUDE = -IUSB_DEVICE/App -IUSB_DEVICE/Target -ICore/Inc -IDrivers/STM32F4xx_HAL_Driver/Inc -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy -IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc -IMiddlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc -IMiddlewares/ST/STM32_Audio/Addons/SVC/Inc -IMiddlewares/ST/STM32_Audio/Addons/GREQ/Inc -IMiddlewares/ST/STM32_Audio/Addons/Common/Inc -IDrivers/CMSIS/Device/ST/STM32F4xx/Include -IDrivers/CMSIS/Include
15 | CFLAGS = -mcpu=cortex-m4 -g3 -DUSE_HAL_DRIVER -DSTM32F446xx -ffunction-sections -fdata-sections -Wall -fstack-usage --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb
16 | LDFLAGS = -mcpu=cortex-m4 --specs=nosys.specs --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--gc-sections -static -LMiddlewares/ST/STM32_Audio/Addons/SVC/Lib -LMiddlewares/ST/STM32_Audio/Addons/GREQ/Lib
17 | ASMFLAGS = -mcpu=cortex-m4 -g3 -x assembler-with-cpp --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb
18 |
19 | # your targets:
20 | # 'make release' for the optimised build (same as just 'make')
21 | # 'make debug' for a build with symbols and no optimisation
22 | # include the 'flash' target to write to your device connected with ST-Link, e.g:
23 | # 'make release flash'
24 | # 'make debug flash'
25 | # if switching between 'release' and 'debug' then do a 'make clean' first, or delete the 'build' directory.
26 |
27 | release: CFLAGS += -O3
28 | debug: CFLAGS += -DDEBUG -g3 -O0
29 |
30 | release: hex bin lst size
31 | debug: hex bin lst size
32 |
33 | # C, C++ and assembly sources
34 |
35 | CSRC := $(shell find . -name "*.c")
36 | CPPSRC := $(shell find . -name "*.cpp")
37 | ASMSRC := $(shell find . -name "*.s")
38 |
39 | # equivalent objects for the sources
40 |
41 | OBJ := $(CSRC:%.c=build/%.o) $(CPPSRC:%.cpp=build/%.o) $(ASMSRC:%.s=build/%.o)
42 |
43 | # everything gets built into a 'build' sub-directory
44 |
45 | build/%.o: %.c
46 | mkdir -p "$(@D)"
47 | $(CC) $(CFLAGS) ${INCLUDE} -c $< -o $@
48 |
49 | build/%.o: %.cpp
50 | mkdir -p "$(@D)"
51 | $(CC) $(CFLAGS) ${INCLUDE} -c $< -o $@
52 |
53 | build/%.o: %.s
54 | mkdir -p "$(@D)"
55 | $(CC) $(ASMFLAGS) ${INCLUDE} -c $< -o $@
56 |
57 | # linker
58 |
59 | elf: $(OBJ)
60 | $(CC) -o build/usb-microphone.elf $(OBJ) $(LDFLAGS) -lSVC -lGREQ -TSTM32F446RCTX_FLASH.ld -Wl,-Map=build/usb-microphone.map -Wl,--start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-group
61 |
62 | # convert elf to ihex for flashing
63 |
64 | hex: elf
65 | $(OBJCOPY) -O ihex build/usb-microphone.elf build/usb-microphone.hex
66 |
67 | # binary
68 |
69 | bin: elf
70 | $(OBJCOPY) -O binary build/usb-microphone.elf build/usb-microphone.bin
71 |
72 | # assembly listing
73 |
74 | lst: elf
75 | $(OBJDUMP) -h -S build/usb-microphone.elf > build/usb-microphone.lst
76 |
77 | # size information to show MCU memory utilisation
78 |
79 | size: elf
80 | $(SIZE) --format=berkeley build/usb-microphone.elf | tee build/usb-microphone.size
81 |
82 | # programmer (flags = use SWD, connect under reset, hardware reset, program, verify, reset-and-run)
83 |
84 | flash: elf
85 | $(PROGRAMMER) -c port=SWD mode=UR reset=HWrst -d build/usb-microphone.elf -v -hardRst
86 |
87 | # clean up
88 |
89 | clean:
90 | rm -rf build
91 |
--------------------------------------------------------------------------------
/Middlewares/ST/STM32_Audio/Addons/Common/Inc/audio_fw_glo.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file audio_fw_glo.h
4 | * @author MCD Application Team
5 | * @version V1.0.1
6 | * @date 15-Oct-2017
7 | * @brief This file contains audio fw definitions common to all audio modules
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2017 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Image SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_image_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 | #ifndef _AUDIO_FW_GLO_H_
30 | #define _AUDIO_FW_GLO_H_
31 |
32 | #ifdef __cplusplus
33 | extern "C" {
34 | #endif
35 |
36 | /* Includes ------------------------------------------------------------------*/
37 |
38 |
39 | /* Exported constants --------------------------------------------------------*/
40 | #define NOT_INTERLEAVED 0
41 | #define INTERLEAVED 1
42 |
43 | /* Exported types ------------------------------------------------------------*/
44 |
45 | typedef struct {
46 | int32_t nb_channels; /* Number of channels */
47 | int32_t nb_bytes_per_Sample; /* Nb bytes per sample */
48 | void *data_ptr; /* Pointer to data buffer */
49 | int32_t buffer_size; /* Number of samples per channel in the data buffer */
50 | int32_t mode; /* buffer mode (interleaved, non interleaved) */
51 | } buffer_t;
52 |
53 | /* External variables --------------------------------------------------------*/
54 | /* Exported macros -----------------------------------------------------------*/
55 | /* Exported functions ------------------------------------------------------- */
56 |
57 |
58 | #ifdef __cplusplus
59 | }
60 | #endif
61 |
62 | #endif /*_AUDIO_FW_GLO_H_*/
63 |
64 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
65 |
--------------------------------------------------------------------------------
/Middlewares/ST/STM32_Audio/Addons/GREQ/Inc/greq_glo.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file greq_glo.h
4 | * @author MCD Application Team
5 | * @version V1.0.2
6 | * @date 15-Oct-2017
7 | * @brief This file contains GREQ module definitions to export
8 | * For more details about this Library, please refer to document
9 | * "UM1798 User manual".
10 | ******************************************************************************
11 | * @attention
12 | *
13 | * © COPYRIGHT 2017 STMicroelectronics
14 | *
15 | * Licensed under MCD-ST Image SW License Agreement V2, (the "License");
16 | * You may not use this file except in compliance with the License.
17 | * You may obtain a copy of the License at:
18 | *
19 | * http://www.st.com/software_license_agreement_image_v2
20 | *
21 | * Unless required by applicable law or agreed to in writing, software
22 | * distributed under the License is distributed on an "AS IS" BASIS,
23 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 | * See the License for the specific language governing permissions and
25 | * limitations under the License.
26 | *
27 | ******************************************************************************
28 | */
29 |
30 | /* Define to prevent recursive inclusion -------------------------------------*/
31 | #ifndef GREQ_GLO_H
32 | #define GREQ_GLO_H
33 |
34 | #ifdef __cplusplus
35 | extern "C" {
36 | #endif
37 |
38 | /* Includes ------------------------------------------------------------------*/
39 | #include "audio_fw_glo.h"
40 |
41 | /* Exported constants --------------------------------------------------------*/
42 |
43 | /* C O D E C O N F I G U R A T I O N */
44 | /* Supported number of bands */
45 | #define GREQ_NB_BANDS_5 (5)
46 | #define GREQ_NB_BANDS_8 (8)
47 | #define GREQ_NB_BANDS_10 (10)
48 |
49 | /* Supported Equalizer presets */
50 | #define GREQ_NO_PRESET (0)
51 | #define GREQ_PRESET_POP (GREQ_NO_PRESET + 1)
52 | #define GREQ_PRESET_JAZZ (GREQ_PRESET_POP + 1)
53 | #define GREQ_PRESET_ROCK (GREQ_PRESET_JAZZ + 1)
54 | #define GREQ_PRESET_VOCAL (GREQ_PRESET_ROCK + 1)
55 | #define GREQ_PRESET_CLASSICAL (GREQ_PRESET_VOCAL + 1)
56 | #define GREQ_PRESET_HIPHOP (GREQ_PRESET_CLASSICAL + 1)
57 | #define GREQ_PRESET_END (GREQ_PRESET_HIPHOP)
58 |
59 | /* E R R O R V A L U E S */
60 | #define GREQ_ERROR_NONE 0
61 | #define GREQ_UNSUPPORTED_NUMBER_OF_BYTEPERSAMPLE -1
62 | #define GREQ_UNSUPPORTED_NUMBER_OF_CHANNELS -2
63 | #define GREQ_UNSUPPORTED_NUMBER_OF_BANDS -3
64 | #define GREQ_UNSUPPORTED_GAIN_PRESET -4
65 | #define GREQ_UNSUPPORTED_INTERLEAVING_MODE -5
66 | #define GREQ_UNSUPPORTED_FRAME_SIZE -6
67 | #define GREQ_UNSUPPORTED_GAIN -7
68 | #define GREQ_BAD_HW -8
69 |
70 | /* Exported types ------------------------------------------------------------*/
71 |
72 | struct greq_dynamic_param {
73 | int16_t enable; // 0/1 to disable or enable effect
74 | int16_t user_gain_per_band_dB[GREQ_NB_BANDS_10]; // in dB from -12 to +12 by 1dB step
75 | int16_t gain_preset_idx; // see equalizer presets defined above
76 | };
77 | typedef struct greq_dynamic_param greq_dynamic_param_t;
78 |
79 | struct greq_static_param {
80 | int16_t nb_bands; // see supported number of bands defined above
81 | };
82 | typedef struct greq_static_param greq_static_param_t;
83 |
84 | /* External variables --------------------------------------------------------*/
85 |
86 | extern const uint32_t greq_scratch_mem_size;
87 | extern const uint32_t greq_persistent_mem_size;
88 |
89 | /* Exported macros -----------------------------------------------------------*/
90 | /* Exported functions ------------------------------------------------------- */
91 |
92 | /* greq_reset() : initializes static memory, states machines, ... */
93 | extern int32_t greq_reset(void *persistent_mem_ptr, void *scratch_mem_ptr);
94 | /* greq_setConfig() : use to change dynamically some parameters */
95 | extern int32_t greq_setConfig(greq_dynamic_param_t *input_dynamic_param_ptr, void *persistent_mem_ptr);
96 | /* greq_getConfig() : use to get values of dynamic parameters */
97 | extern int32_t greq_getConfig(greq_dynamic_param_t *input_dynamic_param_ptr, void *persistent_mem_ptr);
98 | /* greq_setParam() : use to set parameters that won't change during processing */
99 | extern int32_t greq_setParam(greq_static_param_t *input_static_param_ptr, void *persistent_mem_ptr);
100 | /* greq_getParam() : use to get values of static parameters */
101 | extern int32_t greq_getParam(greq_static_param_t *input_static_param_ptr, void *persistent_mem_ptr);
102 | /* greq_process() : this is the main processing routine */
103 | extern int32_t greq_process(buffer_t *input_buffer, buffer_t *output_buffer, void *persistent_mem_ptr);
104 |
105 | #ifdef __cplusplus
106 | }
107 | #endif
108 |
109 | #endif /* GREQ_GLO_H */
110 |
111 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
112 |
--------------------------------------------------------------------------------
/Middlewares/ST/STM32_Audio/Addons/GREQ/Lib/libGREQ.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andysworkshop/usb-microphone/5eb348566212141c235f19b99f2e8b577523ca65/Middlewares/ST/STM32_Audio/Addons/GREQ/Lib/libGREQ.a
--------------------------------------------------------------------------------
/Middlewares/ST/STM32_Audio/Addons/SVC/Inc/svc_glo.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file svc_glo.h
4 | * @author MCD Application Team
5 | * @version V1.0.4
6 | * @date 15-Oct-2017
7 | * @brief This file contains API for Smart Volume Control library (SVC)
8 | * For more details about this Library, please refer to document
9 | * "UM1642 User manual".
10 | ******************************************************************************
11 | * @attention
12 | *
13 | * © COPYRIGHT 2017 STMicroelectronics
14 | *
15 | * Licensed under MCD-ST Image SW License Agreement V2, (the "License");
16 | * You may not use this file except in compliance with the License.
17 | * You may obtain a copy of the License at:
18 | *
19 | * http://www.st.com/software_license_agreement_image_v2
20 | *
21 | * Unless required by applicable law or agreed to in writing, software
22 | * distributed under the License is distributed on an "AS IS" BASIS,
23 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 | * See the License for the specific language governing permissions and
25 | * limitations under the License.
26 | *
27 | ******************************************************************************
28 | */
29 |
30 | /* Define to prevent recursive inclusion -------------------------------------*/
31 | #ifndef SVC_GLO_H
32 | #define SVC_GLO_H
33 |
34 | #ifdef __cplusplus
35 | extern "C" {
36 | #endif
37 |
38 | /* Includes ------------------------------------------------------------------*/
39 | #include "audio_fw_glo.h"
40 |
41 | /* Exported constants --------------------------------------------------------*/
42 |
43 | #define SVC_MUTE_NOT_ACTIVATED 0
44 | #define SVC_MUTE_ACTIVATED (SVC_MUTE_NOT_ACTIVATED + 1)
45 | #define SVC_DISABLE_EFFECT 0
46 | #define SVC_ENABLE_EFFECT (SVC_DISABLE_EFFECT + 1)
47 |
48 |
49 | /* E R R O R V A L U E S */
50 | #define SVC_ERROR_NONE 0
51 | #define SVC_UNSUPPORTED_DELAY_LENGTH -1
52 | #define SVC_UNSUPPORTED_VOLUME -2
53 | #define SVC_UNSUPPORTED_MUTE_MODE -3
54 | #define SVC_UNSUPPORTED_QUALITY_MODE -4
55 | #define SVC_UNSUPPORTED_JOINT_STEREO_MODE -5
56 | #define SVC_UNSUPPORTED_NUMBER_OF_BYTEPERSAMPLE -6
57 | #define SVC_BAD_HW -7
58 |
59 | /* Exported types ------------------------------------------------------------*/
60 |
61 | struct svc_dynamic_param {
62 | int16_t target_volume_dB; /* in dB */
63 | int16_t mute; /* 0 = unmute, 1 = mute */
64 | int16_t enable_compr;
65 | int32_t attack_time;
66 | int32_t release_time;
67 | int16_t quality; /* 0:STANDARD, 1:HIGH_Q */
68 | };
69 | typedef struct svc_dynamic_param svc_dynamic_param_t;
70 |
71 | struct svc_static_param {
72 | int16_t delay_len;
73 | int16_t joint_stereo;
74 | };
75 | typedef struct svc_static_param svc_static_param_t;
76 |
77 | /* External variables --------------------------------------------------------*/
78 |
79 | extern const uint32_t svc_scratch_mem_size;
80 | extern const uint32_t svc_persistent_mem_size;
81 |
82 | /* Exported macros -----------------------------------------------------------*/
83 | /* Exported functions ------------------------------------------------------- */
84 |
85 | /* svc_reset() : initializes static memory, states machines, ... */
86 | extern int32_t svc_reset(void *persistent_mem_ptr, void *scratch_mem_ptr);
87 | /* svc_setConfig() : use to change dynamically some parameters */
88 | extern int32_t svc_setConfig(svc_dynamic_param_t *input_dynamic_param_ptr, void *persistent_mem_ptr);
89 | /* svc_getConfig() : use to get values of dynamic parameters */
90 | extern int32_t svc_getConfig(svc_dynamic_param_t *input_dynamic_param_ptr, void *persistent_mem_ptr);
91 | /* svc_setParam() : use to set parameters that won't change during processing */
92 | extern int32_t svc_setParam(svc_static_param_t *input_static_param_ptr, void *persistent_mem_ptr);
93 | /* svc_getParam() : use to get values of static parameters */
94 | extern int32_t svc_getParam(svc_static_param_t *input_static_param_ptr, void *persistent_mem_ptr);
95 | /* svc_process() : this is the main processing routine */
96 | extern int32_t svc_process(buffer_t *input_buffer, buffer_t *output_buffer, void *persistent_mem_ptr);
97 |
98 | #ifdef __cplusplus
99 | }
100 | #endif
101 |
102 | #endif // SVC_GLO_H
103 |
104 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
105 |
--------------------------------------------------------------------------------
/Middlewares/ST/STM32_Audio/Addons/SVC/Lib/libSVC.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andysworkshop/usb-microphone/5eb348566212141c235f19b99f2e8b577523ca65/Middlewares/ST/STM32_Audio/Addons/SVC/Lib/libSVC.a
--------------------------------------------------------------------------------
/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc/usbd_audio_in.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_audio_in.h
4 | * @author Central Labs
5 | * @version V2.4.2 MOD
6 | * @date 01-Sep-2016
7 | * @brief header file for the usbd_audio_in.c file.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT(c) 2014 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Redistribution and use in source and binary forms, with or without modification,
20 | * are permitted provided that the following conditions are met:
21 | * 1. Redistributions of source code must retain the above copyright notice,
22 | * this list of conditions and the following disclaimer.
23 | * 2. Redistributions in binary form must reproduce the above copyright notice,
24 | * this list of conditions and the following disclaimer in the documentation
25 | * and/or other materials provided with the distribution.
26 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
27 | * may be used to endorse or promote products derived from this software
28 | * without specific prior written permission.
29 | *
30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
34 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
38 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 | *
41 | ******************************************************************************
42 | */
43 |
44 | #pragma once
45 |
46 | #include "usbd_ioreq.h"
47 |
48 | #define AUDIO_OUT_EP 0x01
49 | #define USB_AUDIO_CONFIG_DESC_SIZ 109
50 | #define AUDIO_INTERFACE_DESC_SIZE 9
51 | #define USB_AUDIO_DESC_SIZ 0x09
52 | #define AUDIO_STANDARD_ENDPOINT_DESC_SIZE 0x09
53 | #define AUDIO_STREAMING_ENDPOINT_DESC_SIZE 0x07
54 | #define AUDIO_DESCRIPTOR_TYPE 0x21
55 | #define USB_DEVICE_CLASS_AUDIO 0x01
56 | #define AUDIO_SUBCLASS_AUDIOCONTROL 0x01
57 | #define AUDIO_SUBCLASS_AUDIOSTREAMING 0x02
58 | #define AUDIO_PROTOCOL_UNDEFINED 0x00
59 | #define AUDIO_STREAMING_GENERAL 0x01
60 | #define AUDIO_STREAMING_FORMAT_TYPE 0x02
61 | /* Audio Descriptor Types */
62 | #define AUDIO_INTERFACE_DESCRIPTOR_TYPE 0x24
63 | #define AUDIO_ENDPOINT_DESCRIPTOR_TYPE 0x25
64 | /* Audio Control Interface Descriptor Subtypes */
65 | #define AUDIO_CONTROL_HEADER 0x01
66 | #define AUDIO_CONTROL_INPUT_TERMINAL 0x02
67 | #define AUDIO_CONTROL_OUTPUT_TERMINAL 0x03
68 | #define AUDIO_CONTROL_FEATURE_UNIT 0x06
69 | #define AUDIO_INPUT_TERMINAL_DESC_SIZE 0x0C
70 | #define AUDIO_OUTPUT_TERMINAL_DESC_SIZE 0x09
71 | #define AUDIO_STREAMING_INTERFACE_DESC_SIZE 0x07
72 | #define AUDIO_CONTROL_MUTE 0x0002
73 | #define AUDIO_FORMAT_TYPE_I 0x01
74 | #define AUDIO_FORMAT_TYPE_III 0x03
75 | #define AUDIO_ENDPOINT_GENERAL 0x01
76 | #define AUDIO_REQ_GET_CUR 0x81
77 | #define AUDIO_REQ_GET_MIN 0x82
78 | #define AUDIO_REQ_GET_MAX 0x83
79 | #define AUDIO_REQ_GET_RES 0x84
80 | #define AUDIO_REQ_SET_CUR 0x01
81 | #define AUDIO_OUT_STREAMING_CTRL 0x02
82 |
83 | #define AUDIO_CTRL_REQ_SET_CUR_VOLUME 0x01
84 | #define AUDIO_CTRL_REQ_SET_CUR_EQUALIZER 0x02
85 |
86 | #define VOL_MIN 0xb000 // -80dB (1 == 1/256dB)
87 | #define VOL_RES 128 // 0.5dB (1 == 1/256dB)
88 | #define VOL_MAX 9216 // 36dB (1 == 1/256dB)
89 |
90 | #define AUDIO_IN_PACKET (uint32_t)((((48000/1000)+2)*8)*2)
91 | #define MIC_IN_TERMINAL_ID 1
92 | #define MIC_FU_ID 2
93 | #define MIC_OUT_TERMINAL_ID 3
94 | #define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
95 | /* Audio Data in endpoint */
96 | #define AUDIO_IN_EP 0x81
97 |
98 | #define FEATURE_MUTE 0x01
99 | #define FEATURE_VOLUME 0x02
100 | #define FEATURE_BASS 0x04
101 | #define FEATURE_MID 0x08
102 | #define FEATURE_TREBLE 0x10
103 | #define FEATURE_GRAPHIC_EQ 0x20
104 | #define FEATURE_AUTO_GAIN 0x40
105 | #define FEATURE_DELAY 0x80
106 |
107 | /* Buffering state definitions */
108 | typedef enum {
109 | STATE_USB_WAITING_FOR_INIT = 0, STATE_USB_IDLE = 1, STATE_USB_REQUESTS_STARTED = 2, STATE_USB_BUFFER_WRITE_STARTED = 3,
110 | } AUDIO_StatesTypeDef;
111 |
112 | /* Number of sub-packets in the audio transfer buffer.*/
113 | #define AUDIO_IN_PACKET_NUM 6
114 |
115 | #define TIMEOUT_VALUE 200
116 |
117 | /* Audio Commands enmueration */
118 | typedef enum {
119 | AUDIO_CMD_START = 1, AUDIO_CMD_PLAY, AUDIO_CMD_STOP,
120 | } AUDIO_CMD_TypeDef;
121 |
122 | typedef enum {
123 | AUDIO_OFFSET_NONE = 0, AUDIO_OFFSET_HALF, AUDIO_OFFSET_FULL, AUDIO_OFFSET_UNKNOWN,
124 | } AUDIO_OffsetTypeDef;
125 |
126 | typedef struct {
127 | uint8_t cmd;
128 | uint8_t data[USB_MAX_EP0_SIZE];
129 | uint8_t len;
130 | uint8_t unit;
131 | } USBD_AUDIO_ControlTypeDef;
132 |
133 | typedef struct {
134 | __IO uint32_t alt_setting;
135 | uint8_t channels;
136 | uint32_t frequency;
137 | __IO int16_t timeout;
138 | uint16_t buffer_length;
139 | uint16_t dataAmount;
140 | uint16_t paketDimension;
141 | uint8_t state;
142 | uint16_t rd_ptr;
143 | uint16_t wr_ptr;
144 | uint8_t upper_treshold;
145 | uint8_t lower_treshold;
146 | USBD_AUDIO_ControlTypeDef control;
147 | uint8_t *buffer;
148 | } USBD_AUDIO_HandleTypeDef;
149 |
150 | typedef struct {
151 | int8_t (*Init)(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr);
152 | int8_t (*DeInit)(uint32_t options);
153 | int8_t (*Record)(void);
154 | int8_t (*VolumeCtl)(int16_t Volume);
155 | int8_t (*MuteCtl)(uint8_t cmd);
156 | int8_t (*Stop)(void);
157 | int8_t (*Pause)(void);
158 | int8_t (*Resume)(void);
159 | int8_t (*CommandMgr)(uint8_t cmd);
160 | } USBD_AUDIO_ItfTypeDef;
161 |
162 | extern USBD_ClassTypeDef USBD_AUDIO;
163 |
164 | uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_AUDIO_ItfTypeDef *fops);
165 | void USBD_AUDIO_Init_Microphone_Descriptor(USBD_HandleTypeDef *pdev, uint32_t samplingFrequency, uint8_t Channels);
166 | uint8_t USBD_AUDIO_Data_Transfer(USBD_HandleTypeDef *pdev, int16_t *audioData, uint16_t dataAmount);
167 |
--------------------------------------------------------------------------------
/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_core.h
4 | * @author MCD Application Team
5 | * @brief Header file for usbd_core.c file
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2015 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 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USBD_CORE_H
22 | #define __USBD_CORE_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "usbd_conf.h"
30 | #include "usbd_def.h"
31 | #include "usbd_ioreq.h"
32 | #include "usbd_ctlreq.h"
33 |
34 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
35 | * @{
36 | */
37 |
38 | /** @defgroup USBD_CORE
39 | * @brief This file is the Header file for usbd_core.c file
40 | * @{
41 | */
42 |
43 |
44 | /** @defgroup USBD_CORE_Exported_Defines
45 | * @{
46 | */
47 | #ifndef USBD_DEBUG_LEVEL
48 | #define USBD_DEBUG_LEVEL 0U
49 | #endif /* USBD_DEBUG_LEVEL */
50 | /**
51 | * @}
52 | */
53 |
54 |
55 | /** @defgroup USBD_CORE_Exported_TypesDefinitions
56 | * @{
57 | */
58 |
59 |
60 | /**
61 | * @}
62 | */
63 |
64 |
65 |
66 | /** @defgroup USBD_CORE_Exported_Macros
67 | * @{
68 | */
69 |
70 | /**
71 | * @}
72 | */
73 |
74 | /** @defgroup USBD_CORE_Exported_Variables
75 | * @{
76 | */
77 | #define USBD_SOF USBD_LL_SOF
78 | /**
79 | * @}
80 | */
81 |
82 | /** @defgroup USBD_CORE_Exported_FunctionsPrototype
83 | * @{
84 | */
85 | USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id);
86 | USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev);
87 | USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev);
88 | USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev);
89 | USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
90 |
91 | USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev);
92 | USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
93 | USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
94 |
95 | USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup);
96 | USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
97 | USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
98 |
99 | USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev);
100 | USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed);
101 | USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev);
102 | USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev);
103 |
104 | USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev);
105 | USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
106 | USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
107 |
108 | USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev);
109 | USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev);
110 |
111 | /* USBD Low Level Driver */
112 | USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev);
113 | USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev);
114 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev);
115 | USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev);
116 |
117 | USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
118 | uint8_t ep_type, uint16_t ep_mps);
119 |
120 | USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
121 | USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
122 | USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
123 | USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
124 | USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr);
125 |
126 | USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
127 | uint8_t *pbuf, uint32_t size);
128 |
129 | USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
130 | uint8_t *pbuf, uint32_t size);
131 |
132 | uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
133 | uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
134 |
135 | void USBD_LL_Delay(uint32_t Delay);
136 |
137 | /**
138 | * @}
139 | */
140 |
141 | #ifdef __cplusplus
142 | }
143 | #endif
144 |
145 | #endif /* __USBD_CORE_H */
146 |
147 | /**
148 | * @}
149 | */
150 |
151 | /**
152 | * @}
153 | */
154 |
155 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
156 |
157 |
158 |
159 |
--------------------------------------------------------------------------------
/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_req.h
4 | * @author MCD Application Team
5 | * @brief Header file for the usbd_req.c file
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2015 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 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USB_REQUEST_H
22 | #define __USB_REQUEST_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "usbd_def.h"
30 |
31 |
32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
33 | * @{
34 | */
35 |
36 | /** @defgroup USBD_REQ
37 | * @brief header file for the usbd_req.c file
38 | * @{
39 | */
40 |
41 | /** @defgroup USBD_REQ_Exported_Defines
42 | * @{
43 | */
44 | /**
45 | * @}
46 | */
47 |
48 |
49 | /** @defgroup USBD_REQ_Exported_Types
50 | * @{
51 | */
52 | /**
53 | * @}
54 | */
55 |
56 |
57 |
58 | /** @defgroup USBD_REQ_Exported_Macros
59 | * @{
60 | */
61 | /**
62 | * @}
63 | */
64 |
65 | /** @defgroup USBD_REQ_Exported_Variables
66 | * @{
67 | */
68 | /**
69 | * @}
70 | */
71 |
72 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype
73 | * @{
74 | */
75 |
76 | USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
77 | USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
78 | USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
79 |
80 | void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
81 | void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata);
82 | void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len);
83 |
84 | /**
85 | * @}
86 | */
87 |
88 | #ifdef __cplusplus
89 | }
90 | #endif
91 |
92 | #endif /* __USB_REQUEST_H */
93 |
94 | /**
95 | * @}
96 | */
97 |
98 | /**
99 | * @}
100 | */
101 |
102 |
103 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
104 |
--------------------------------------------------------------------------------
/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_ioreq.h
4 | * @author MCD Application Team
5 | * @brief Header file for the usbd_ioreq.c file
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2015 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 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USBD_IOREQ_H
22 | #define __USBD_IOREQ_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "usbd_def.h"
30 | #include "usbd_core.h"
31 |
32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
33 | * @{
34 | */
35 |
36 | /** @defgroup USBD_IOREQ
37 | * @brief header file for the usbd_ioreq.c file
38 | * @{
39 | */
40 |
41 | /** @defgroup USBD_IOREQ_Exported_Defines
42 | * @{
43 | */
44 | /**
45 | * @}
46 | */
47 |
48 |
49 | /** @defgroup USBD_IOREQ_Exported_Types
50 | * @{
51 | */
52 |
53 |
54 | /**
55 | * @}
56 | */
57 |
58 |
59 |
60 | /** @defgroup USBD_IOREQ_Exported_Macros
61 | * @{
62 | */
63 |
64 | /**
65 | * @}
66 | */
67 |
68 | /** @defgroup USBD_IOREQ_Exported_Variables
69 | * @{
70 | */
71 |
72 | /**
73 | * @}
74 | */
75 |
76 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype
77 | * @{
78 | */
79 |
80 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
81 | uint8_t *pbuf, uint32_t len);
82 |
83 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
84 | uint8_t *pbuf, uint32_t len);
85 |
86 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
87 | uint8_t *pbuf, uint32_t len);
88 |
89 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
90 | uint8_t *pbuf, uint32_t len);
91 |
92 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev);
93 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev);
94 |
95 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
96 |
97 | /**
98 | * @}
99 | */
100 |
101 | #ifdef __cplusplus
102 | }
103 | #endif
104 |
105 | #endif /* __USBD_IOREQ_H */
106 |
107 | /**
108 | * @}
109 | */
110 |
111 | /**
112 | * @}
113 | */
114 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
115 |
--------------------------------------------------------------------------------
/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_ioreq.c
4 | * @author MCD Application Team
5 | * @brief This file provides the IO requests APIs for control endpoints.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2015 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 |
20 | /* Includes ------------------------------------------------------------------*/
21 | #include "usbd_ioreq.h"
22 |
23 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
24 | * @{
25 | */
26 |
27 |
28 | /** @defgroup USBD_IOREQ
29 | * @brief control I/O requests module
30 | * @{
31 | */
32 |
33 | /** @defgroup USBD_IOREQ_Private_TypesDefinitions
34 | * @{
35 | */
36 | /**
37 | * @}
38 | */
39 |
40 |
41 | /** @defgroup USBD_IOREQ_Private_Defines
42 | * @{
43 | */
44 |
45 | /**
46 | * @}
47 | */
48 |
49 |
50 | /** @defgroup USBD_IOREQ_Private_Macros
51 | * @{
52 | */
53 | /**
54 | * @}
55 | */
56 |
57 |
58 | /** @defgroup USBD_IOREQ_Private_Variables
59 | * @{
60 | */
61 |
62 | /**
63 | * @}
64 | */
65 |
66 |
67 | /** @defgroup USBD_IOREQ_Private_FunctionPrototypes
68 | * @{
69 | */
70 | /**
71 | * @}
72 | */
73 |
74 |
75 | /** @defgroup USBD_IOREQ_Private_Functions
76 | * @{
77 | */
78 |
79 | /**
80 | * @brief USBD_CtlSendData
81 | * send data on the ctl pipe
82 | * @param pdev: device instance
83 | * @param buff: pointer to data buffer
84 | * @param len: length of data to be sent
85 | * @retval status
86 | */
87 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
88 | uint8_t *pbuf, uint32_t len)
89 | {
90 | /* Set EP0 State */
91 | pdev->ep0_state = USBD_EP0_DATA_IN;
92 | pdev->ep_in[0].total_length = len;
93 | pdev->ep_in[0].rem_length = len;
94 |
95 | /* Start the transfer */
96 | (void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
97 |
98 | return USBD_OK;
99 | }
100 |
101 | /**
102 | * @brief USBD_CtlContinueSendData
103 | * continue sending data on the ctl pipe
104 | * @param pdev: device instance
105 | * @param buff: pointer to data buffer
106 | * @param len: length of data to be sent
107 | * @retval status
108 | */
109 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
110 | uint8_t *pbuf, uint32_t len)
111 | {
112 | /* Start the next transfer */
113 | (void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
114 |
115 | return USBD_OK;
116 | }
117 |
118 | /**
119 | * @brief USBD_CtlPrepareRx
120 | * receive data on the ctl pipe
121 | * @param pdev: device instance
122 | * @param buff: pointer to data buffer
123 | * @param len: length of data to be received
124 | * @retval status
125 | */
126 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
127 | uint8_t *pbuf, uint32_t len)
128 | {
129 | /* Set EP0 State */
130 | pdev->ep0_state = USBD_EP0_DATA_OUT;
131 | pdev->ep_out[0].total_length = len;
132 | pdev->ep_out[0].rem_length = len;
133 |
134 | /* Start the transfer */
135 | (void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
136 |
137 | return USBD_OK;
138 | }
139 |
140 | /**
141 | * @brief USBD_CtlContinueRx
142 | * continue receive data on the ctl pipe
143 | * @param pdev: device instance
144 | * @param buff: pointer to data buffer
145 | * @param len: length of data to be received
146 | * @retval status
147 | */
148 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
149 | uint8_t *pbuf, uint32_t len)
150 | {
151 | (void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
152 |
153 | return USBD_OK;
154 | }
155 |
156 | /**
157 | * @brief USBD_CtlSendStatus
158 | * send zero lzngth packet on the ctl pipe
159 | * @param pdev: device instance
160 | * @retval status
161 | */
162 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev)
163 | {
164 | /* Set EP0 State */
165 | pdev->ep0_state = USBD_EP0_STATUS_IN;
166 |
167 | /* Start the transfer */
168 | (void)USBD_LL_Transmit(pdev, 0x00U, NULL, 0U);
169 |
170 | return USBD_OK;
171 | }
172 |
173 | /**
174 | * @brief USBD_CtlReceiveStatus
175 | * receive zero lzngth packet on the ctl pipe
176 | * @param pdev: device instance
177 | * @retval status
178 | */
179 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev)
180 | {
181 | /* Set EP0 State */
182 | pdev->ep0_state = USBD_EP0_STATUS_OUT;
183 |
184 | /* Start the transfer */
185 | (void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
186 |
187 | return USBD_OK;
188 | }
189 |
190 | /**
191 | * @brief USBD_GetRxCount
192 | * returns the received data length
193 | * @param pdev: device instance
194 | * @param ep_addr: endpoint address
195 | * @retval Rx Data blength
196 | */
197 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
198 | {
199 | return USBD_LL_GetRxDataSize(pdev, ep_addr);
200 | }
201 |
202 | /**
203 | * @}
204 | */
205 |
206 |
207 | /**
208 | * @}
209 | */
210 |
211 |
212 | /**
213 | * @}
214 | */
215 |
216 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
217 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | # I2S USB Microphone
3 |
4 | This repository contains the source code to the firmware for a 48kHz 16-bit USB microphone implemented using an I2S INMP441 MEMS microphone and an STM32F446.
5 |
6 | Additional features include real-time graphic equalizer and smart volume control audio processing using ST Micro's GREQ and SVC libraries.
7 |
8 | The documentation for this project can be found at [my website](https://andybrown.me.uk/2021/01/30/usb-microphone).
9 |
10 | 
11 |
12 | ## Building the firmware
13 |
14 | The firmware has been tested to build successfully on Ubuntu Linux and it should work on any similar system. You'll need to have the `arm-none-eabi` gcc toolchain installed. If you haven't got this then Google 'arm-none-eabi' for instructions how to install it.
15 |
16 | If you also want to flash the firmware to a device over an SWD connection managed by ST-Link then you'll also need the `STM32CubeProgrammer` package. Again, if you haven't got it then Google it and follow the online installation instructions. When installing on a Linux system then do it from an elevated `sudo` prompt so that it gets installed into `/usr/local/STMicroelectronics/STM32Cube/STM32CubeProgrammer`.
17 |
18 | A `Makefile` is provided that will build the firmware and optionally flash it. Here are example invocations:
19 |
20 | ```
21 | make release ; builds an optimised binary with -O3
22 | make debug ; builds a debug binary with -O0 -g3
23 | ```
24 |
25 | If you also want to automatically flash the firmware using a connected ST-Link debugger then just append the `flash` target.
26 |
27 | ```
28 | make release flash
29 | make debug flash
30 | ```
31 |
32 | The `flash` target assumes that you've installed `STM32CubeProgrammer` into `/usr/local/STMicroelectronics/STM32Cube/STM32CubeProgrammer`. If this is not the case then edit `Makefile` and correct the `PROGRAMMER` macro at the top of the file.
33 |
34 | All generated files are placed in a `build` subdirectory.
35 |
36 | ## Developing the firmware
37 |
38 | If you'd like to edit the firmware in the STM32Cube IDE then `.project` and `.cproject` files are provided that can be imported directly into the IDE.
39 |
40 | You will find `Debug` and `Debug_Semihosting` build configurations that use standard GDB debugging and debugging with semihosting enabled, respectively. There are matching `Debug` and `Debug_Semihosting` launch configurations to use for live hardware debugging. I don't keep semihosting enabled all the time because it's just so dreadfully slow.
41 |
42 | The CubeMX GUI configuration file `usb-microphone.ioc` is provided for reference only. You can open and view it but don't try to generate project source code from it because the sources have diverged so much from what CubeMX expects that it will overwrite the firmware source.
43 |
44 | ## WAV samples
45 |
46 | In the `wav-samples` directory you'll find some sample audio files:
47 |
48 | `1-direct-no-transforms.wav`: Straight from the microphone, no processing. It's very quiet.
49 |
50 | `2-svc-36db-amplification.wav`: 36dB amplification applied by the SVC filter.
51 |
52 | `3-svc-greq.wav`: -6 -6 -6 +6 +6 +6 +6 +6 +6 +6 GREQ filter followed by +36dB SVC filter.
53 |
--------------------------------------------------------------------------------
/STM32F446RCTX_FLASH.ld:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file LinkerScript.ld
4 | * @author Auto-generated by STM32CubeIDE
5 | * @brief Linker script for STM32F446RCTx Device from STM32F4 series
6 | * 256Kbytes FLASH
7 | * 128Kbytes RAM
8 | *
9 | * Set heap size, stack size and stack location according
10 | * to application requirements.
11 | *
12 | * Set memory bank area and size if external memory is used
13 | ******************************************************************************
14 | * @attention
15 | *
16 | * © Copyright (c) 2020 STMicroelectronics.
17 | * All rights reserved.
18 | *
19 | * This software component is licensed by ST under BSD 3-Clause license,
20 | * the "License"; You may not use this file except in compliance with the
21 | * License. You may obtain a copy of the License at:
22 | * opensource.org/licenses/BSD-3-Clause
23 | *
24 | ******************************************************************************
25 | */
26 |
27 | /* Entry Point */
28 | ENTRY(Reset_Handler)
29 |
30 | /* Highest address of the user mode stack */
31 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
32 |
33 | _Min_Heap_Size = 0x4000 ; /* required amount of heap */
34 | _Min_Stack_Size = 0x1000 ; /* required amount of stack */
35 |
36 | /* Memories definition */
37 | MEMORY
38 | {
39 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
40 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 256K
41 | }
42 |
43 | /* Sections */
44 | SECTIONS
45 | {
46 | /* The startup code into "FLASH" Rom type memory */
47 | .isr_vector :
48 | {
49 | . = ALIGN(4);
50 | KEEP(*(.isr_vector)) /* Startup code */
51 | . = ALIGN(4);
52 | } >FLASH
53 |
54 | /* The program code and other data into "FLASH" Rom type memory */
55 | .text :
56 | {
57 | . = ALIGN(4);
58 | *(.text) /* .text sections (code) */
59 | *(.text*) /* .text* sections (code) */
60 | *(.glue_7) /* glue arm to thumb code */
61 | *(.glue_7t) /* glue thumb to arm code */
62 | *(.eh_frame)
63 |
64 | KEEP (*(.init))
65 | KEEP (*(.fini))
66 |
67 | . = ALIGN(4);
68 | _etext = .; /* define a global symbols at end of code */
69 | } >FLASH
70 |
71 | /* Constant data into "FLASH" Rom type memory */
72 | .rodata :
73 | {
74 | . = ALIGN(4);
75 | *(.rodata) /* .rodata sections (constants, strings, etc.) */
76 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
77 | . = ALIGN(4);
78 | } >FLASH
79 |
80 | .ARM.extab : {
81 | . = ALIGN(4);
82 | *(.ARM.extab* .gnu.linkonce.armextab.*)
83 | . = ALIGN(4);
84 | } >FLASH
85 |
86 | .ARM : {
87 | . = ALIGN(4);
88 | __exidx_start = .;
89 | *(.ARM.exidx*)
90 | __exidx_end = .;
91 | . = ALIGN(4);
92 | } >FLASH
93 |
94 | .preinit_array :
95 | {
96 | . = ALIGN(4);
97 | PROVIDE_HIDDEN (__preinit_array_start = .);
98 | KEEP (*(.preinit_array*))
99 | PROVIDE_HIDDEN (__preinit_array_end = .);
100 | . = ALIGN(4);
101 | } >FLASH
102 |
103 | .init_array :
104 | {
105 | . = ALIGN(4);
106 | PROVIDE_HIDDEN (__init_array_start = .);
107 | KEEP (*(SORT(.init_array.*)))
108 | KEEP (*(.init_array*))
109 | PROVIDE_HIDDEN (__init_array_end = .);
110 | . = ALIGN(4);
111 | } >FLASH
112 |
113 | .fini_array :
114 | {
115 | . = ALIGN(4);
116 | PROVIDE_HIDDEN (__fini_array_start = .);
117 | KEEP (*(SORT(.fini_array.*)))
118 | KEEP (*(.fini_array*))
119 | PROVIDE_HIDDEN (__fini_array_end = .);
120 | . = ALIGN(4);
121 | } >FLASH
122 |
123 | /* Used by the startup to initialize data */
124 | _sidata = LOADADDR(.data);
125 |
126 | /* Initialized data sections into "RAM" Ram type memory */
127 | .data :
128 | {
129 | . = ALIGN(4);
130 | _sdata = .; /* create a global symbol at data start */
131 | *(.data) /* .data sections */
132 | *(.data*) /* .data* sections */
133 |
134 | . = ALIGN(4);
135 | _edata = .; /* define a global symbol at data end */
136 |
137 | } >RAM AT> FLASH
138 |
139 | /* Uninitialized data section into "RAM" Ram type memory */
140 | . = ALIGN(4);
141 | .bss :
142 | {
143 | /* This is used by the startup in order to initialize the .bss section */
144 | _sbss = .; /* define a global symbol at bss start */
145 | __bss_start__ = _sbss;
146 | *(.bss)
147 | *(.bss*)
148 | *(COMMON)
149 |
150 | . = ALIGN(4);
151 | _ebss = .; /* define a global symbol at bss end */
152 | __bss_end__ = _ebss;
153 | } >RAM
154 |
155 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
156 | ._user_heap_stack :
157 | {
158 | . = ALIGN(8);
159 | PROVIDE ( end = . );
160 | PROVIDE ( _end = . );
161 | . = . + _Min_Heap_Size;
162 | . = . + _Min_Stack_Size;
163 | . = ALIGN(8);
164 | } >RAM
165 |
166 | /* Remove information from the compiler libraries */
167 | /DISCARD/ :
168 | {
169 | libc.a ( * )
170 | libm.a ( * )
171 | libgcc.a ( * )
172 | }
173 |
174 | .ARM.attributes 0 : { *(.ARM.attributes) }
175 | }
176 |
--------------------------------------------------------------------------------
/USB_DEVICE/App/usb_device.c:
--------------------------------------------------------------------------------
1 | #include "usb_device.h"
2 | #include "usbd_core.h"
3 | #include "usbd_desc.h"
4 | #include "usbd_audio_in.h"
5 | #include "usbd_audio_if.h"
6 |
7 |
8 | USBD_HandleTypeDef hUsbDeviceFS;
9 |
10 |
11 | void MX_USB_DEVICE_Init() {
12 |
13 | USBD_AUDIO_Init_Microphone_Descriptor(&hUsbDeviceFS, MIC_SAMPLE_FREQUENCY, MIC_NUM_CHANNELS);
14 |
15 | /* Init Device Library, add supported class and start the library. */
16 |
17 | if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK ||
18 | USBD_RegisterClass(&hUsbDeviceFS, &USBD_AUDIO) != USBD_OK ||
19 | USBD_AUDIO_RegisterInterface(&hUsbDeviceFS, &USBD_AUDIO_fops) != USBD_OK ||
20 | USBD_Start(&hUsbDeviceFS) != USBD_OK) {
21 | Error_Handler();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/USB_DEVICE/App/usb_device.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "stm32f4xx.h"
4 | #include "stm32f4xx_hal.h"
5 | #include "usbd_def.h"
6 |
7 | void MX_USB_DEVICE_Init();
8 |
--------------------------------------------------------------------------------
/USB_DEVICE/App/usbd_audio_if.cpp:
--------------------------------------------------------------------------------
1 | #include "Application.h"
2 |
3 | static int8_t Audio_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr);
4 | static int8_t Audio_DeInit(uint32_t options);
5 | static int8_t Audio_Record();
6 | static int8_t Audio_VolumeCtl(int16_t Volume);
7 | static int8_t Audio_MuteCtl(uint8_t cmd);
8 | static int8_t Audio_Stop();
9 | static int8_t Audio_Pause();
10 | static int8_t Audio_Resume();
11 | static int8_t Audio_CommandMgr(uint8_t cmd);
12 |
13 | USBD_AUDIO_ItfTypeDef USBD_AUDIO_fops = { Audio_Init, Audio_DeInit, Audio_Record, Audio_VolumeCtl, Audio_MuteCtl,
14 | Audio_Stop, Audio_Pause, Audio_Resume, Audio_CommandMgr, };
15 |
16 | /**
17 | * @brief Initializes the AUDIO media low layer over USB FS IP
18 | * @param AudioFreq: Audio frequency used to play the audio stream.
19 | * @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
20 | * @param options: Reserved for future use
21 | * @retval USBD_OK if all operations are OK else USBD_FAIL
22 | */
23 |
24 | static int8_t Audio_Init(uint32_t AudioFreq, uint32_t Volume, uint32_t options) {
25 | HAL_GPIO_WritePin(LINK_LED_GPIO_Port, LINK_LED_Pin, GPIO_PIN_SET);
26 | return USBD_OK;
27 | }
28 |
29 | /**
30 | * @brief De-Initializes the AUDIO media low layer
31 | * @param options: Reserved for future use
32 | * @retval USBD_OK if all operations are OK else USBD_FAIL
33 | */
34 |
35 | static int8_t Audio_DeInit(uint32_t options) {
36 | return USBD_OK;
37 | }
38 |
39 | /**
40 | * @brief Start audio recording engine
41 | * @retval BSP_ERROR_NONE in case of success, AUDIO_ERROR otherwise
42 | */
43 |
44 | static int8_t Audio_Record() {
45 | return Audio::_instance->start();
46 | }
47 |
48 | /**
49 | * @brief Controls AUDIO Volume.
50 | * @param vol: volume level
51 | * @retval USBD_OK if all operations are OK else USBD_FAIL
52 | */
53 |
54 | static int8_t Audio_VolumeCtl(int16_t vol) {
55 | Audio::_instance->setVolume(vol);
56 | return USBD_OK;
57 | }
58 |
59 | /**
60 | * @brief Controls AUDIO Mute.
61 | * @param cmd: command opcode
62 | * @retval USBD_OK if all operations are OK else USBD_FAIL
63 | */
64 |
65 | static int8_t Audio_MuteCtl(uint8_t cmd) {
66 | return USBD_OK;
67 | }
68 |
69 | /**
70 | * @brief Stops audio acquisition
71 | * @param none
72 | * @retval BSP_ERROR_NONE in case of success, AUDIO_ERROR otherwise
73 | */
74 |
75 | static int8_t Audio_Stop() {
76 | return Audio::_instance->stop();
77 | }
78 |
79 | /**
80 | * @brief Pauses audio acquisition
81 | * @param none
82 | * @retval BSP_ERROR_NONE in case of success, AUDIO_ERROR otherwise
83 | */
84 |
85 | static int8_t Audio_Pause() {
86 | return Audio::_instance->pause();
87 | }
88 |
89 | /**
90 | * @brief Resumes audio acquisition
91 | * @param none
92 | * @retval BSP_ERROR_NONE in case of success, AUDIO_ERROR otherwise
93 | */
94 |
95 | static int8_t Audio_Resume() {
96 | return Audio::_instance->resume();
97 | }
98 |
99 | /**
100 | * @brief Manages command from usb
101 | * @param None
102 | * @retval BSP_ERROR_NONE in case of success, AUDIO_ERROR otherwise
103 | */
104 |
105 | static int8_t Audio_CommandMgr(uint8_t cmd) {
106 | return USBD_OK;
107 | }
108 |
109 | /**
110 | * Implement the HAL interrupt callbacks that process completed milliseconds of data
111 | */
112 |
113 | extern "C" {
114 |
115 | void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s) {
116 | Audio::_instance->i2s_halfComplete();
117 | }
118 |
119 | void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s) {
120 | Audio::_instance->i2s_complete();
121 | }
122 |
123 | }
124 |
125 |
--------------------------------------------------------------------------------
/USB_DEVICE/App/usbd_audio_if.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "usbd_audio_in.h"
4 |
5 | #define MIC_SAMPLE_FREQUENCY 48000
6 | #define MIC_SAMPLES_PER_MS (MIC_SAMPLE_FREQUENCY/1000) // == 48
7 | #define MIC_NUM_CHANNELS 1
8 | #define MIC_MS_PER_PACKET 20
9 | #define MIC_SAMPLES_PER_PACKET (MIC_SAMPLES_PER_MS * MIC_MS_PER_PACKET) // == 960
10 |
11 | extern USBD_AUDIO_ItfTypeDef USBD_AUDIO_fops;
12 |
--------------------------------------------------------------------------------
/USB_DEVICE/App/usbd_desc.c:
--------------------------------------------------------------------------------
1 | #include "usbd_core.h"
2 | #include "usbd_desc.h"
3 | #include "usbd_conf.h"
4 |
5 | #define USBD_VID 0x0483
6 | #define USBD_LANGID_STRING 1033
7 | #define USBD_MANUFACTURER_STRING "Andy's Workshop"
8 | #define USBD_PID_FS 0x5731
9 | #define USBD_PRODUCT_STRING_FS "Andy's Workshop Microphone"
10 | #define USBD_CONFIGURATION_STRING_FS "AUDIO Config"
11 | #define USBD_INTERFACE_STRING_FS "AUDIO Interface"
12 |
13 | #define USB_SIZ_BOS_DESC 0x0C
14 |
15 | static void Get_SerialNum(void);
16 | static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len);
17 |
18 | uint8_t* USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
19 | uint8_t* USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
20 | uint8_t* USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
21 | uint8_t* USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
22 | uint8_t* USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
23 | uint8_t* USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
24 | uint8_t* USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
25 |
26 | #if (USBD_LPM_ENABLED == 1)
27 | uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
28 | #endif /* (USBD_LPM_ENABLED == 1) */
29 |
30 | USBD_DescriptorsTypeDef FS_Desc = { USBD_FS_DeviceDescriptor, USBD_FS_LangIDStrDescriptor,
31 | USBD_FS_ManufacturerStrDescriptor, USBD_FS_ProductStrDescriptor, USBD_FS_SerialStrDescriptor,
32 | USBD_FS_ConfigStrDescriptor, USBD_FS_InterfaceStrDescriptor
33 | #if (USBD_LPM_ENABLED == 1)
34 | , USBD_FS_USR_BOSDescriptor
35 | #endif /* (USBD_LPM_ENABLED == 1) */
36 | };
37 |
38 | /** USB standard device descriptor. */
39 |
40 | __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = { 0x12, /*bLength */
41 | USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
42 | #if (USBD_LPM_ENABLED == 1)
43 | 0x01, /*bcdUSB */ /* changed to USB version 2.01
44 | in order to support LPM L1 suspend
45 | resume test of USBCV3.0*/
46 | #else
47 | 0x00, /*bcdUSB */
48 | #endif /* (USBD_LPM_ENABLED == 1) */
49 | 0x02, 0x00, /*bDeviceClass*/
50 | 0x00, /*bDeviceSubClass*/
51 | 0x00, /*bDeviceProtocol*/
52 | USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
53 | LOBYTE(USBD_VID), /*idVendor*/
54 | HIBYTE(USBD_VID), /*idVendor*/
55 | LOBYTE(USBD_PID_FS), /*idProduct*/
56 | HIBYTE(USBD_PID_FS), /*idProduct*/
57 | 0x00, /*bcdDevice rel. 2.00*/
58 | 0x02,
59 | USBD_IDX_MFC_STR, /*Index of manufacturer string*/
60 | USBD_IDX_PRODUCT_STR, /*Index of product string*/
61 | USBD_IDX_SERIAL_STR, /*Index of serial number string*/
62 | USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
63 | };
64 |
65 | /* USB_DeviceDescriptor */
66 | /** BOS descriptor. */
67 |
68 | #if (USBD_LPM_ENABLED == 1)
69 | __ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
70 | {
71 | 0x5,
72 | USB_DESC_TYPE_BOS,
73 | 0xC,
74 | 0x0,
75 | 0x1, /* 1 device capability*/
76 | /* device capability*/
77 | 0x7,
78 | USB_DEVICE_CAPABITY_TYPE,
79 | 0x2,
80 | 0x2, /* LPM capability bit set*/
81 | 0x0,
82 | 0x0,
83 | 0x0
84 | };
85 | #endif /* (USBD_LPM_ENABLED == 1) */
86 |
87 | /** USB lang indentifier descriptor. */
88 |
89 | __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
90 | USB_LEN_LANGID_STR_DESC,
91 | USB_DESC_TYPE_STRING, LOBYTE(USBD_LANGID_STRING), HIBYTE(USBD_LANGID_STRING) };
92 |
93 | #if defined ( __ICCARM__ ) /* IAR Compiler */
94 | #pragma data_alignment=4
95 | #endif /* defined ( __ICCARM__ ) */
96 | /* Internal string descriptor. */
97 | __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
98 |
99 | #if defined ( __ICCARM__ ) /*!< IAR Compiler */
100 | #pragma data_alignment=4
101 | #endif
102 | __ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = {
103 | USB_SIZ_STRING_SERIAL,
104 | USB_DESC_TYPE_STRING, };
105 |
106 | /**
107 | * @brief Return the device descriptor
108 | * @param speed : Current device speed
109 | * @param length : Pointer to data length variable
110 | * @retval Pointer to descriptor buffer
111 | */
112 |
113 | uint8_t* USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
114 | *length = sizeof(USBD_FS_DeviceDesc);
115 | return USBD_FS_DeviceDesc;
116 | }
117 |
118 | /**
119 | * @brief Return the LangID string descriptor
120 | * @param speed : Current device speed
121 | * @param length : Pointer to data length variable
122 | * @retval Pointer to descriptor buffer
123 | */
124 |
125 | uint8_t* USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
126 | *length = sizeof(USBD_LangIDDesc);
127 | return USBD_LangIDDesc;
128 | }
129 |
130 | /**
131 | * @brief Return the product string descriptor
132 | * @param speed : Current device speed
133 | * @param length : Pointer to data length variable
134 | * @retval Pointer to descriptor buffer
135 | */
136 |
137 | uint8_t* USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
138 |
139 | if (speed == 0) {
140 | USBD_GetString((uint8_t*) USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
141 | } else {
142 | USBD_GetString((uint8_t*) USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
143 | }
144 | return USBD_StrDesc;
145 | }
146 |
147 | /**
148 | * @brief Return the manufacturer string descriptor
149 | * @param speed : Current device speed
150 | * @param length : Pointer to data length variable
151 | * @retval Pointer to descriptor buffer
152 | */
153 |
154 | uint8_t* USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
155 | USBD_GetString((uint8_t*) USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
156 | return USBD_StrDesc;
157 | }
158 |
159 | /**
160 | * @brief Return the serial number string descriptor
161 | * @param speed : Current device speed
162 | * @param length : Pointer to data length variable
163 | * @retval Pointer to descriptor buffer
164 | */
165 |
166 | uint8_t* USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
167 | *length = USB_SIZ_STRING_SERIAL;
168 |
169 | /* Update the serial number string descriptor with the data from the unique ID */
170 |
171 | Get_SerialNum();
172 | return (uint8_t*) USBD_StringSerial;
173 | }
174 |
175 | /**
176 | * @brief Return the configuration string descriptor
177 | * @param speed : Current device speed
178 | * @param length : Pointer to data length variable
179 | * @retval Pointer to descriptor buffer
180 | */
181 |
182 | uint8_t* USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
183 |
184 | if (speed == USBD_SPEED_HIGH) {
185 | USBD_GetString((uint8_t*) USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
186 | } else {
187 | USBD_GetString((uint8_t*) USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
188 | }
189 | return USBD_StrDesc;
190 | }
191 |
192 | /**
193 | * @brief Return the interface string descriptor
194 | * @param speed : Current device speed
195 | * @param length : Pointer to data length variable
196 | * @retval Pointer to descriptor buffer
197 | */
198 |
199 | uint8_t* USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
200 | if (speed == 0) {
201 | USBD_GetString((uint8_t*) USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
202 | } else {
203 | USBD_GetString((uint8_t*) USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
204 | }
205 | return USBD_StrDesc;
206 | }
207 |
208 | #if (USBD_LPM_ENABLED == 1)
209 | /**
210 | * @brief Return the BOS descriptor
211 | * @param speed : Current device speed
212 | * @param length : Pointer to data length variable
213 | * @retval Pointer to descriptor buffer
214 | */
215 |
216 | uint8_t *USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
217 | *length = sizeof(USBD_FS_BOSDesc);
218 | return (uint8_t*)USBD_FS_BOSDesc;
219 | }
220 | #endif /* (USBD_LPM_ENABLED == 1) */
221 |
222 | /**
223 | * @brief Create the serial number string descriptor
224 | * @param None
225 | * @retval None
226 | */
227 |
228 | static void Get_SerialNum() {
229 | uint32_t deviceserial0, deviceserial1, deviceserial2;
230 |
231 | deviceserial0 = *(uint32_t*) DEVICE_ID1;
232 | deviceserial1 = *(uint32_t*) DEVICE_ID2;
233 | deviceserial2 = *(uint32_t*) DEVICE_ID3;
234 |
235 | deviceserial0 += deviceserial2;
236 |
237 | if (deviceserial0 != 0) {
238 | IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8);
239 | IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4);
240 | }
241 | }
242 |
243 | /**
244 | * @brief Convert Hex 32Bits value into char
245 | * @param value: value to convert
246 | * @param pbuf: pointer to the buffer
247 | * @param len: buffer length
248 | * @retval None
249 | */
250 |
251 | static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len) {
252 |
253 | uint8_t idx = 0;
254 |
255 | for (idx = 0; idx < len; idx++) {
256 | if (((value >> 28)) < 0xA) {
257 | pbuf[2 * idx] = (value >> 28) + '0';
258 | } else {
259 | pbuf[2 * idx] = (value >> 28) + 'A' - 10;
260 | }
261 | value = value << 4;
262 | pbuf[2 * idx + 1] = 0;
263 | }
264 | }
265 |
--------------------------------------------------------------------------------
/USB_DEVICE/App/usbd_desc.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "usbd_def.h"
4 |
5 | #define DEVICE_ID1 (UID_BASE)
6 | #define DEVICE_ID2 (UID_BASE + 0x4)
7 | #define DEVICE_ID3 (UID_BASE + 0x8)
8 |
9 | #define USB_SIZ_STRING_SERIAL 0x1A
10 |
11 | extern USBD_DescriptorsTypeDef FS_Desc;
12 |
--------------------------------------------------------------------------------
/USB_DEVICE/Target/usbd_conf.h:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file : usbd_conf.h
5 | * @version : v1.0_Cube
6 | * @brief : Header for usbd_conf.c file.
7 | ******************************************************************************
8 | * @attention
9 | *
10 | * © Copyright (c) 2020 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 __USBD_CONF__H__
24 | #define __USBD_CONF__H__
25 |
26 | #ifdef __cplusplus
27 | extern "C" {
28 | #endif
29 |
30 | /* Includes ------------------------------------------------------------------*/
31 | #include
32 | #include
33 | #include
34 | #include "main.h"
35 | #include "stm32f4xx.h"
36 | #include "stm32f4xx_hal.h"
37 |
38 | /* USER CODE BEGIN INCLUDE */
39 |
40 | /* USER CODE END INCLUDE */
41 |
42 | /** @addtogroup USBD_OTG_DRIVER
43 | * @brief Driver for Usb device.
44 | * @{
45 | */
46 |
47 | /** @defgroup USBD_CONF USBD_CONF
48 | * @brief Configuration file for Usb otg low level driver.
49 | * @{
50 | */
51 |
52 | /** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables
53 | * @brief Public variables.
54 | * @{
55 | */
56 |
57 | /**
58 | * @}
59 | */
60 |
61 | /** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines
62 | * @brief Defines for configuration of the Usb device.
63 | * @{
64 | */
65 |
66 | /*---------- -----------*/
67 | #define USBD_MAX_NUM_INTERFACES 2U
68 | /*---------- -----------*/
69 | #define USBD_MAX_NUM_CONFIGURATION 1U
70 | /*---------- -----------*/
71 | #define USBD_MAX_STR_DESC_SIZ 512U
72 | /*---------- -----------*/
73 | #define USBD_DEBUG_LEVEL 0U
74 | /*---------- -----------*/
75 | #define USBD_LPM_ENABLED 0U
76 | /*---------- -----------*/
77 | #define USBD_SELF_POWERED 0U
78 | /*---------- -----------*/
79 | #define USBD_AUDIO_FREQ 48000U
80 |
81 | /****************************************/
82 | /* #define for FS and HS identification */
83 | #define DEVICE_FS 0
84 | #define DEVICE_HS 1
85 |
86 | /**
87 | * @}
88 | */
89 |
90 | /** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros
91 | * @brief Aliases.
92 | * @{
93 | */
94 |
95 | /* Memory management macros */
96 |
97 | /** Alias for memory allocation. */
98 | #define USBD_malloc malloc
99 |
100 | /** Alias for memory release. */
101 | #define USBD_free free
102 |
103 | /** Alias for memory set. */
104 | #define USBD_memset memset
105 |
106 | /** Alias for memory copy. */
107 | #define USBD_memcpy memcpy
108 |
109 | /** Alias for delay. */
110 | #define USBD_Delay HAL_Delay
111 |
112 | /* DEBUG macros */
113 |
114 | #if (USBD_DEBUG_LEVEL > 0)
115 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\
116 | printf("\n");
117 | #else
118 | #define USBD_UsrLog(...)
119 | #endif
120 |
121 | #if (USBD_DEBUG_LEVEL > 1)
122 |
123 | #define USBD_ErrLog(...) printf("ERROR: ") ;\
124 | printf(__VA_ARGS__);\
125 | printf("\n");
126 | #else
127 | #define USBD_ErrLog(...)
128 | #endif
129 |
130 | #if (USBD_DEBUG_LEVEL > 2)
131 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\
132 | printf(__VA_ARGS__);\
133 | printf("\n");
134 | #else
135 | #define USBD_DbgLog(...)
136 | #endif
137 |
138 | /**
139 | * @}
140 | */
141 |
142 | /** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types
143 | * @brief Types.
144 | * @{
145 | */
146 |
147 | /**
148 | * @}
149 | */
150 |
151 | /** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype
152 | * @brief Declaration of public functions for Usb device.
153 | * @{
154 | */
155 |
156 | /* Exported functions -------------------------------------------------------*/
157 |
158 | /**
159 | * @}
160 | */
161 |
162 | /**
163 | * @}
164 | */
165 |
166 | /**
167 | * @}
168 | */
169 |
170 | #ifdef __cplusplus
171 | }
172 | #endif
173 |
174 | #endif /* __USBD_CONF__H__ */
175 |
176 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
177 |
--------------------------------------------------------------------------------
/board-running.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andysworkshop/usb-microphone/5eb348566212141c235f19b99f2e8b577523ca65/board-running.jpg
--------------------------------------------------------------------------------
/usb-microphone Debug_Semihosting.cfg:
--------------------------------------------------------------------------------
1 | # This is an genericBoard board with a single STM32F446RCTx chip
2 | #
3 | # Generated by STM32CubeIDE
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-dap.cfg]
7 |
8 |
9 | set WORKAREASIZE 0x8000
10 |
11 | transport select "dapdirect_swd"
12 |
13 | set CHIPNAME STM32F446RCTx
14 | set BOARDNAME genericBoard
15 |
16 | # Enable debug when in low power modes
17 | set ENABLE_LOW_POWER 1
18 |
19 | # Stop Watchdog counters when halt
20 | set STOP_WATCHDOG 1
21 |
22 | # STlink Debug clock frequency
23 | set CLOCK_FREQ 8000
24 |
25 | # Reset configuration
26 | # use hardware reset, connect under reset
27 | # connect_assert_srst needed if low power mode application running (WFI...)
28 | reset_config srst_only srst_nogate connect_assert_srst
29 | set CONNECT_UNDER_RESET 1
30 | set CORE_RESET 0
31 |
32 | # ACCESS PORT NUMBER
33 | set AP_NUM 0
34 | # GDB PORT
35 | set GDB_PORT 3333
36 |
37 |
38 |
39 | # BCTM CPU variables
40 |
41 | source [find target/stm32f4x.cfg]
42 |
43 | #SWV trace
44 | tpiu config disable
45 |
--------------------------------------------------------------------------------
/usb-microphone Debug_Semihosting.launch:
--------------------------------------------------------------------------------
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 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/usb-microphone.ioc:
--------------------------------------------------------------------------------
1 | #MicroXplorer Configuration settings - do not modify
2 | Mcu.Family=STM32F4
3 | ProjectManager.MainLocation=Core/Src
4 | PA2.GPIO_PuPd=GPIO_PULLUP
5 | PH0-OSC_IN.Locked=true
6 | PB13.GPIOParameters=GPIO_Label
7 | USB_DEVICE.CLASS_NAME_FS=AUDIO
8 | PH0-OSC_IN.Signal=RCC_OSC_IN
9 | RCC.CortexFreq_Value=180000000
10 | I2S1.ErrorAudioFreq=0.0 %
11 | ProjectManager.KeepUserCode=true
12 | Mcu.UserName=STM32F446RCTx
13 | RCC.PLLCLKFreq_Value=180000000
14 | RCC.PLLQCLKFreq_Value=51428571.428571425
15 | ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_I2S1_Init-I2S1-false-HAL-true,5-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false
16 | I2S1.Mode=I2S_MODE_MASTER_RX
17 | PA11.Mode=Device_Only
18 | PC9.Locked=true
19 | RCC.PLLI2SRCLKFreq_Value=50000000
20 | PB13.GPIO_Label=MUTE_LED
21 | PB13.Signal=GPIO_Output
22 | RCC.SAIAFreq_Value=96000000
23 | PA2.GPIOParameters=GPIO_PuPd,GPIO_Label
24 | PinOutPanel.RotationAngle=0
25 | I2S1.Instance=SPI$Index
26 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
27 | ProjectManager.StackSize=0x1000
28 | USB_DEVICE.PID_AUDIO_FS=0x5731
29 | Mcu.IP4=SYS
30 | RCC.FCLKCortexFreq_Value=180000000
31 | Mcu.IP5=USB_DEVICE
32 | Mcu.IP2=NVIC
33 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false
34 | Mcu.IP3=RCC
35 | Mcu.IP0=DMA
36 | PA12.Locked=true
37 | Mcu.IP1=I2S1
38 | PA12.Signal=USB_OTG_FS_DP
39 | Mcu.UserConstants=
40 | Dma.SPI1_RX.0.Direction=DMA_PERIPH_TO_MEMORY
41 | PA4.Mode=Half_Duplex_Master
42 | I2S1.DataFormat=I2S_DATAFORMAT_24B
43 | Mcu.ThirdPartyNb=0
44 | RCC.SDIOFreq_Value=48000000
45 | RCC.HCLKFreq_Value=180000000
46 | Mcu.IPNb=7
47 | ProjectManager.PreviousToolchain=STM32CubeIDE
48 | RCC.APB2TimFreq_Value=180000000
49 | RCC.SPDIFRXFreq_Value=180000000
50 | Mcu.Pin6=PB12
51 | NVIC.DMA2_Stream0_IRQn=true\:0\:0\:false\:false\:true\:false\:true
52 | Mcu.Pin7=PB13
53 | Mcu.Pin8=PC9
54 | Mcu.Pin9=PA11
55 | RCC.I2S2CLockSelection=RCC_I2SAPB2CLKSOURCE_EXT
56 | RCC.VCOSAIOutputFreq_Value=192000000
57 | RCC.AHBFreq_Value=180000000
58 | PH0-OSC_IN.Mode=HSE-External-Oscillator
59 | PB13.Locked=true
60 | Mcu.Pin0=PH0-OSC_IN
61 | Mcu.Pin1=PH1-OSC_OUT
62 | GPIO.groupedBy=Group By Peripherals
63 | Mcu.Pin2=PA2
64 | Mcu.Pin3=PA4
65 | Mcu.Pin4=PA5
66 | Mcu.Pin5=PA7
67 | ProjectManager.ProjectBuild=false
68 | RCC.HSE_VALUE=8000000
69 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
70 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false
71 | PA4.Locked=true
72 | NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true
73 | PB12.GPIO_Label=LINK_LED
74 | Dma.SPI1_RX.0.PeriphInc=DMA_PINC_DISABLE
75 | ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.25.2
76 | MxDb.Version=DB.6.0.10
77 | USB_DEVICE.MANUFACTURER_STRING-AUDIO_FS=Andy's Workshop
78 | ProjectManager.BackupPrevious=false
79 | RCC.VCOInputFreq_Value=1000000
80 | File.Version=6
81 | PC9.Mode=Audio_ClockIn
82 | PH1-OSC_OUT.Locked=true
83 | I2S1.ClockSource-Half_Duplex_Master=I2S_CLOCK_PLL
84 | I2S1.IPParameters=Instance,VirtualMode,FullDuplexMode,RealAudioFreq,ErrorAudioFreq,Mode,DataFormat,AudioFreq,ClockSource-Half_Duplex_Master
85 | RCC.PLLRCLKFreq_Value=180000000
86 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false
87 | Dma.RequestsNb=1
88 | RCC.PLLI2SoutputFreq_Value=50000000
89 | ProjectManager.HalAssertFull=false
90 | ProjectManager.ProjectName=usb-microphone
91 | PH1-OSC_OUT.Mode=HSE-External-Oscillator
92 | RCC.MCO2PinFreq_Value=180000000
93 | USB_DEVICE.PRODUCT_STRING_AUDIO_FS=Andy's Workshop Microphone
94 | Mcu.Package=LQFP64
95 | PA5.Locked=true
96 | PA7.Locked=true
97 | RCC.I2S2Freq_Value=12288000
98 | NVIC.OTG_FS_IRQn=true\:0\:0\:false\:false\:true\:false\:true
99 | ProjectManager.ToolChainLocation=
100 | PA2.GPIO_Label=MUTE
101 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick
102 | USB_OTG_FS.VirtualMode=Device_Only
103 | RCC.PLLSAIN=96
104 | RCC.PLLSAIM=4
105 | RCC.PLLSAIP=RCC_PLLSAIP_DIV4
106 | RCC.APB2CLKDivider=RCC_HCLK_DIV2
107 | RCC.CECFreq_Value=32786.88524590164
108 | RCC.APB1TimFreq_Value=90000000
109 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
110 | USB_OTG_FS.IPParameters=VirtualMode,Sof_enable
111 | RCC.SAIBFreq_Value=96000000
112 | Dma.SPI1_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode
113 | Dma.Request0=SPI1_RX
114 | ProjectManager.CustomerFirmwarePackage=
115 | RCC.PLLSAIQCLKFreq_Value=96000000
116 | USB_DEVICE.USBD_AUDIO_FREQ-AUDIO_FS=48000
117 | PA5.Mode=Half_Duplex_Master
118 | PA2.Locked=true
119 | USB_DEVICE.VID-AUDIO_FS=0x483
120 | ProjectManager.ProjectFileName=usb-microphone.ioc
121 | PA7.Mode=Half_Duplex_Master
122 | USB_DEVICE.VirtualMode-AUDIO_FS=Audio
123 | Mcu.PinsNb=13
124 | ProjectManager.NoMain=false
125 | USB_DEVICE.VirtualModeFS=Audio_FS
126 | RCC.FMPI2C1Freq_Value=45000000
127 | RCC.VCOI2SInputFreq_Value=2000000
128 | ProjectManager.DefaultFWLocation=true
129 | I2S1.AudioFreq=I2S_AUDIOFREQ_48K
130 | PB12.Locked=true
131 | ProjectManager.DeletePrevious=true
132 | Dma.SPI1_RX.0.Mode=DMA_CIRCULAR
133 | USB_DEVICE.USBD_MAX_NUM_INTERFACES-AUDIO_FS=2
134 | RCC.APB1CLKDivider=RCC_HCLK_DIV4
135 | USB_DEVICE.IPParameters=VirtualMode-AUDIO_FS,VirtualModeFS,CLASS_NAME_FS,USBD_AUDIO_FREQ-AUDIO_FS,VID-AUDIO_FS,PID_AUDIO_FS,MANUFACTURER_STRING-AUDIO_FS,PRODUCT_STRING_AUDIO_FS,USBD_SELF_POWERED-AUDIO_FS,USBD_LPM_ENABLED-AUDIO_FS,USBD_MAX_NUM_INTERFACES-AUDIO_FS
136 | RCC.FamilyName=M
137 | Dma.SPI1_RX.0.FIFOMode=DMA_FIFOMODE_DISABLE
138 | PA11.Locked=true
139 | ProjectManager.TargetToolchain=STM32CubeIDE
140 | I2S1.VirtualMode=I2S_MODE_MASTER
141 | RCC.I2S1Freq_Value=50000000
142 | ProjectManager.RegisterCallBack=
143 | RCC.USBFreq_Value=48000000
144 | RCC.PLLSAIoutputFreq_Value=48000000
145 | RCC.VCOI2SOutputFreq_Value=100000000
146 | RCC.USBCLockSelection=RCC_CLK48CLKSOURCE_PLLSAIP
147 | PA5.Signal=I2S1_CK
148 | RCC.PLLSAIPCLKFreq_Value=48000000
149 | board=custom
150 | RCC.VCOOutputFreq_Value=360000000
151 | ProjectManager.LastFirmware=true
152 | RCC.APB2Freq_Value=90000000
153 | MxCube.Version=6.1.1
154 | RCC.PLLI2SPCLKFreq_Value=50000000
155 | Dma.SPI1_RX.0.Instance=DMA2_Stream0
156 | VP_SYS_VS_Systick.Mode=SysTick
157 | Dma.SPI1_RX.0.PeriphDataAlignment=DMA_PDATAALIGN_WORD
158 | PH1-OSC_OUT.Signal=RCC_OSC_OUT
159 | Dma.SPI1_RX.0.MemDataAlignment=DMA_MDATAALIGN_WORD
160 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false
161 | USB_OTG_FS.Sof_enable=DISABLE
162 | I2S1.FullDuplexMode=I2S_FULLDUPLEXMODE_DISABLE
163 | VP_USB_DEVICE_VS_USB_DEVICE_AUDIO_FS.Mode=AUDIO_FS
164 | VP_USB_DEVICE_VS_USB_DEVICE_AUDIO_FS.Signal=USB_DEVICE_VS_USB_DEVICE_AUDIO_FS
165 | ProjectManager.FreePins=false
166 | RCC.IPParameters=AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,CECFreq_Value,CortexFreq_Value,FCLKCortexFreq_Value,FMPI2C1Freq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,I2S1Freq_Value,I2S2CLockSelection,I2S2Freq_Value,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLI2SM,PLLI2SN,PLLI2SPCLKFreq_Value,PLLI2SQCLKFreq_Value,PLLI2SRCLKFreq_Value,PLLI2SoutputFreq_Value,PLLM,PLLN,PLLQ,PLLQCLKFreq_Value,PLLRCLKFreq_Value,PLLSAIM,PLLSAIN,PLLSAIP,PLLSAIPCLKFreq_Value,PLLSAIQCLKFreq_Value,PLLSAIoutputFreq_Value,PWRFreq_Value,SAIAFreq_Value,SAIBFreq_Value,SDIOFreq_Value,SPDIFRXFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,USBCLockSelection,USBFreq_Value,VCOI2SInputFreq_Value,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VCOSAIInputFreq_Value,VCOSAIOutputFreq_Value
167 | ProjectManager.AskForMigrate=true
168 | Mcu.Name=STM32F446R(C-E)Tx
169 | RCC.PLLI2SQCLKFreq_Value=50000000
170 | Dma.SPI1_RX.0.MemInc=DMA_MINC_ENABLE
171 | PA2.Signal=GPIO_Input
172 | ProjectManager.UnderRoot=true
173 | Mcu.IP6=USB_OTG_FS
174 | RCC.VCOSAIInputFreq_Value=2000000
175 | ProjectManager.CoupleFile=false
176 | RCC.SYSCLKFreq_VALUE=180000000
177 | PA4.Signal=I2S1_WS
178 | PA12.Mode=Device_Only
179 | NVIC.ForceEnableDMAVector=true
180 | KeepUserPlacement=false
181 | USB_DEVICE.USBD_SELF_POWERED-AUDIO_FS=0
182 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false
183 | ProjectManager.CompilerOptimize=6
184 | PA11.Signal=USB_OTG_FS_DM
185 | ProjectManager.HeapSize=0x4000
186 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
187 | Dma.SPI1_RX.0.Priority=DMA_PRIORITY_LOW
188 | ProjectManager.ComputerToolchain=false
189 | RCC.PLLQ=7
190 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
191 | Mcu.Pin11=VP_SYS_VS_Systick
192 | Mcu.Pin12=VP_USB_DEVICE_VS_USB_DEVICE_AUDIO_FS
193 | RCC.PLLM=8
194 | RCC.PLLN=360
195 | Mcu.Pin10=PA12
196 | RCC.PWRFreq_Value=180000000
197 | PC9.Signal=I2S_CKIN
198 | I2S1.RealAudioFreq=48.0 KHz
199 | RCC.APB1Freq_Value=45000000
200 | USB_DEVICE.USBD_LPM_ENABLED-AUDIO_FS=0
201 | RCC.PLLI2SN=50
202 | ProjectManager.DeviceId=STM32F446RCTx
203 | PB12.GPIOParameters=GPIO_Label
204 | PB12.Signal=GPIO_Output
205 | ProjectManager.LibraryCopy=1
206 | RCC.PLLI2SM=4
207 | PA7.Signal=I2S1_SD
208 |
--------------------------------------------------------------------------------
/wav-samples/1-direct-no-transforms.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andysworkshop/usb-microphone/5eb348566212141c235f19b99f2e8b577523ca65/wav-samples/1-direct-no-transforms.wav
--------------------------------------------------------------------------------
/wav-samples/2-svc-36db-amplification.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andysworkshop/usb-microphone/5eb348566212141c235f19b99f2e8b577523ca65/wav-samples/2-svc-36db-amplification.wav
--------------------------------------------------------------------------------
/wav-samples/3-svc-greq.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andysworkshop/usb-microphone/5eb348566212141c235f19b99f2e8b577523ca65/wav-samples/3-svc-greq.wav
--------------------------------------------------------------------------------
/wav-samples/mute-button-click-fix/after.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andysworkshop/usb-microphone/5eb348566212141c235f19b99f2e8b577523ca65/wav-samples/mute-button-click-fix/after.mp3
--------------------------------------------------------------------------------
/wav-samples/mute-button-click-fix/before.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andysworkshop/usb-microphone/5eb348566212141c235f19b99f2e8b577523ca65/wav-samples/mute-button-click-fix/before.mp3
--------------------------------------------------------------------------------