USB Host, "Blue Pill", die Methode zur Aufteilung des Segments in zwei Hälften und der Preis für Wodka in der UdSSR

Schrieb kürzlich eine Software USB-HOST auf esp32 , um mit Tastatur / Maus / Joystick zu arbeiten. Der Prozessor ist schnell, aber empfindlich, 5 Volt an den Beinen können es nicht aushalten. Aus diesem Grund habe ich beschlossen, es in stm32f103c8t6 umzuschreiben, das in der Version des Debug-Boards "Blue Pill" weithin bekannt ist .





Leider ist dies nach heutigen Maßstäben ein sehr gemächlicher Prozessor (72 MHz gegenüber 240 für esp32), so dass Zweifel bestanden, ob ich die notwendige Genauigkeit des Zeitintervalls zwischen Bits während der Übertragung ( 1,5 Mbit / s +/- 1,5% ) liefern konnte entspricht +/- 0,01 uS, was ungefähr einem Zyklus des Prozessors entspricht. Das heißt, ein Verzögerungsverfahren wie:





static inline  void cpuDelay(uint32_t ticks)
{
	uint32_t stop =_getCycleCount32() + ticks;
	while((_getCycleCount32() - stop)&0x80000000u); // ntinue while overflow
}

      
      



Ich habe aufgehört, die erforderliche Genauigkeit bereitzustellen, und habe mich daher entschlossen, zu einem Verfahren des Formulars überzugehen:





void cpuDelay()
{
__asm__ __volatile__("nop");
__asm__ __volatile__("nop");
__asm__ __volatile__("nop");
__asm__ __volatile__("nop");
}
  
      
      



mit der erforderlichen Anzahl von "nop" - s. Als ich es satt hatte, die Latenz manuell anzupassen und den Code neu zu kompilieren, entschied ich mich, eine Prozedur zu schreiben, die die erforderliche Latenz auswählt und in einem weiten Bereich von Prozessorfrequenzen arbeitet. Die Idee ist wie folgt: Anstatt die Prozedur mit der cpuDelay-Adresse einzugeben, geben Sie die Prozedur in der Mitte am Zeiger ein:





#define TNOP1  { __asm__ __volatile__("   nop"); }
#define TNOP2  {TNOP1 TNOP1}
#define TNOP4  {TNOP2 TNOP2}
#define TNOP8  {TNOP4 TNOP4}
#define TNOP16  {TNOP8 TNOP8}
#define TNOP32  {TNOP16 TNOP16}
#define TNOP64  {TNOP32 TNOP32}

__volatile__ void cpuDelayBase()
{
	TNOP64;
	TNOP64;
	TNOP64;
	TNOP64;
END_BASE:;
}

void (*delay_pntA)() = &cpuDelayBase;

#define cpuDelay(x) {(*delay_pntA)();}

#define SIZEOF_NOP 2

void setDelay(uint8_t ticks)
{
	delay_pntA = (&cpuDelayBase)+((256-ticks)*SIZEOF_NOP);
}

      
      



200,, delay_pntA.





6 4.0uS. 6 . 6 , :





, , 0.12uS 4.12 uS.





!!!???





, , CCCP , , , . , , , , .





. , , 2-87, - 3-62, 4-12. . 2.87 3.62 ( ) 4.12 () - . 12 , .





Russischer Wodka, Etikett:
Stolichnaya Wodka, Etikett:

Dies sind Bilder von hier





Also 4,0 - Inhalt und 0,12 Kapazität insgesamt 4,12 ---- Dies ist der Preis für Stolichnaya Wodka im Jahr 1981.





Laufergebnis:





pins 8 9 1 1 is OK!
cpu freq = 72.000000 MHz
TIME_MULT = 43
120 bits in 57.333332 uSec 2.093023 MHz  6 ticks in 2.866667 uS
120 bits in 269.000000 uSec 0.446097 MHz  6 ticks in 13.450000 uS
120 bits in 162.333328 uSec 0.739220 MHz  6 ticks in 8.116667 uS
120 bits in 109.000000 uSec 1.100917 MHz  6 ticks in 5.450000 uS
120 bits in 82.916664 uSec 1.447236 MHz  6 ticks in 4.145833 uS
120 bits in 69.000000 uSec 1.739130 MHz  6 ticks in 3.450000 uS
120 bits in 75.666664 uSec 1.585903 MHz  6 ticks in 3.783333 uS
120 bits in 75.666664 uSec 1.585903 MHz  6 ticks in 3.783333 uS
120 bits in 77.333336 uSec 1.551724 MHz  6 ticks in 3.866667 uS
120 bits in 77.333336 uSec 1.551724 MHz  6 ticks in 3.866667 uS
TRANSMIT_TIME_DELAY = 15 time = 4.145833 error = 0.627029%
USB1: Ack = 0 Nack = 0 20 pcurrent->cb_Cmd = 2  state = 2 epCount = 0
USB2: Ack = 0 Nack = 0 00 pcurrent->cb_Cmd = 0  state = 0 epCount = 0
desc.bDeviceClass    = 00
desc.bNumConfigurations = 01
cfg.bLength         = 09
cfg.wLength         = 59
cfg.bNumIntf        = 02
cfg.bCV             = 01
cfg.bIndex          = 00
cfg.bAttr           = a0
cfg.bMaxPower       = 50
pcurrent->epCount = 1
pcurrent->epCount = 2
desc.bDeviceClass    = 00
desc.bNumConfigurations = 01
cfg.bLength         = 09
cfg.wLength         = 34
cfg.bNumIntf        = 01
cfg.bCV             = 01
cfg.bIndex          = 00
cfg.bAttr           = a0
cfg.bMaxPower       = 50
pcurrent->epCount = 1
USB0: Ack = 6 Nack = 0 80 pcurrent->cb_Cmd = 14  state = 100 epCount = 2
USB1: Ack = 6 Nack = 0 20 pcurrent->cb_Cmd = 14  state = 104 epCount = 1

      
      



PS Wodka Wodka, wir in Israel haben Hanf erlaubt, ich habe vergessen, die Quelle hier zu posten .





PPS findet keinen Fehler im Code. Dies ist nur ein Proof of Concept. Wird gereinigt.








All Articles