<html><body><style> @font-face{font-family:'Cambria Math';panose-1:2 4 5 3 5 4 6 3 2 4}@font-face{font-family:Calibri;panose-1:2 15 5 2 2 2 4 3 2 4}@font-face{font-family:Consolas;panose-1:2 11 6 9 2 2 4 3 2 4}.apply-styles p.-wm-MsoNormal, .apply-styles li.-wm-MsoNormal, .apply-styles div.-wm-MsoNormal{margin:0cm;font-size:11pt;font-family:'Calibri',sans-serif}.apply-styles a:link, .apply-styles span.-wm-MsoHyperlink{mso-style-priority:99;color:blue;text-decoration:underline}.apply-styles pre{mso-style-priority:99;mso-style-link:'Form\e1 tovan\fd v HTML Char';margin:0cm;font-size:10pt;font-family:'Courier New'}.apply-styles span.-wm-FormtovanvHTMLChar{mso-style-name:'Form\e1 tovan\fd v HTML Char';mso-style-priority:99;mso-style-link:'Form\e1 tovan\fd v HTML';font-family:'Courier New'}.apply-styles .-wm-MsoChpDefault{mso-style-type:export-only}@page WordSection1 {size:612pt 792pt;margin:70.85pt 70.85pt 70.85pt 70.85pt}.apply-styles div.-wm-WordSection1{}</style><div>registry s podtržítky jsou definované v libopencm3 ale to jste asi nechtěl slyšet ...</div><div><br></div><aside>
---------- Původní e-mail ----------<br>
Od: Pavel Hudecek <edizon@seznam.cz><br>
Komu: HW-news <hw-list@list.hw.cz><br>
Datum: 29. 11. 2020 18:23:57<br>
Předmět: RE: Zase STM32
</aside><br><blockquote data-email="edizon@seznam.cz"><div class="-wm-WordSection1"><p class="-wm-MsoNormal">Díky všem,</p><p class="-wm-MsoNormal"> </p><p class="-wm-MsoNormal">K PWM jsem si vytvořil hezký driver (viz dále). Ale nakonec jsem narazil na nečekaný problém: Po překladu jsou všechny řádky červené, počínaje tím, že nezná <span style="font-family:Consolas">TIM3_CCR0.</span></p><p class="-wm-MsoNormal"> </p><p class="-wm-MsoNormal">A v default kódu vygenerovaném grafickým konfigurátorem jsou věci jako:</p><p class="-wm-MsoNormal">htim3.Init.CounterMode = TIM_COUNTERMODE_UP;</p><p class="-wm-MsoNormal"> </p><p class="-wm-MsoNormal">Mě by se teda líbilo, kdyby tam byly ty věci co jsem použil, s podtržítky, které souhlasí s názvy z datasheetu. Předpokládám, že bych měl něco includnout. Tak prosím ještě o název fajlu:-)</p><p class="-wm-MsoNormal"> </p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas">// moje PWM TIM3 chan</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas">#define PWM0_chan 3 // az po propojeni</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas">#define PWM1_chan 4</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas">#define PWM2_chan 2</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> </span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas">void pwmSet(char chan, uint16_t val) { // hodnota PWM -------------------------------------------------</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> switch(chan) {</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 0: TIM3_CCR0 = val; break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 1: TIM3_CCR1 = val; break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 2: TIM3_CCR2 = val; break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 3: TIM3_CCR3 = val; break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 4: TIM3_CCR4 = val; break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> }</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas">}</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> </span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas">void pwmInit(uint8_t chan, char port, uint8_t pin, uint16_t per, uint16_t val) { // -------------------</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> int n;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> </span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> RCC_APB1ENR |=2; //TIM3 en</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> switch (port) {</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 'A':</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> GPIOA_MODER |= 2<<(1<<pin); //port alt fn</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> switch(chan) {</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 0:</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 1:</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> GPIOA_AFRL |= 1<<(pin<<2); // AF1</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 2:</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> GPIOA_AFRL |= 1<<(pin<<2); // AF1</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 3:</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 4:</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> }</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 'B':</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> GPIOB_MODER |= 2<<(1<<pin); //port alt fn</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> switch(chan) {</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 0:</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 1:</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> GPIOB_AFRL |= 1<<(pin<<2); // AF1</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 2:</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> GPIOB_AFRL |= 1<<(pin<<2); // AF1</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 3:</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> GPIOB_AFRL |= 1<<(pin<<2); // AF1</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> case 4:</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> GPIOB_AFRL |= 1<<(pin<<2); // AF1</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> }</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> break;</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> }</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> TIM3_CR1 = 0x1; // Bit 1 UDIS: Update disable</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> TIM3_CCMR2_Output = 0b110<<12; // OC4M out 111 PWM mode 2, 110 PWM mode 1</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> TIM3_CCR4 = val; // PWM value</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> TIM3_CCER = 0x3000; // CC4P 1: OC1 active low / CC4E 1: On - OC1 signal is output</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> TIM3_CNT = 0; // counter</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> TIM3_PSC = 0; // nedelit - 48 MHz</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> TIM3_ARR = per; // perioda</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> TIM3_CR1 = 0x1; // CEN 1: Counter enabled</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas"> pwmSet(chan, val); // hodnota PWM</span></p><p class="-wm-MsoNormal"><span style="font-size:10pt;font-family:Consolas">}</span></p><p class="-wm-MsoNormal"> </p><p class="-wm-MsoNormal">A tady použití:</p><p class="-wm-MsoNormal"> </p><p class="-wm-MsoNormal"><span style="font-family:Consolas"> pwmInit(PWM0_chan, 'B', 0, CPU_freq/PWM_freq, pwm0);</span></p><p class="-wm-MsoNormal"><span style="font-family:Consolas"> pwmInit(PWM1_chan, 'B', 1, CPU_freq/PWM_freq, pwm1);</span></p><p class="-wm-MsoNormal"><span style="font-family:Consolas"> pwmInit(PWM2_chan, 'A', 7, CPU_freq/PWM_freq, pwm2);</span></p><p class="-wm-MsoNormal"><span style="font-family:Consolas"> </span></p><p class="-wm-MsoNormal"><span style="font-family:Consolas">PH</span></p><p class="-wm-MsoNormal"> </p><div style="mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1pt;padding:3pt 0cm 0cm 0cm"><p class="-wm-MsoNormal" style="border:none;padding:0cm"><b>Od: </b><a href="mailto:info@elektronikavyvoj.cz">Fanda Kopriva</a><br><b>Odesláno:</b>neděle 29. listopadu 2020 13:22<br><b>Komu: </b><a href="mailto:hw-list@list.hw.cz">hw-list@list.hw.cz</a><br><b>Předmět: </b>Re: Zase STM32</p></div><p class="-wm-MsoNormal"> </p><div><p class="-wm-MsoNormal">dobry den</p></div><div><p class="-wm-MsoNormal">s STM32F030K6T6 jsem delal pro kamarada nastavovani modelarskeho serva opakovacka 20 ms a pulz 1-2ms</p></div><div><p class="-wm-MsoNormal"> </p></div><div><p class="-wm-MsoNormal" style="margin-bottom:12pt">void motor(char co)<br>{<br>unsigned int pwmx;<br> switch (co) {<br> case 'I':<br> RCC_APB1ENR |=2; //servo inicializace<br> GPIOB_MODER |= 0x00000008; //port pb1<br> GPIOB_AFRL |= 0x00000010;<br> TIM3_CR1 = 0x1; <br> TIM3_CCMR2_Output = 0x7000; <br> TIM3_CCR4 = 0; //togle<br> TIM3_CCER = 0x3000; //11<br> TIM3_CNT = 0;<br> TIM3_PSC = 7; //1us<br> TIM3_ARR = 20000; //20ms<br> TIM3_CR1 = 0x1; //43<br> TIM3_CCR4 = 1000; //1.5ms<br> break;<br> case 'P':<br> pwmx = servo * 50 + 1000; //servo nastaveni<br> if (pwmx>2000) pwmx=2000; <br> TIM3_CCR4 = pwmx;<br> break;<br> case 'S':TIM3_CCR4 = 1000; //1.5ms servo stop<br> break;<br> }<br>}</p></div><div><p class="-wm-MsoNormal"> </p></div><p class="-wm-MsoNormal">jeste priklad pro stm32f446 - </p><div><p class="-wm-MsoNormal"> </p></div><div><p class="-wm-MsoNormal"> </p></div><div><p class="-wm-MsoNormal">#define enc1 0 //pc7 T3ch2<br>#define enc2 0 //pc8 T3ch3<br><br>void encod(unsigned char co){<br> if (co=='I') { //inicializace<br> GPIOC_MODER &= 0xfffc3fff;<br> GPIOC_MODER |= 0x00028000;<br> GPIOC_AFRH |= 0x00000002;<br> GPIOC_AFRL |= 0x20000000;<br> GPIOC_OSPEEDR |=0x00028000;<br> RCC_APB1ENR |= 0x2; //tim3 168/4 42MHz<br> TIM3_CR1 = 0x81; <br> TIM3_CCMR1_Output = 0x7000; <br> TIM3_CCMR2_Output = 0x0070; <br> TIM3_CCER = 0x0110; <br> TIM3_CNT = 0;<br> TIM3_PSC = 0;<br> TIM3_ARR = 20000;<br> TIM3_CCR2 = 10000;<br> TIM3_CCR3 = 10000;<br> TIM3_CR1 = 0x81; //zisk ad603 pwm1 ch1<br> }<br><br> if (co=='P') { //nastaveni<br><br> if (laserA>18000) pwmx=18000; else pwmx=18000 - laserA;<br> TIM1_CCR2 = pwmx;<br> if (laserB>18000) pwmx=18000; else pwmx=18000 - laserB;<br> TIM1_CCR3 = pwmx;<br> }<br> }</p></div><div><p class="-wm-MsoNormal"> </p></div><div><p class="-wm-MsoNormal"> </p></div><div><p class="-wm-MsoNormal">mam tady jeste priklad pro stm32f427 - </p></div><div><p class="-wm-MsoNormal"> </p></div><div><p class="-wm-MsoNormal" style="margin-bottom:12pt">//#define laspwm 0x200 //d14 T4ch3<br>//#define pwina // d12 T4ch1 //zisk<br>//#define pwin // d13 T4ch2</p></div><div><p class="-wm-MsoNormal">unsigned int laseron ;<br>void laser(unsigned char co)<br>{<br>signed int laspoz;<br>switch (co) {<br> case 'I':<br> GPIOD_MODER &= 0xc0FFFFFF;<br> GPIOD_MODER |= 0x2a000000;<br> GPIOD_AFRH |= 0x02220000;<br> RCC_APB1ENR |= 0x4;<br> TIM4_CR1 = 0x1;<br> TIM4_CCMR2_Output = 0x70;<br> TIM4_CCMR1_Output = 0x7070;<br> TIM4_CCER = 0x0111; //11<br> TIM4_CNT = 0;<br> TIM4_PSC = 10;<br> TIM4_ARR = 256;<br> TIM4_CCR3 = 255;<br> TIM4_CR1 = 0x1; //zisk ad603 pwm1 ch1 unsigned int lasset,lasproud,maxlaser;<br> break;<br> case 'P':<br> TIM4_CCR3 = laserproud;</p></div><div><p class="-wm-MsoNormal"> TIM4_CCR2 = zisk;<br> TIM4_CCR1 = ziska;<br> break;<br> }<br>}<br><br>fanda</p></div><div><p class="-wm-MsoNormal"> </p></div><div><p class="-wm-MsoNormal">Dne 29. 11. 2020 v 11:15 Pavel Hudecek napsal(a):</p></div><blockquote style="margin-top:5pt;margin-bottom:5pt"><p class="-wm-MsoNormal">Dobrý den všem,</p><p class="-wm-MsoNormal"> </p><p class="-wm-MsoNormal">Trápím se tady s STM32F030K6T6, k PC připojeno přes STM32F0308 discovery, Cube IDE.</p><p class="-wm-MsoNormal"> </p><p class="-wm-MsoNormal">1. Jak udělat, aby program běžel i po disconnect?</p><p class="-wm-MsoNormal">2. Nedaří se mi zprovoznit PWM. Byla by nějaká ukázka, nejlépe pro TIM3?</p><p class="-wm-MsoNormal"> </p><p class="-wm-MsoNormal">Díky,</p><p class="-wm-MsoNormal">PH</p><p class="-wm-MsoNormal"> </p><p class="-wm-MsoNormal"><br><br></p><pre>_______________________________________________</pre><pre>HW-list mailing list - sponsored by <a href="http://www.hw.cz">www.HW.cz</a></pre><pre><a href="mailto:Hw-list@list.hw.cz">Hw-list@list.hw.cz</a></pre><pre><a href="http://list.hw.cz/mailman/listinfo/hw-list">http://list.hw.cz/mailman/listinfo/hw-list</a></pre></blockquote><p> </p><p class="-wm-MsoNormal"> </p></div>_______________________________________________<br>HW-list mailing list - sponsored by www.HW.cz<br>Hw-list@list.hw.cz<br>http://list.hw.cz/mailman/listinfo/hw-list<br></blockquote></body></html>