Simple USBHost library for STM32F746NG Discovery board. Only either the Fastspeed or the Highspeed port can be used( not both together)
Dependents: DISCO-F746NG_USB_Host
Fork of KL46Z-USBHost by
USBHost/USB_Helper.c@24:5396b6a93262, 2016-06-13 (annotated)
- Committer:
- DieterGraef
- Date:
- Mon Jun 13 17:21:07 2016 +0000
- Revision:
- 24:5396b6a93262
USB Host for STM32F746 DISCO Board. At the moment you can only use either the High Speed Port or the Fast Speed Port.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DieterGraef | 24:5396b6a93262 | 1 | #include "USB_Helper.h" |
DieterGraef | 24:5396b6a93262 | 2 | |
DieterGraef | 24:5396b6a93262 | 3 | /* cache flush */ |
DieterGraef | 24:5396b6a93262 | 4 | void CPU_CACHE_Flush(uint32_t * buffer, uint32_t length) |
DieterGraef | 24:5396b6a93262 | 5 | { |
DieterGraef | 24:5396b6a93262 | 6 | // SCB_InvalidateDCache_by_Addr(buffer,length); |
DieterGraef | 24:5396b6a93262 | 7 | uint32_t ccsidr; |
DieterGraef | 24:5396b6a93262 | 8 | uint32_t smask; |
DieterGraef | 24:5396b6a93262 | 9 | uint32_t sshift; |
DieterGraef | 24:5396b6a93262 | 10 | uint32_t ways; |
DieterGraef | 24:5396b6a93262 | 11 | uint32_t wshift; |
DieterGraef | 24:5396b6a93262 | 12 | uint32_t ssize; |
DieterGraef | 24:5396b6a93262 | 13 | uint32_t sets; |
DieterGraef | 24:5396b6a93262 | 14 | uint32_t sw; |
DieterGraef | 24:5396b6a93262 | 15 | uint32_t start; |
DieterGraef | 24:5396b6a93262 | 16 | uint32_t ende; |
DieterGraef | 24:5396b6a93262 | 17 | |
DieterGraef | 24:5396b6a93262 | 18 | start=(uint32_t)buffer; |
DieterGraef | 24:5396b6a93262 | 19 | ende=start+length; |
DieterGraef | 24:5396b6a93262 | 20 | /* Get the characteristics of the D-Cache */ |
DieterGraef | 24:5396b6a93262 | 21 | |
DieterGraef | 24:5396b6a93262 | 22 | ccsidr = SCB->CCSIDR; |
DieterGraef | 24:5396b6a93262 | 23 | smask = CCSIDR_SETS(ccsidr); /* (Number of sets) - 1 */ |
DieterGraef | 24:5396b6a93262 | 24 | sshift = CCSIDR_LSSHIFT(ccsidr) + 4; /* log2(cache-line-size-in-bytes) */ |
DieterGraef | 24:5396b6a93262 | 25 | ways = CCSIDR_WAYS(ccsidr); /* (Number of ways) - 1 */ |
DieterGraef | 24:5396b6a93262 | 26 | |
DieterGraef | 24:5396b6a93262 | 27 | /* Calculate the bit offset for the way field in the DCCISW register by |
DieterGraef | 24:5396b6a93262 | 28 | * counting the number of leading zeroes. For example: |
DieterGraef | 24:5396b6a93262 | 29 | * |
DieterGraef | 24:5396b6a93262 | 30 | * Number of Value of ways Field |
DieterGraef | 24:5396b6a93262 | 31 | * Ways 'ways' Offset |
DieterGraef | 24:5396b6a93262 | 32 | * 2 1 31 |
DieterGraef | 24:5396b6a93262 | 33 | * 4 3 30 |
DieterGraef | 24:5396b6a93262 | 34 | * 8 7 29 |
DieterGraef | 24:5396b6a93262 | 35 | * ... |
DieterGraef | 24:5396b6a93262 | 36 | */ |
DieterGraef | 24:5396b6a93262 | 37 | |
DieterGraef | 24:5396b6a93262 | 38 | wshift = __CLZ(ways) & 0x1f; |
DieterGraef | 24:5396b6a93262 | 39 | |
DieterGraef | 24:5396b6a93262 | 40 | /* Clean and invalidate the D-Cache over the range of addresses */ |
DieterGraef | 24:5396b6a93262 | 41 | |
DieterGraef | 24:5396b6a93262 | 42 | ssize = (1 << sshift); |
DieterGraef | 24:5396b6a93262 | 43 | start &= ~(ssize - 1); |
DieterGraef | 24:5396b6a93262 | 44 | __DSB(); |
DieterGraef | 24:5396b6a93262 | 45 | |
DieterGraef | 24:5396b6a93262 | 46 | do |
DieterGraef | 24:5396b6a93262 | 47 | { |
DieterGraef | 24:5396b6a93262 | 48 | int32_t tmpways = ways; |
DieterGraef | 24:5396b6a93262 | 49 | |
DieterGraef | 24:5396b6a93262 | 50 | /* Isolate the cache line associated with this address. For example |
DieterGraef | 24:5396b6a93262 | 51 | * if the cache line size is 32 bytes and the cache size is 16KB, then |
DieterGraef | 24:5396b6a93262 | 52 | * |
DieterGraef | 24:5396b6a93262 | 53 | * sshift = 5 : Offset to the beginning of the set field |
DieterGraef | 24:5396b6a93262 | 54 | * smask = 0x007f : Mask of the set field |
DieterGraef | 24:5396b6a93262 | 55 | */ |
DieterGraef | 24:5396b6a93262 | 56 | |
DieterGraef | 24:5396b6a93262 | 57 | sets = ((uint32_t)start >> sshift) & smask; |
DieterGraef | 24:5396b6a93262 | 58 | |
DieterGraef | 24:5396b6a93262 | 59 | /* Clean and invalidate each way for this cacheline */ |
DieterGraef | 24:5396b6a93262 | 60 | |
DieterGraef | 24:5396b6a93262 | 61 | do |
DieterGraef | 24:5396b6a93262 | 62 | { |
DieterGraef | 24:5396b6a93262 | 63 | sw = ((tmpways << wshift) | (sets << sshift)); |
DieterGraef | 24:5396b6a93262 | 64 | SCB->DCCISW=sw; |
DieterGraef | 24:5396b6a93262 | 65 | |
DieterGraef | 24:5396b6a93262 | 66 | } |
DieterGraef | 24:5396b6a93262 | 67 | while (tmpways--); |
DieterGraef | 24:5396b6a93262 | 68 | |
DieterGraef | 24:5396b6a93262 | 69 | /* Increment the address by the size of one cache line. */ |
DieterGraef | 24:5396b6a93262 | 70 | |
DieterGraef | 24:5396b6a93262 | 71 | start += ssize; |
DieterGraef | 24:5396b6a93262 | 72 | } |
DieterGraef | 24:5396b6a93262 | 73 | while (start < ende); |
DieterGraef | 24:5396b6a93262 | 74 | |
DieterGraef | 24:5396b6a93262 | 75 | __DSB(); |
DieterGraef | 24:5396b6a93262 | 76 | __ISB(); |
DieterGraef | 24:5396b6a93262 | 77 | } |