Add USB CDC and loop-back test
This commit is contained in:
commit
7234eb8360
34 changed files with 15808 additions and 0 deletions
38
stm32f103c8t6/src/usb_util.c
Normal file
38
stm32f103c8t6/src/usb_util.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include "usb_util.h"
|
||||
|
||||
void USB_PMAToMemory(void *mem, uint16_t offset, size_t length)
|
||||
{
|
||||
uint8_t *dst = (uint8_t*)mem;
|
||||
uint8_t *pma = (uint8_t*)(USB_PMA_ADDR + 2 * offset);
|
||||
|
||||
for(unsigned int i = 0; i < length; i++)
|
||||
{
|
||||
*dst++ = *pma++;
|
||||
if(i & 1)
|
||||
{
|
||||
pma += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void USB_MemoryToPMA(uint16_t offset, const void *mem, size_t length)
|
||||
{
|
||||
// Only words can be copied. Thus, if the length is not even, it has to be
|
||||
// incremented to ensure that the last byte is copied. Since the PMA buffer
|
||||
// always has even size, this is not a problem.
|
||||
if(length & 1)
|
||||
{
|
||||
length++;
|
||||
}
|
||||
|
||||
const uint8_t *src = (const uint8_t*)mem;
|
||||
|
||||
uint16_t *pma = (uint16_t*)(USB_PMA_ADDR + 2 * offset);
|
||||
for(unsigned int i = 0; i < length / 2; i++)
|
||||
{
|
||||
uint16_t tmp = src[2 * i] | (src[2 * i + 1] << 8);
|
||||
*pma++ = tmp;
|
||||
pma++;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue