Nove pozice v nasem tymu (ST Praha, MCU support nebo FAE pro Cechy a Slovensko)
Tomas Dresler
dresler na hw.cz
Pátek Leden 9 16:13:39 CET 2015
Mrknete se do zdrojaku nasich driveru (at uz Std.Peripheral Library
nebo CubeFx), vzdy v hlavicce C souboru je popsano, jak tu periferii s
konkretnim driverem nastavit. Presne tak, jak zadate nize.
Dale v kazde knihovne (at stare nebo nove) jsou priklady pro konkretni
periferie. CubeMx vam take pomuze nakonfigurovat, ceho potrebujete
dosahnout.
Navic tam jsou slozitejsi aplikacni konstrukce, od Ethernetu s SSL po
graficka dema s TFT...
/**
******************************************************************************
* @file stm32f4xx_hal_i2s.c
* @author MCD Application Team
* @version V1.1.0
* @date 19-June-2014
* @brief I2S HAL module driver.
* This file provides firmware functions to manage the
following
* functionalities of the Integrated Interchip Sound (I2S)
peripheral:
* + Initialization and de-initialization functions
* + IO operation functions
* + Peripheral State and Errors functions
@verbatim
===============================================================================
##### How to use this driver #####
===============================================================================
[..]
The I2S HAL driver can be used as follow:
(#) Declare a I2S_HandleTypeDef handle structure.
(#) Initialize the I2S low level resources by implement the
HAL_I2S_MspInit() API:
(##) Enable the SPIx interface clock.
(##) I2S pins configuration:
(+++) Enable the clock for the I2S GPIOs.
(+++) Configure these I2S pins as alternate function
pull-up.
(##) NVIC configuration if you need to use interrupt process
(HAL_I2S_Transmit_IT()
and HAL_I2S_Receive_IT() APIs).
(+++) Configure the I2Sx interrupt priority.
(+++) Enable the NVIC I2S IRQ handle.
(##) DMA Configuration if you need to use DMA process
(HAL_I2S_Transmit_DMA()
and HAL_I2S_Receive_DMA() APIs:
(+++) Declare a DMA handle structure for the Tx/Rx stream.
(+++) Enable the DMAx interface clock.
(+++) Configure the declared DMA handle structure with the
required Tx/Rx parameters.
(+++) Configure the DMA Tx/Rx Stream.
(+++) Associate the initilalized DMA handle to the I2S DMA
Tx/Rx handle.
(+++) Configure the priority and enable the NVIC for the
transfer complete interrupt on the
DMA Tx/Rx Stream.
(#) Program the Mode, Standard, Data Format, MCLK Output, Audio
frequency and Polarity
using HAL_I2S_Init() function.
- na - The specific I2S interrupts (Transmission complete interrupt,
RXNE interrupt and Error Interrupts) will be managed using the
macros
__I2S_ENABLE_IT() and __I2S_DISABLE_IT() inside the transmit and
receive process.
- na - Make sure that either:
(+@) I2S PLL is configured or
(+@) External clock source is configured after setting
correctly
the define constant EXTERNAL_CLOCK_VALUE in the
stm32f4xx_hal_conf.h file.
(#) Three operation modes are available within this driver :
*** Polling mode IO operation ***
=================================
[..]
(+) Send an amount of data in blocking mode using
HAL_I2S_Transmit()
(+) Receive an amount of data in blocking mode using
HAL_I2S_Receive()
*** Interrupt mode IO operation ***
===================================
[..]
(+) Send an amount of data in non blocking mode using
HAL_I2S_Transmit_IT()
(+) At transmission end of half transfer
HAL_I2S_TxHalfCpltCallback is executed and user can
add his own code by customization of function pointer
HAL_I2S_TxHalfCpltCallback
(+) At transmission end of transfer HAL_I2S_TxCpltCallback is
executed and user can
add his own code by customization of function pointer
HAL_I2S_TxCpltCallback
(+) Receive an amount of data in non blocking mode using
HAL_I2S_Receive_IT()
(+) At reception end of half transfer HAL_I2S_RxHalfCpltCallback
is executed and user can
add his own code by customization of function pointer
HAL_I2S_RxHalfCpltCallback
(+) At reception end of transfer HAL_I2S_RxCpltCallback is
executed and user can
add his own code by customization of function pointer
HAL_I2S_RxCpltCallback
(+) In case of transfer Error, HAL_I2S_ErrorCallback() function is
executed and user can
add his own code by customization of function pointer
HAL_I2S_ErrorCallback
*** DMA mode IO operation ***
==============================
[..]
(+) Send an amount of data in non blocking mode (DMA) using
HAL_I2S_Transmit_DMA()
(+) At transmission end of half transfer
HAL_I2S_TxHalfCpltCallback is executed and user can
add his own code by customization of function pointer
HAL_I2S_TxHalfCpltCallback
(+) At transmission end of transfer HAL_I2S_TxCpltCallback is
executed and user can
add his own code by customization of function pointer
HAL_I2S_TxCpltCallback
(+) Receive an amount of data in non blocking mode (DMA) using
HAL_I2S_Receive_DMA()
(+) At reception end of half transfer HAL_I2S_RxHalfCpltCallback
is executed and user can
add his own code by customization of function pointer
HAL_I2S_RxHalfCpltCallback
(+) At reception end of transfer HAL_I2S_RxCpltCallback is
executed and user can
add his own code by customization of function pointer
HAL_I2S_RxCpltCallback
(+) In case of transfer Error, HAL_I2S_ErrorCallback() function is
executed and user can
add his own code by customization of function pointer
HAL_I2S_ErrorCallback
(+) Pause the DMA Transfer using HAL_I2S_DMAPause()
(+) Resume the DMA Transfer using HAL_I2S_DMAResume()
(+) Stop the DMA Transfer using HAL_I2S_DMAStop()
*** I2S HAL driver macros list ***
=============================================
[..]
Below the list of most used macros in USART HAL driver.
(+) __HAL_I2S_ENABLE: Enable the specified SPI peripheral (in I2S
mode)
(+) __HAL_I2S_DISABLE: Disable the specified SPI peripheral (in
I2S mode)
(+) __HAL_I2S_ENABLE_IT : Enable the specified I2S interrupts
(+) __HAL_I2S_DISABLE_IT : Disable the specified I2S interrupts
(+) __HAL_I2S_GET_FLAG: Check whether the specified I2S flag is
set or not
[..]
(@) You can refer to the I2S HAL driver header file for more
useful macros
Tomas
On 2015-01-09 13:48, Fanda Kopriva wrote:
> Dobry den
> mel bych takovou prosbu (muzete-li to ovlivnit).
> Bylo by hezke udelat ukazky inicializace jednotlivych periferii.
> Napriklad philips ma v zahlavi popisu kazde periferie co je potreba
> udelat aby se
> periferie rozbehla.
> 1 - spustit hodiny a kde .
> 2 - nastavit porty a kde
> 3 - pripadne dalsi nastaveni
> 4 - nastavit registry u periferie pro nejaky zakladni rezim.
> Kdyz toto udelate tak se periferie spusti a muzete si s ni hrat.
> ST nabizi komplexni reseni ,ktere zahrnuje vsechny moznosti pro
> vsechny procesory.
>
> Bezne si prectu kapitolu o periferii a zacnu konfigurovat registry.
> Kdyz to nebezi tak to znamena cist vsechno ostatni a nebo se zacit
> hrabat v prikladu.
> To znamena skakat mezi radou souboru .c a .h a snazit se pochopit co
> chtel basnik rict.
>
> Priklad
> potreboval jsem rozchodit 16 bit sar AD prevodnik v f373.
> vysledek je nize.Je to par radku ,ale nikde jsem se nedocetl ,ze se
> musi zvlast zapnout
> napajeni prevodniku PWR_CR |= 0x200; (nebo to prehledl)
> Cely se to chovalo ,ze to zije ,jenom data byly nulovy.
> Potom jsem ve vasem prikladu hledal dve hodiny ,ze tam ma byt ten
> prikaz.
> A potom nasel ten registr v manualu v uplne jiny kapitole.
>
>
> void adcinit(void)
> {
> RCC_CFGR |= 0x90000000; // 9 >> 48 deleno 8 = 6mhz pro
> sdadc
> RCC_APB2ENR |= 0x07000000; //zapne hodiny adcdc
> toto jsem tam nadal PWR_CR |= 0x200;
> SDADC1_CR1 |= 0x80000000; //ini
> citac = 100;while ( citac ) citac--;
> while (!( SDADC1_ISR & 0x80000000 )) ; // cekej na ini
> SDADC1_CR1 |= 0x00000008; //interupt na konec extref
> SDADC1_CR2 |= 0x01480000; //fast,cont
> SDADC1_CONF0R = 0x00000000 | (gain<<20); //gain ofset
> SDADC1_CONFCHR2 = 0; //conf0 pro kanal8
> SDADC1_CR1 &= ~0x80000000; // konec ini
> citac = 100;while ( citac ) citac--;
> SDADC1_CR2 |= 0x00000001; //adon
> while ( SDADC1_ISR & 0x80004000 ) ; // cekej na ini=0
> citac = 100;while ( citac ) citac--;
> SDADC1_CR2 |= 0x00800000; //start konverze
> NVIC_IntEnable(IVT_INT_SDADC1);
>
> hodnotamin=0xffff;
> hodnotamax=0;
> citac = 0;
> }
>
>
> void sdacint() iv IVT_INT_SDADC1 ics ICS_AUTO { //25us 7us
> GPIOA_BSRR = tesd0A;
> hodnota = SDADC1_RDATAR + 32767;citac++;
> audiobufer[audiobuferinuk++]=hodnota ;
> if (audiobuferinuk>6144) audiobuferinuk=0;
> if (hodnotamin>hodnota) hodnotamin=hodnota;
> if (hodnotamax<hodnota) hodnotamax=hodnota;
> GPIOA_BSRR = tesd0A << 16;
> }
>
> Techto par radku nahradite desitkama kilobytu textu a pritom prave
> techto par radku je podstatnych.
> Ty priklady od Vas spise zavadeji (aspon mne) .Malo kdo bude treba
> merit termoclanek a tak aby vyuzil Vas priklad tak musi
> projit a zahodit vetsinu programu z prikladu a napsat si vlastni.To
> co je potreba je prave jenom ta
> inicializacni cast.
>
> Pripada mi ,ze prave prilisna komplexnost ukazek je na skodu.
>
> Podobna byla ukazka usb VCP.Nikdo nebude procesorem resit VCP s
> vystupem na USART.
> Na to pouzije FTD nebo neco podobnyho.Ocistit VCP od toho Usartu mi
> dalo dost prace a nez jsem to dodelal tak
> jste tam dali to reseni bez Usartu .Ale to bylo od zacatku zbytecny.
> Treba u USB si myslim ,ze by pro vetsinu aplikaci stacilo udelat neco
> jako USB stack jako je FTD.Jednoduchy rozhrani
> Prijde byte nastavi se flag a muzu ho vycist a mam-li volny bufr tak
> muzu zapsat.
>
> Omlouvam se za to postesknuti ,ale mozna je vic takovych staromodnich
> programatoru, co si program
> misto sestavovani pisou.
>
> Diky Fanda
Další informace o konferenci Hw-list