Skip to content

Commit

Permalink
I2S clock for mcHF STM32F4 corrected to 12.288Mhz
Browse files Browse the repository at this point in the history
Found working clock configuration which provides exactly 12.288 Mhz as I2S
clock and not something slightly lower as before. This may reduce USB audio
issues but still depends on accurate clocks on BOTH ends of the USB
connection (which is never a 100% match). However, for most mcHF USB audio
user this should improve audio quality. No impact on OVI40 which already
uses the correct 12.288Mhz clock. See discussion on df8oe#1077
  • Loading branch information
db4ple committed Feb 26, 2018
1 parent 8834607 commit e16f92d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 49 deletions.
10 changes: 5 additions & 5 deletions mchf-eclipse/basesw/mcHF/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ void SystemClock_Config(void)
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 16;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLM = 10;
RCC_OscInitStruct.PLL.PLLN = 210;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
Expand All @@ -207,15 +207,15 @@ void SystemClock_Config(void)

PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S|RCC_PERIPHCLK_I2S
|RCC_PERIPHCLK_RTC;
PeriphClkInitStruct.PLLI2S.PLLI2SN = 258;
PeriphClkInitStruct.PLLI2S.PLLI2SR = 7;
PeriphClkInitStruct.PLLI2S.PLLI2SN = 192;
PeriphClkInitStruct.PLLI2S.PLLI2SR = 5;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}

HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_PLLI2SCLK, RCC_MCODIV_3);
HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_PLLI2SCLK, RCC_MCODIV_5);

/**Configure the Systick interrupt time
*/
Expand Down
85 changes: 41 additions & 44 deletions mchf-eclipse/basesw/mcHF/mcHF.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ I2C2.I2C_Mode=I2C_Fast
I2C2.IPParameters=I2C_Mode,ClockSpeed,DutyCycle,OwnAddress
I2C2.OwnAddress=0x33
I2S3.AudioFreq=I2S_AUDIOFREQ_48K
I2S3.ErrorAudioFreq=-0.01 %
I2S3.ErrorAudioFreq=0.0 %
I2S3.FullDuplexMode=I2S_FULLDUPLEXMODE_ENABLE
I2S3.IPParameters=FullDuplexMode,RealAudioFreq,ErrorAudioFreq,AudioFreq
I2S3.RealAudioFreq=47.991 KHz
I2S3.IPParameters=FullDuplexMode,RealAudioFreq,ErrorAudioFreq,AudioFreq,Instance,VirtualMode
I2S3.Instance=SPI$Index
I2S3.RealAudioFreq=48.0 KHz
I2S3.VirtualMode=I2S_MODE_MASTER
KeepUserPlacement=false
Mcu.Family=STM32F4
Mcu.IP0=ADC1
Expand Down Expand Up @@ -179,24 +181,24 @@ Mcu.UserConstants=
Mcu.UserName=STM32F407VGTx
MxCube.Version=4.19.0
MxDb.Version=DB.4.0.190
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true
NVIC.DMA1_Stream2_IRQn=true\:2\:0\:true\:false\:true
NVIC.DMA1_Stream4_IRQn=true\:14\:0\:true\:false\:true
NVIC.DMA1_Stream5_IRQn=true\:14\:0\:true\:false\:true
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true
NVIC.EXTI0_IRQn=true\:14\:0\:true\:false\:true
NVIC.EXTI15_10_IRQn=true\:14\:0\:true\:false\:true
NVIC.EXTI1_IRQn=true\:14\:0\:true\:false\:true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true
NVIC.OTG_FS_IRQn=true\:1\:0\:true\:false\:true
NVIC.OTG_HS_IRQn=true\:14\:0\:true\:false\:true
NVIC.PendSV_IRQn=true\:15\:0\:false\:false\:true
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:true
NVIC.DMA1_Stream2_IRQn=true\:2\:0\:true\:false\:true\:true
NVIC.DMA1_Stream4_IRQn=true\:14\:0\:true\:false\:true\:true
NVIC.DMA1_Stream5_IRQn=true\:14\:0\:true\:false\:true\:true
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:true
NVIC.EXTI0_IRQn=true\:14\:0\:true\:false\:true\:true
NVIC.EXTI15_10_IRQn=true\:14\:0\:true\:false\:true\:true
NVIC.EXTI1_IRQn=true\:14\:0\:true\:false\:true\:true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:true
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:true
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:true
NVIC.OTG_FS_IRQn=true\:1\:0\:true\:false\:true\:true
NVIC.OTG_HS_IRQn=true\:14\:0\:true\:false\:true\:true
NVIC.PendSV_IRQn=true\:15\:0\:false\:false\:true\:true
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true
NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:true
NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:true
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:true
PA0-WKUP.GPIOParameters=GPIO_PuPd
PA0-WKUP.GPIO_PuPd=GPIO_PULLUP
PA0-WKUP.Signal=S_TIM5_CH1
Expand Down Expand Up @@ -271,15 +273,6 @@ PC7.GPIO_PuPd=GPIO_PULLUP
PC7.Signal=S_TIM8_CH2
PC9.Mode=Clock-out-2
PC9.Signal=RCC_MCO_2
PCC.Checker=false
PCC.Line=STM32F407/417
PCC.MCU=STM32F407V(E-G)Tx
PCC.MXVersion=4.19.0
PCC.PartNumber=STM32F407VGTx
PCC.Seq0=0
PCC.Series=STM32F4
PCC.Temperature=25
PCC.Vdd=3.3
PD0.Mode=16b-d1
PD0.Signal=FSMC_D2
PD1.Mode=16b-d1
Expand Down Expand Up @@ -344,12 +337,13 @@ PH0-OSC_IN.Mode=HSE-External-Oscillator
PH0-OSC_IN.Signal=RCC_OSC_IN
PH1-OSC_OUT.Mode=HSE-External-Oscillator
PH1-OSC_OUT.Signal=RCC_OSC_OUT
ProjectManager.AskForMigrate=true
PinOutPanel.RotationAngle=0
ProjectManager.AskForMigrate=false
ProjectManager.BackupPrevious=false
ProjectManager.CompilerOptimize=2
ProjectManager.ComputerToolchain=false
ProjectManager.CoupleFile=true
ProjectManager.CustomerFirmwarePackage=C\:/Tools/stm32fxx/stm32ws/CubeRepo/STM32Cube_FW_F4_V1.14.0
ProjectManager.CustomerFirmwarePackage=
ProjectManager.DefaultFWLocation=true
ProjectManager.DeletePrevious=false
ProjectManager.DeviceId=STM32F407VGTx
Expand All @@ -366,7 +360,7 @@ ProjectManager.ProjectFileName=mcHF.ioc
ProjectManager.ProjectName=mcHF
ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=Other Toolchains (GPDSC)
ProjectManager.ToolChainLocation=C\:\\Tools\\stm32fxx\\stm32ws\\mchf-github\\mchf-eclipse\\basesw\\mcHF
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL,2-MX_DMA_Init-DMA-false-HAL,3-SystemClock_Config-RCC-false-HAL,4-MX_ADC1_Init-ADC1-false-HAL,5-MX_ADC2_Init-ADC2-false-HAL,6-MX_ADC3_Init-ADC3-false-HAL,7-MX_DAC_Init-DAC-false-HAL,8-MX_I2C1_Init-I2C1-false-HAL,9-MX_I2C2_Init-I2C2-false-HAL,10-MX_I2S3_Init-I2S3-false-HAL,11-MX_RTC_Init-RTC-false-HAL,12-MX_SPI2_Init-SPI2-false-HAL,13-MX_TIM3_Init-TIM3-false-HAL,14-MX_TIM5_Init-TIM5-false-HAL,15-MX_TIM8_Init-TIM8-false-HAL,16-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL,17-MX_USB_HOST_Init-USB_HOST-false-HAL,18-MX_FATFS_Init-FATFS-false-HAL,19-MX_FSMC_Init-FSMC-false-HAL,20-MX_TIM4_Init-TIM4-false-HAL
RCC.48MHZClocksFreq_Value=48000000
Expand All @@ -384,28 +378,28 @@ RCC.FamilyName=M
RCC.HCLKFreq_Value=168000000
RCC.HSE_VALUE=16000000
RCC.HSI_VALUE=16000000
RCC.I2SClocksFreq_Value=36857142.85714286
RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLI2SN,PLLI2SR,PLLN,PLLQ,PLLQCLKFreq_Value,RCC_MCO2Source,RCC_MCODiv2,RCC_RTC_Clock_Source,RCC_RTC_Clock_SourceVirtual,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VcooutputI2S
RCC.I2SClocksFreq_Value=61440000
RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLI2SR,PLLM,PLLN,PLLQ,PLLQCLKFreq_Value,RCC_MCO2Source,RCC_MCODiv2,RCC_RTC_Clock_Source,RCC_RTC_Clock_SourceVirtual,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VcooutputI2S
RCC.LSI_VALUE=32000
RCC.MCO2PinFreq_Value=12285714.285714285
RCC.MCO2PinFreq_Value=12288000
RCC.PLLCLKFreq_Value=168000000
RCC.PLLI2SN=258
RCC.PLLI2SR=7
RCC.PLLN=336
RCC.PLLI2SR=5
RCC.PLLM=10
RCC.PLLN=210
RCC.PLLQ=7
RCC.PLLQCLKFreq_Value=48000000
RCC.RCC_MCO2Source=RCC_MCO2SOURCE_PLLI2SCLK
RCC.RCC_MCODiv2=RCC_MCODIV_3
RCC.RCC_MCODiv2=RCC_MCODIV_5
RCC.RCC_RTC_Clock_Source=RCC_RTCCLKSOURCE_LSE
RCC.RCC_RTC_Clock_SourceVirtual=RCC_RTCCLKSOURCE_LSE
RCC.RTCFreq_Value=32768
RCC.RTCHSEDivFreq_Value=8000000
RCC.SYSCLKFreq_VALUE=168000000
RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
RCC.VCOI2SOutputFreq_Value=258000000
RCC.VCOInputFreq_Value=1000000
RCC.VCOI2SOutputFreq_Value=307200000
RCC.VCOInputFreq_Value=1600000
RCC.VCOOutputFreq_Value=336000000
RCC.VcooutputI2S=36857142.85714286
RCC.VcooutputI2S=61440000
SH.ADCx_IN2.0=ADC3_IN2,IN2
SH.ADCx_IN2.ConfNb=1
SH.ADCx_IN3.0=ADC2_IN3,IN3
Expand Down Expand Up @@ -440,8 +434,10 @@ SPI2.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_4
SPI2.CLKPhase=SPI_PHASE_2EDGE
SPI2.CLKPolarity=SPI_POLARITY_HIGH
SPI2.CalculateBaudRate=10.5 MBits/s
SPI2.IPParameters=Mode,CalculateBaudRate,CLKPolarity,CLKPhase,BaudRatePrescaler
SPI2.Direction=SPI_DIRECTION_2LINES
SPI2.IPParameters=Mode,CalculateBaudRate,CLKPolarity,CLKPhase,BaudRatePrescaler,VirtualType,Direction
SPI2.Mode=SPI_MODE_MASTER
SPI2.VirtualType=VM_MASTER
TIM3.EncoderMode=TIM_ENCODERMODE_TI12
TIM3.IC1Polarity=TIM_ICPOLARITY_FALLING
TIM3.IC2Polarity=TIM_ICPOLARITY_FALLING
Expand All @@ -463,11 +459,12 @@ TIM8.IC2Polarity=TIM_ICPOLARITY_FALLING
TIM8.IPParameters=Period,EncoderMode,IC1Polarity,IC2Polarity
TIM8.Period=4103
USB_DEVICE.CLASS_NAME_FS=AUDIO
USB_DEVICE.IPParameters=CLASS_NAME_FS,USBD_AUDIO_FREQ-AUDIO_FS,SERIALNUMBER_STRING_AUDIO_FS,PID_AUDIO_FS,USBD_MAX_NUM_INTERFACES-AUDIO_FS
USB_DEVICE.IPParameters=CLASS_NAME_FS,USBD_AUDIO_FREQ-AUDIO_FS,SERIALNUMBER_STRING_AUDIO_FS,PID_AUDIO_FS,USBD_MAX_NUM_INTERFACES-AUDIO_FS,VirtualModeFS
USB_DEVICE.PID_AUDIO_FS=0x7740
USB_DEVICE.SERIALNUMBER_STRING_AUDIO_FS=00000000002A
USB_DEVICE.USBD_AUDIO_FREQ-AUDIO_FS=48000
USB_DEVICE.USBD_MAX_NUM_INTERFACES-AUDIO_FS=5
USB_DEVICE.VirtualModeFS=Audio_FS
USB_HOST.IPParameters=VirtualModeHS,USBH_HandleTypeDef-ALL_Classes_HS
USB_HOST.USBH_HandleTypeDef-ALL_Classes_HS=hUsbHostHS
USB_HOST.VirtualModeHS=All_Classes
Expand Down

0 comments on commit e16f92d

Please sign in to comment.