usbd_otp_if.c
Go to the documentation of this file.
1 
28 /* Includes ------------------------------------------------------------------*/
29 #include "usbd_otp_if.h"
30 #include "usbd_dfu_mal.h"
31 
32 /* Private typedef -----------------------------------------------------------*/
33 /* Private define ------------------------------------------------------------*/
34 /* Private macro -------------------------------------------------------------*/
35 
36 /* Private function prototypes -----------------------------------------------*/
37 uint16_t OTP_If_Write (uint32_t Add, uint32_t Len);
38 uint8_t *OTP_If_Read (uint32_t Add, uint32_t Len);
39 uint16_t OTP_If_DeInit(void);
40 uint16_t OTP_If_CheckAdd(uint32_t Add);
41 
42 
43 /* Private variables ---------------------------------------------------------*/
45  {
47  NULL, /* Init not supported*/
48  NULL, /* DeInit not supported */
49  NULL, /* Erase not supported */
53  1, /* Erase Time in ms */
54  10 /* Programming Time in ms */
55  };
56 
57 /* Private functions ---------------------------------------------------------*/
58 
66 uint16_t OTP_If_Write(uint32_t Add, uint32_t Len)
67 {
68  uint32_t idx = 0;
69 
70  if (Len & 0x3) /* Not an aligned data */
71  {
72  for (idx = Len; idx < ((Len & 0xFFFC) + 4); idx++)
73  {
74  MAL_Buffer[idx] = 0xFF;
75  }
76  }
77 
78  /* Data received are Word multiple */
79  for (idx = 0; idx < Len; idx = idx + 4)
80  {
81  FLASH_ProgramWord(Add, *(uint32_t *)(MAL_Buffer + idx));
82  Add += 4;
83  }
84  return MAL_OK;
85 }
86 
94 uint8_t *OTP_If_Read (uint32_t Add, uint32_t Len)
95 {
96 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
97  uint32_t idx = 0;
98  for (idx = 0; idx < Len; idx += 4)
99  {
100  *(uint32_t*)(MAL_Buffer + idx) = *(uint32_t *)(Add + idx);
101  }
102  return (uint8_t*)(MAL_Buffer);
103 #else
104  return (uint8_t*)(Add);
105 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
106 }
107 
115 uint16_t OTP_If_CheckAdd(uint32_t Add)
116 {
117  if ((Add >= OTP_START_ADD) && (Add < OTP_END_ADD))
118  {
119  return MAL_OK;
120  }
121  else
122  {
123  return MAL_FAIL;
124  }
125 }
126 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
uint8_t * OTP_If_Read(uint32_t Add, uint32_t Len)
OTP_If_Read Memory read routine.
Definition: usbd_otp_if.c:94
#define OTP_IF_STRING
Definition: usbd_otp_if.h:40
uint8_t MAL_Buffer[XFERSIZE]
Definition: usbd_dfu_mal.c:83
uint16_t OTP_If_CheckAdd(uint32_t Add)
OTP_If_CheckAdd Check if the address is an allowed address for this memory.
Definition: usbd_otp_if.c:115
DFU_MAL_Prop_TypeDef DFU_Otp_cb
Definition: usbd_otp_if.c:44
Header for usbd_otp_if.c file.
Header for usbd_dfu_mal.c file.
#define MAL_OK
Definition: usbd_dfu_mal.h:55
uint16_t OTP_If_Write(uint32_t Add, uint32_t Len)
OTP_If_Write Memory write routine.
Definition: usbd_otp_if.c:66
#define NULL
Definition: usbd_def.h:50
uint16_t OTP_If_DeInit(void)
FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data)
Programs a word at a specified address.
#define OTP_START_ADD
Definition: usbd_otp_if.h:37
#define OTP_END_ADD
Definition: usbd_otp_if.h:38
#define MAL_FAIL
Definition: usbd_dfu_mal.h:56


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Oct 24 2019 03:17:20