2 ******************************************************************************
4 * @author MCD Application Team
7 * @brief Specific media access Layer for OTP (One Time Programming) memory.
8 ******************************************************************************
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
22 /* Includes ------------------------------------------------------------------*/
23 #include "usbd_otp_if.h"
24 #include "usbd_dfu_mal.h"
26 /* Private typedef -----------------------------------------------------------*/
27 /* Private define ------------------------------------------------------------*/
28 /* Private macro -------------------------------------------------------------*/
30 /* Private function prototypes -----------------------------------------------*/
31 uint16_t OTP_If_Write (uint32_t Add, uint32_t Len);
32 uint8_t *OTP_If_Read (uint32_t Add, uint32_t Len);
33 uint16_t OTP_If_DeInit(void);
34 uint16_t OTP_If_CheckAdd(uint32_t Add);
37 /* Private variables ---------------------------------------------------------*/
38 DFU_MAL_Prop_TypeDef DFU_Otp_cb =
41 NULL, /* Init not supported*/
42 NULL, /* DeInit not supported */
43 NULL, /* Erase not supported */
47 1, /* Erase Time in ms */
48 10 /* Programming Time in ms */
51 /* Private functions ---------------------------------------------------------*/
55 * Memory write routine.
56 * @param Add: Address to be written to.
57 * @param Len: Number of data to be written (in bytes).
58 * @retval MAL_OK if operation is successeful, MAL_FAIL else.
60 uint16_t OTP_If_Write(uint32_t Add, uint32_t Len)
64 if (Len & 0x3) /* Not an aligned data */
66 for (idx = Len; idx < ((Len & 0xFFFC) + 4); idx++)
68 MAL_Buffer[idx] = 0xFF;
72 /* Data received are Word multiple */
73 for (idx = 0; idx < Len; idx = idx + 4)
75 FLASH_ProgramWord(Add, *(uint32_t *)(MAL_Buffer + idx));
83 * Memory read routine.
84 * @param Add: Address to be read from.
85 * @param Len: Number of data to be read (in bytes).
86 * @retval Pointer to the phyisical address where data should be read.
88 uint8_t *OTP_If_Read (uint32_t Add, uint32_t Len)
90 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
92 for (idx = 0; idx < Len; idx += 4)
94 *(uint32_t*)(MAL_Buffer + idx) = *(uint32_t *)(Add + idx);
96 return (uint8_t*)(MAL_Buffer);
98 return (uint8_t*)(Add);
99 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
103 * @brief OTP_If_CheckAdd
104 * Check if the address is an allowed address for this memory.
105 * @param Add: Address to be checked.
106 * @param Len: Number of data to be read (in bytes).
107 * @retval MAL_OK if the address is allowed, MAL_FAIL else.
109 uint16_t OTP_If_CheckAdd(uint32_t Add)
111 if ((Add >= OTP_START_ADD) && (Add < OTP_END_ADD))
120 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/