cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407G RTC & SD Card(SPI) Not working simultaneously

DParm.1
Associate II

Hello,

I am developing a board based on STM32F407G (Disc1) Where I am connecting an SD-Card over the SPI to store some data in the file on SD card. I am configuring internal RTC for the time tracking, On internal clock, a 16x2 LCD connected via 4-bit mode and some push buttons.

The problem I am facing is, When the Code do file operation on SD card(i.e writing data in file) the RTC time becomes 0. If board powered-up without the SD-card on it, It just works fine. For debugging I tried to do SD-Card activity after some time of booting(i.e. 30 Sec), So during the first 30 sec the RTC date-time showing fine, as the SD-Card operation started after 30 sec, RTC time-date became 0.

CubeMx configuration of the project is as below;

USART2(PD5, PD6)- asynchronous mode UART

SPI1(PB3-Clk, PB4-Miso, PB5-Mosi, PA15-GPIO_Out for CS)

PC0 to PC7-GPIO Output for LCD

PE0 to PE5-GPIO Input for Push-buttons

FATFS-User defined

RTC-Internal clock

TIM1-Micro second delay

For SD-Card configuration I followed: https://controllerstech.com/sd-card-using-spi-in-stm32/#:~:text=In%20this%20tutorial%20we%20will,writing%2C%20reading%2C%20deleting%20etc.

RTC: https://controllerstech.com/internal-rtc-in-stm32/

Can anyone please help me to understand what I missed here and resolve the issue? Also Let me know if anymore information required.

Thanks,

4 REPLIES 4
Mouadh JERIDI
Associate III

Hello @DParm.1​ , can you please provide me with the IOC file to perform some analyzes ?

Hi, Thank you for responding to this Mouadh JERIDI.
Here I am attaching the ioc file.
Thanks,
Dixit

#MicroXplorer Configuration settings - do not modify

Mcu.Family=STM32F4

ProjectManager.MainLocation=Core/Src

FATFS._USE_FORWARD=1

PC7.GPIOParameters=GPIO_Label

USART2.IPParameters=VirtualMode

RCC.CortexFreq_Value=25000000

ProjectManager.KeepUserCode=true

Mcu.UserName=STM32F407VGTx

SPI1.VirtualType=VM_MASTER

TIM1.IPParameters=Prescaler

USART1.BaudRate=9600

RCC.PLLCLKFreq_Value=25000000

RCC.PLLQCLKFreq_Value=14285714.285714285

PC5.Locked=true

PC7.Locked=true

ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_RTC_Init-RTC-false-HAL-true,4-MX_TIM1_Init-TIM1-false-HAL-true,5-MX_USART2_UART_Init-USART2-false-HAL-true,6-MX_SPI1_Init-SPI1-false-HAL-true,7-MX_FATFS_Init-FATFS-false-HAL-false,8-MX_USART1_UART_Init-USART1-false-HAL-true

PC0.GPIOParameters=GPIO_Label

PC0.GPIO_Label=RS

PC6.GPIO_Label=D6

VP_RTC_VS_RTC_Activate.Mode=RTC_Enabled

RTC.WeekDay=RTC_WEEKDAY_THURSDAY

RCC.RTCFreq_Value=32000

PD6.Locked=true

VP_RTC_VS_RTC_Calendar.Signal=RTC_VS_RTC_Calendar

USART1.IPParameters=VirtualMode,BaudRate

PC1.Locked=true

PinOutPanel.RotationAngle=0

RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK

ProjectManager.StackSize=0x400

Mcu.IP4=SPI1

RCC.FCLKCortexFreq_Value=25000000

Mcu.IP5=SYS

NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:true\:false

Mcu.IP2=RCC

Mcu.IP3=RTC

Mcu.IP0=FATFS

Mcu.IP1=NVIC

TIM1.Prescaler=25-1

Mcu.UserConstants=

PC1.GPIOParameters=GPIO_Label

Mcu.ThirdPartyNb=0

SPI1.Direction=SPI_DIRECTION_2LINES

RCC.HCLKFreq_Value=25000000

Mcu.IPNb=9

RCC.I2SClocksFreq_Value=192000000

ProjectManager.PreviousToolchain=SW4STM32

RCC.APB2TimFreq_Value=25000000

PB6.Signal=USART1_TX

RCC.VcooutputI2S=192000000

PC7.Signal=GPIO_Output

PB6.Mode=Asynchronous

RTC.IPParameters=Hours,Minutes,WeekDay,Month,Date,Format

SPI1.CalculateBaudRate=48.828 KBits/s

Mcu.Pin6=PC2

Mcu.Pin7=PC4

Mcu.Pin8=PC5

PE5.Signal=GPIO_Input

Mcu.Pin9=PC6

PE1.Signal=GPIO_Input

RCC.AHBFreq_Value=25000000

Mcu.Pin0=PE2

PD5.Mode=Asynchronous

Mcu.Pin1=PE3

Mcu.Pin2=PE4

Mcu.Pin3=PE5

Mcu.Pin4=PC0

Mcu.Pin5=PC1

ProjectManager.ProjectBuild=false

RCC.HSE_VALUE=8000000

RTC.Minutes=59

NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false

NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:true\:false

PB3.Mode=Full_Duplex_Master

NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:true\:true

ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.25.2

MxDb.Version=DB.6.0.0

RTC.Month=RTC_MONTH_DECEMBER

PB4.Mode=Full_Duplex_Master

ProjectManager.BackupPrevious=false

RCC.VCOInputFreq_Value=2000000

PC4.GPIO_Label=D4

PB5.Mode=Full_Duplex_Master

File.Version=6

PE3.Locked=true

PE2.Signal=GPIO_Input

PB7.Signal=USART1_RX

PE1.Locked=true

PB6.Locked=true

NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:true\:false

PE4.Signal=GPIO_Input

ProjectManager.HalAssertFull=false

VP_TIM1_VS_ClockSourceINT.Mode=Internal

ProjectManager.ProjectName=F4_UART

FATFS._USE_LABEL=1

RCC.MCO2PinFreq_Value=25000000

Mcu.Package=LQFP100

VP_FATFS_VS_Generic.Signal=FATFS_VS_Generic

USART2.VirtualMode=VM_ASYNC

ProjectManager.ToolChainLocation=

RCC.LSI_VALUE=32000

VP_SYS_VS_Systick.Signal=SYS_VS_Systick

VP_RTC_VS_RTC_Calendar.Mode=RTC_Calendar

PA15.Signal=GPIO_Output

RCC.APB2CLKDivider=RCC_HCLK_DIV2

RCC.APB1TimFreq_Value=12500000

NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false

PC4.Locked=true

PC5.Signal=GPIO_Output

PD6.Signal=USART2_RX

SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_256

PD5.Locked=true

PC2.GPIO_Label=EN

ProjectManager.CustomerFirmwarePackage=

PC4.GPIOParameters=GPIO_Label

PB3.Locked=true

PB4.Signal=SPI1_MISO

VP_RTC_VS_RTC_Activate.Signal=RTC_VS_RTC_Activate

ProjectManager.ProjectFileName=F4_UART.ioc

Mcu.PinsNb=26

ProjectManager.NoMain=false

SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler

PC4.Signal=GPIO_Output

PC2.Signal=GPIO_Output

PC6.Signal=GPIO_Output

ProjectManager.DefaultFWLocation=true

PD5.Signal=USART2_TX

ProjectManager.DeletePrevious=true

PC0.Signal=GPIO_Output

RCC.APB1CLKDivider=RCC_HCLK_DIV4

boardIOC=true

PD6.Mode=Asynchronous

RCC.FamilyName=M

FATFS.IPParameters=_USE_CHMOD,_USE_LABEL,_USE_FORWARD

PA15.Locked=true

ProjectManager.TargetToolchain=SW4STM32

PC6.Locked=true

PC5.GPIOParameters=GPIO_Label

VP_TIM1_VS_ClockSourceINT.Signal=TIM1_VS_ClockSourceINT

PE4.Locked=true

PB5.Locked=true

RTC.Format=RTC_FORMAT_BIN

PC2.Locked=true

ProjectManager.RegisterCallBack=

PE0.Locked=true

RCC.LSE_VALUE=32768

VP_FATFS_VS_Generic.Mode=User_defined

RCC.VCOI2SOutputFreq_Value=384000000

board=STM32F407G-DISC1

RCC.VCOOutputFreq_Value=100000000

ProjectManager.LastFirmware=true

RCC.APB2Freq_Value=12500000

MxCube.Version=6.0.1

SPI1.Mode=SPI_MODE_MASTER

PC2.GPIOParameters=GPIO_Label

PC1.GPIO_Label=RW

VP_SYS_VS_Systick.Mode=SysTick

RCC.EthernetFreq_Value=25000000

NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:true\:false

PE5.Locked=true

ProjectManager.FreePins=false

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,LSE_VALUE,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLM,PLLN,PLLP,PLLQ,PLLQCLKFreq_Value,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VcooutputI2S

ProjectManager.AskForMigrate=true

Mcu.Name=STM32F407V(E-G)Tx

PE0.Signal=GPIO_Input

RCC.RTCHSEDivFreq_Value=4000000

Mcu.Pin24=VP_SYS_VS_Systick

ProjectManager.UnderRoot=true

Mcu.Pin25=VP_TIM1_VS_ClockSourceINT

Mcu.IP8=USART2

FATFS._USE_CHMOD=1

PC7.GPIO_Label=D7

Mcu.IP6=TIM1

Mcu.IP7=USART1

ProjectManager.CoupleFile=false

RCC.48MHZClocksFreq_Value=14285714.285714285

PB4.Locked=true

PB3.Signal=SPI1_SCK

RCC.SYSCLKFreq_VALUE=25000000

RTC.Hours=23

PB5.Signal=SPI1_MOSI

Mcu.Pin22=VP_RTC_VS_RTC_Activate

Mcu.Pin23=VP_RTC_VS_RTC_Calendar

Mcu.Pin20=PE1

Mcu.Pin21=VP_FATFS_VS_Generic

NVIC.ForceEnableDMAVector=true

KeepUserPlacement=false

PC5.GPIO_Label=D5

NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:true\:false

USART1.VirtualMode=VM_ASYNC

ProjectManager.CompilerOptimize=6

PB7.Mode=Asynchronous

ProjectManager.HeapSize=0x200

Mcu.Pin15=PB4

NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false

Mcu.Pin16=PB5

Mcu.Pin13=PD6

PC6.GPIOParameters=GPIO_Label

Mcu.Pin14=PB3

Mcu.Pin19=PE0

ProjectManager.ComputerToolchain=false

Mcu.Pin17=PB6

RCC.HSI_VALUE=16000000

Mcu.Pin18=PB7

RCC.PLLP=RCC_PLLP_DIV4

RCC.PLLQ=7

NVIC.PriorityGroup=NVIC_PRIORITYGROUP_0

Mcu.Pin11=PA15

Mcu.Pin12=PD5

RCC.PLLM=8

RCC.PLLN=50

Mcu.Pin10=PC7

PB7.Locked=true

PE2.Locked=true

PE3.Signal=GPIO_Input

RCC.APB1Freq_Value=6250000

RTC.Date=31

PC0.Locked=true

ProjectManager.DeviceId=STM32F407VGTx

PC1.Signal=GPIO_Output

ProjectManager.LibraryCopy=1

Read out and check/compare RTC and RCC_BDCR registers content between "working" and "non-working" case.

JW