/******************************************************************************* * Function Name : UserToPMABufferCopy * Description : Copy data from the user memory area to PMA (data packet memory area) * Input : pbUsrBuf: points to the user's memory area * wPMABufAddr: the address of wPMABufAddr to be copied to PMA * wNBytes: the length of the data to be copied (unit: word) * Output : None. * Return : None . *******************************************************************************/ void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) { uint32_t n = (wNBytes + 1) >> 1; //n = (wNBytes + 1) / 2, indicating how many words uint32_t i, temp1, temp2; uint16_t *pdwVal; pdwVal = (uint16_t *)(wPMABufAddr * 2 + PMAAddr); //pdwVal stores the address where the data is to be stored for (i = n; i != 0; i--) //Start testing the data { temp1 = (uint16_t) * pbUsrBuf; pbUsrBuf++; temp2 = temp1 | (uint16_t) * pbUsrBuf << 8; //Integrate 2 16-bit data *pdwVal++ = temp2; //Copy the integrated data to PMA pdwVal++; //The destination pointer points to the next address pbUsrBuf++; //The source pointer points to the next address } } /******************************************************************************* * Function Name : PMAToUserBufferCopy * Description : Copy a buffer from user memory area to packet memory area (PMA) * Input : pbUsrBuf points to the user's memory area * wPMABufAddr PAM address * wNBytes number of bytes to be copied * Output : None. * Return : None. ******************************************************************************/ void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) { uint32_t n = (wNBytes + 1) >> 1; //n = (wNBytes + 1) / 2, indicating how many words uint32_t i; uint32_t *pdwVal; pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr); //Read 1 word of data from the PAM area for (i = n; i != 0; i--) { *(uint16_t*)pbUsrBuf++ = *pdwVal++; //Copy the user's memory area pbUsrBuf++; } }
/*******************************************************************************
* Function Name : USB_SIL_Init
* Description : Initialize USB device IP and endpoints
* Input : None.
* Output : None.
* Return : Status.
*******************************************************************************/
uint32_t USB_SIL_Init(void)
{
#ifndef STM32F10X_CL
/* USB interrupts initialization */
/* clear pending interrupts */
_SetISTR(0); //Disable all interrupts
wInterrupt_Mask = IMR_MSK;
/* set interrupts mask */
_SetCNTR(wInterrupt_Mask); //Enable some interrupts
#else
/* Perform OTG Device initialization procedure (including EP0 init) */
OTG_DEV_Init(); //Execute initialization procedure OTG device (including EP0 initialization)
#endif /* STM32F10X_CL */
return 0;
}
/*******************************************************************************
* Function Name : USB_SIL_Write
* Description : Write data to the selected endpoint
* Input : bEpAddr: address of non-control endpoint
* pBufferPointer: points to the buffer data to be written to the endpoint
* wBufferSize: length of data to be written (unit: byte)
* Output : None.
* Return : Status.
*******************************************************************************/
uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize)
{
#ifndef STM32F10X_CL
UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize); //Copy user data to PMA
SetEPTxCount((bEpAddr & 0x7F), wBufferSize); //Update the control register of data length
#else
PCD_EP_Write (bEpAddr, pBufferPointer, wBufferSize); //Use the PCD interface layer function to write to the selected endpoint
#endif /* STM32F10X_CL */
return 0;
}
/*******************************************************************************
* Function Name : USB_SIL_Read
* Description : Read data from the selected endpoint
* Input : bEpAddr: address of non-control endpoint
* pBufferPointer: point to the address of the data area to be saved
* Output : None.
* Return : Return the length of the read data (unit: byte)
*******************************************************************************/
uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer)
{
uint32_t DataLength = 0;
#ifndef STM32F10X_CL
DataLength = GetEPRxCount(bEpAddr & 0x7F); //Get the received data length from the selected endpointPMAToUserBufferCopy
(pBufferPointer, GetEPRxAddr(bEpAddr & 0x7F), DataLength); //Copy data from PMA to user area
#else
USB_OTG_EP *ep;
ep = PCD_GetOutEP(bEpAddr); //Get the structure pointer of the selected endpointDataLength
= ep->xfer_len; //Get the received data lengthPCD_EP_Read
(bEpAddr, pBufferPointer, DataLength); //Use PCD interface layer function to read the selected port
#endif /* STM32F10X_CL */
return DataLength; //Return the received data length
}
Previous article:STM32 interrupt priority understanding and preemptive priority and slave priority
Next article:Production of STM32 upgrade files
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- [MM32 eMiniBoard Review] Part 7: IIC Read and Write EEPROM
- Altium Designer's dirty tricks to combat piracy
- TMS320F2812 generates PWM waveform process
- TI Power Stage Designer Tool Introduction Documentation
- I would like to ask you, the STM32CUBEMX+SPI+DMA method always sends incorrectly. My chip is STM32F103RC
- Keysight Technology Award-winning Live Broadcast | Thanksgiving Month Opening Ceremony - Oscilloscope Lecture Hall Registration Starts~
- LLC resonance start-up conditions
- GPIO configuration and usage process of CC1310SimpleLink SDK under CCS8
- "Basics of Power Supply Design" - a reference book worth putting on your workbench
- TMP61 ±1% 10kΩ Linear Thermistor