Skip to main content
jakub
Associate
November 25, 2014
Question

stm32F4 BACKUP SRAM and USB HID conflict

  • November 25, 2014
  • 13 replies
  • 2590 views
Posted on November 25, 2014 at 15:37

Hi, usb hid works form me great on discovery f4 but I have a problem with saving to backup sram and backup rtc after USB initialization. I would like to create a program, which is waiting for character from the USB then enters information into backup sram or

backup 

rtc. Put data into backup memory works without USB initialization. But when I want to write something to it after the USB initialization compiler does not detect an error in the program but the memory content does not change, no entry into the memory. Initialization looks like this:

   USBD_Init (& USB_OTG_dev,

   USB_OTG_FS_CORE_ID,

   & USR_desc,

   & USBD_HID_cb,

   & USR_cb);

Any ideas? I have tried many of variance startup but nothing is working. I did off usb global init, stop device, disconnect device... nothing seems to be working.

Every new idea will be helpful!

Regards. 

Amidns

#backup #usb-sram-stm32f2-backup #usb-hid #stm32f4
This topic has been closed for replies.

13 replies

Tesla DeLorean
Guru
November 25, 2014
Posted on November 25, 2014 at 17:51

Wouldn't the code fiddling with the RAM be more pertinent to the problem? Are the clocks to the backup/power domain enabled, and have you unlocked access to it?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
jakub
jakubAuthor
Associate
November 26, 2014
Posted on November 26, 2014 at 08:15

My function  write_to_backup_sram:

int8_t write_to_backup_sram( uint8_t *data, uint16_t bytes, uint16_t offset )

{

 uint8_t* base_addr = (uint8_t *) BKPSRAM_BASE;

  uint16_t i;

 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE);

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);  

  PWR_BackupAccessCmd(ENABLE);               

  PWR_BackupRegulatorCmd(ENABLE);   

  for( i = 0; i < bytes; i++ ) { 

    *(base_addr + offset + i) = *(data + i);  //TEST VALUES

  }

  PWR_BackupAccessCmd(DISABLE);                  

  return 0;

}

   Something is missing? But it works without USB init.

tim239955_stm1_stmicro_com
Associate II
March 17, 2016
Posted on March 17, 2016 at 12:05

Did anyone ever find an answer to this? 

I have exactly the same problem with an STM32F205VE. I can read and write from the battery backed up SRAM just fine until I implement USB VCP. As soon as the USB stack is initialised, the backup SRAM seems to become read only! I can find no mention of this 'feature' in any datasheet.

The processor does not throw a fault if you try to write to to the backup SRAM, it just doesn't update the RAM. It is also no longer possible to update the backup SRAM via JTAG once the USB has been initialised. again, there is no error, it just does not change the values. I have tried every possible Google search that I can think of to find a solution to this problem and this post is the only thing I have found!

Can anyone throw any light on this problem?

Regards

Tim 

Tesla DeLorean
Guru
March 17, 2016
Posted on March 17, 2016 at 16:05

Did anyone ever find an answer to this?

Hard to say, there have been a number of issues with USB_Init() stomping on things, in different threads. Might want to Google a bit more generally.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
jay1991
Associate II
May 24, 2016
Posted on May 24, 2016 at 08:38

How you read this data?

Tesla DeLorean
Guru
May 24, 2016
Posted on May 24, 2016 at 15:11

How you read this data?

The same way you read all the other memory. You could use a pointer, a structure pointer, or via sections and linker scripts or scatter files.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
jay1991
Associate II
May 25, 2016
Posted on May 25, 2016 at 07:15

thank you clive1.

BillThePlatypus
Associate
January 14, 2019

Has anyone found a solution to this? I am running into the same problem, and nothing I can find in the documentation indicates why.

waclawek.jan
Super User
January 14, 2019

Try to be more specific.

JW

BillThePlatypus
Associate
January 15, 2019

To the original problem, that initalizing USB prevents writing to backup SRAM.

BillThePlatypus
Associate
January 21, 2019

OK, I figured it out. For some reason, the standard libraries sets the reset flag for the PWR register, but does not clear the flag afterwards. To solve this, after initializing the USB connection, call:

RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);

Afterwards, you may have to adjust registers in the RCC_APB1Periph_PWR register. I would recommend doing backup SRAM initialization after USB initialization.

As far as I can tell, this doesn't affect any USB functionality, but allows the backup SRAM to work.

waclawek.jan
Super User
January 21, 2019

Thanks for coming back with the answer, but...

For some reason, the standard libraries sets the reset flag for the PWR register, but does not clear the flag afterwards. T

What standard libraries? The SPL-based USB Host and Device, for 'F4? In which file, function?

Thanks,

JW