diff --git a/examples/BeagleSynthHello/BeagleSynthHello.pro b/examples/BeagleSynthHello/BeagleSynthHello.pro deleted file mode 100644 --- a/examples/BeagleSynthHello/BeagleSynthHello.pro +++ /dev/null @@ -1,15 +0,0 @@ -!isEmpty( UCMODEL ) { - contains( UCMODEL, stm32f4 ){ - TEMPLATE = app - BSP = BEAGLESYNTH - #BSP = SOLAR_LFR_PSU - - SOURCES += \ - main.c - } -} - - - - - diff --git a/examples/BeagleSynthHello/main.c b/examples/BeagleSynthHello/main.c deleted file mode 100644 --- a/examples/BeagleSynthHello/main.c +++ /dev/null @@ -1,109 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -extern streamdevice* __opnfiles__[]; - -#define LCD_COLOR_WHITE 0xFFFF -#define LCD_COLOR_BLACK 0x0000 -#define LCD_COLOR_GREY 0xF7DE -#define LCD_COLOR_BLUE 0x001F -#define LCD_COLOR_BLUE2 0x051F -#define LCD_COLOR_RED 0xF800 -#define LCD_COLOR_MAGENTA 0xF81F -#define LCD_COLOR_GREEN 0x07E0 -#define LCD_COLOR_CYAN 0x7FFF -#define LCD_COLOR_YELLOW 0xFFE0 - - -void monkDemo() -{ - while(1) - { - lcd0.paintText(&lcd0," ",10,Monk_24.Height+10,&Monk_24,LCD_COLOR_BLACK); - lcd0.paintText(&lcd0," ",230-Monk_24.Width,310,&Monk_24,LCD_COLOR_BLUE); - for(volatile int i=0;i<(1024*1024*16);i++); - lcd0.paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_WHITE,1,LCD_COLOR_WHITE); - for(volatile int i=0;i<(1024*1024*4);i++); - } -} - - -void randBoxesDemo() -{ - int16_t x,y,w,h,t,r; - x=rand()%240; - y=rand()%320; - w=rand()%(240-x); - if(x>y) - r=(rand()%(y))%(320-y); - else - r=(rand()%(x))%(240-x); - h=rand()%(320-y); - t=rand()%(10); - ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); - ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); - //delay_100us(10); - //for(volatile int i=0;i<(1024*2);i++); -} - -int libuc_main() -{ - INA226_t ina5VSens,ina33VSens,ina15VSens; - gpioset(PSU_DISABLE); - volatile int16_t* regtest=(volatile int16_t*)0x60000000; - volatile int16_t* regtest2=(volatile int16_t*)(0x61FFFFF0); - //ina226open(&ina5VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000); - //ina226open(&ina15VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,1,0,15,1000000); - *regtest=(int16_t)0; - printf("LCD ID=%x\n\r",0xFFFF&(*regtest2)); - printf("Sys Tick=%d\n\r",SysTick->VAL); - printf("Sys Tick=%d\n\r",SysTick->VAL); - printf("Sys Tick=%d\n\r",SysTick->VAL); - printf("Sys Tick=%d\n\r",SysTick->VAL); - ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_BLACK,1,LCD_COLOR_WHITE); - while(1)randBoxesDemo();//monkDemo(); - if(-1==ina226open(&ina33VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000)) - { - printf("Can't open 3.3V monitor\n\r"); - } - int current5V,current33V,current15V; - printf("\t5V\t3.3V\n\r"); - while(1) - { - for(volatile int i=0;i<1024*1024;i++); - gpioset(LED1); - gpioclr(LED2); - for(volatile int i=0;i<1024*1024;i++); - gpioclr(LED1); - gpioset(LED2); - //current5V = ina226getCurrent(&ina5VSens); - current33V = ina226getCurrent(&ina33VSens); - //current15V = ina226getCurrent(&ina15VSens); - //current = ina226getReg(&Psens1,INA226_Current_Reg); - //printf("%duA %dmA\t%duA %dmA\n\r",current5V,current5V/1000,current33V,current33V/1000); - printf("%duA %dmA\n\r",current33V,current33V/1000); - } - printf("hello world\n\r"); - return 0; -} - - - - - - - - - diff --git a/examples/BeagleSynthHelloSupMon/BeagleSynthHelloSupMon.pro b/examples/BeagleSynthHelloSupMon/BeagleSynthHelloSupMon.pro deleted file mode 100644 --- a/examples/BeagleSynthHelloSupMon/BeagleSynthHelloSupMon.pro +++ /dev/null @@ -1,18 +0,0 @@ -!isEmpty( UCMODEL ) { - contains( UCMODEL, stm32f4 ){ - TEMPLATE = app - - DEFINES += CPUFREQ=80000000 - - BSP = BEAGLESYNTH - #BSP = SOLAR_LFR_PSU - #BSP = STM32F4Eval - - SOURCES += \ - main.c - } -} - - - - diff --git a/examples/BeagleSynthHelloSupMon/main.c b/examples/BeagleSynthHelloSupMon/main.c deleted file mode 100644 --- a/examples/BeagleSynthHelloSupMon/main.c +++ /dev/null @@ -1,123 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -extern streamdevice* __opnfiles__[]; - -#define LCD_COLOR_WHITE 0xFFFF -#define LCD_COLOR_BLACK 0x0000 -#define LCD_COLOR_GREY 0xF7DE -#define LCD_COLOR_BLUE 0x001F -#define LCD_COLOR_BLUE2 0x051F -#define LCD_COLOR_RED 0xF800 -#define LCD_COLOR_MAGENTA 0xF81F -#define LCD_COLOR_GREEN 0x07E0 -#define LCD_COLOR_CYAN 0x7FFF -#define LCD_COLOR_YELLOW 0xFFE0 - -#ifndef PSU_DISABLE -#define PSU_DISABLE LED1 -#endif - -void setUartAsStdout() -{ - streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); - uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); - uartmkstreamdev(uart,fd1); - __opnfiles__[1] = fd1; -} - -void printSupplyStatus(int cur5v,int cur33v,int cur15v, int volt5v, int volt33v, int volt15v) -{ - char buffer[64]; - int i=0; - int power5V=(cur5v*(volt5v/1000))/1000,power33V=(cur33v*(volt33v/1000))/1000,power15V=(cur15v*(volt15v/1000))/1000; -#define clearBuff for(i=0;i<64;i++)buffer[i]='\0' - - ili9328paintFilRect(&lcd0,5,5,230,7*(ComicSansMS_18.Height+10)+50,LCD_COLOR_BLACK,4,LCD_COLOR_WHITE); - ili9328paintFilRect(&lcd0,5,7*(ComicSansMS_18.Height+10)+50,230,320 - (7*(ComicSansMS_18.Height+10)+50),LCD_COLOR_BLACK,4,LCD_COLOR_WHITE); - clearBuff; - sprintf(buffer,"%.3fV %dmA",volt5v/1000000.0,cur5v); - ili9328paintText(&lcd0,buffer,10,0*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); - clearBuff; - sprintf(buffer,"%dmW",power5V); - ili9328paintText(&lcd0,buffer,10,1*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); - clearBuff; - sprintf(buffer,"%.3fV %dmA",volt33v/1000000.0,cur33v); - ili9328paintText(&lcd0,buffer,10,2*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); - clearBuff; - sprintf(buffer,"%dmW",power33V); - ili9328paintText(&lcd0,buffer,10,3*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); - clearBuff; - sprintf(buffer,"%.3fV %dmA",volt15v/1000000.0,cur15v); - ili9328paintText(&lcd0,buffer,10,4*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); - clearBuff; - sprintf(buffer,"%dmW",power15V); - ili9328paintText(&lcd0,buffer,10,5*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); - - clearBuff; - sprintf(buffer,"Total = %dmW",power5V+power33V+power15V); - ili9328paintText(&lcd0,buffer,10,320-10-20,&ComicSansMS_18,LCD_COLOR_BLACK); - -} - -int libuc_main() -{ - delay_100us(20000); - INA226_t ina5VSens,ina33VSens,ina15VSens; - gpioset(PSU_DISABLE);//enable psu! - setUartAsStdout(); - //ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_BLACK,1,LCD_COLOR_BLACK); - - ili9328paintFilRect(&lcd0,5,5,230,310,LCD_COLOR_BLACK,4,LCD_COLOR_WHITE); - if(-1==ina226open(&ina33VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,1,15,1000000)) - { - printf("Can't open 3.3V monitor\n\r"); - } - if(-1==ina226open(&ina5VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000)) - { - printf("Can't open 5V monitor\n\r"); - } - if(-1==ina226open(&ina15VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,1,0,15,1000000)) - { - printf("Can't open 1.5V monitor\n\r"); - } - int current5V,current33V,current15V,volt5v, volt33v, volt15v; - while(1) - { - current5V = ina226getCurrent(&ina5VSens); - current33V = ina226getCurrent(&ina33VSens); - current15V = ina226getCurrent(&ina15VSens); - volt5v = ina226getBusVoltage(&ina5VSens); - volt33v = ina226getBusVoltage(&ina33VSens); - volt15v = ina226getBusVoltage(&ina15VSens); - printf("%fV\t%dmA\n\r",volt15v/1000000.0,current15V/1000); - printf("%fV\t%dmA\n\r",volt33v/1000000.0,current33V/1000); - printf("%fV\t%dmA\n\r",volt5v/1000000.0,current5V/1000); - printSupplyStatus(current5V/1000,current33V/1000,current15V/1000,volt5v, volt33v, volt15v); - delay_100us(10000); - } - printf("Exit\n\r"); - return 0; -} - - - - - - - - - diff --git a/examples/DAC/DAC.pro b/examples/DAC/DAC.pro new file mode 100644 --- /dev/null +++ b/examples/DAC/DAC.pro @@ -0,0 +1,22 @@ +TEMPLATE = app + +DEFINES += CPUFREQ=40000000 + +LIBS += -ldac + +eval(UCMODEL = simulator) { + BSP = SIMULATOR +} +eval(UCMODEL = stm32f4) { + BSP = STM32F4Eval +} + +SOURCES += \ + main.c + + + + + + + diff --git a/examples/DAC/main.c b/examples/DAC/main.c new file mode 100644 --- /dev/null +++ b/examples/DAC/main.c @@ -0,0 +1,56 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2013, Alexis Jeandet +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/** @author Alexis Jeandet alexis.jeandet@member.fsf.org +-------------------------------------------------------------------------------*/ +/** +* This file is a simple example for the DAC library. +* +*/ + +#include +#include +#include +#include +#include +#include +int16_t __attribute__ ((aligned (4))) data[512]; +int libuc_main() +{ + /** + Depending on the board the printf can be directed on one uart or LCD screen or + any other stream device. + */ + printf("DAC example\n\r"); + for(int i=0;i<512;i++) + { + data[i]=(int16_t)(2000.0*cos(i/10.0))+2000.0; + } + dacopen(PA4); + dacsetconfig(timer8, 512, DAC1,DAC1_12bit_right_align , 100000,(void*)data); + return 0; +} + + + + + + + + + diff --git a/examples/M4StickV2/M4StickV2.pro b/examples/M4StickV2/M4StickV2.pro deleted file mode 100644 --- a/examples/M4StickV2/M4StickV2.pro +++ /dev/null @@ -1,15 +0,0 @@ -!isEmpty( UCMODEL ) { - contains( UCMODEL, stm32f4 ){ - TEMPLATE = app - - BSP=M4StickV2 - - DEFINES += CPUFREQ=80000000 - - SOURCES += \ - main.c - - } -} - - diff --git a/examples/M4StickV2/main.c b/examples/M4StickV2/main.c deleted file mode 100644 --- a/examples/M4StickV2/main.c +++ /dev/null @@ -1,115 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -void ads1278readOut(spi_t spidev,int32_t* data) -{ - gpioset(ADC_FSYNC); - //delay_100us(1); - for(volatile int i=0;i<50;i++); - gpioclr(ADC_FSYNC); - for(int i=0;i<8;i++) - { - data[i]=spigetw(spidev)<<16; - data[i]+=spigetw(spidev)<<8; - data[i]+=spigetw(spidev); - if((data[i]&(1<<23)))data[i]-=(1<<24); - } - -} - -void pushData(int32_t* data) -{ -// printf("%f\t%f\t%f\n",(6.0/(8*1000*1000)) *data[0],(6.0/(8*1000*1000))*data[1],(6.0/(8*1000*1000))*data[2]); - printf("%f\n",(6.0/(16*1000*1000)) *data[0]); - -} - -void pushData2(int32_t* data) -{ - char buffer[29]; - buffer[0] = 0xa5; - buffer[1] = 0x0f; - buffer[2] = 0x00; - buffer[27] = 0xf0; - buffer[28] = 0x5a; - for(int i=0;i<8;i++) - { - buffer[(i*3)+3] = (char)data[i]>>16; - buffer[(i*3)+4] = (char)data[i]>>8; - buffer[(i*3)+5] = (char)data[i]; - } - uartputnc(uart1,buffer,29); -} - -void sample() -{ - int32_t data[8]; - data[0]=0x712345; - char buffer[2+1+3+2]; - buffer[0] = 0xa5; - buffer[1] = 0x0f; - buffer[2] = 0x00; - buffer[2+1+3] = 0xf0; - buffer[2+1+4] = 0x5a; - while(1) - { - //uartputnc(uart1,buffer,3); - uartputc(uart1,0xa5); - uartputc(uart1,0x0f); - uartputc(uart1,0x01); - uartputc(uart1,25); - for(int i=0;i<8;i++) - { - //ads1278readOut(spi1,data); - uartputc(uart1,(char)0x1);//(data[0])>>16); - uartputc(uart1,(char)0x2);//(data[0]>>8)); - uartputc(uart1,(char)0x3);//(data[0]>>0)); - } - uartputc(uart1,0xf0); - uartputc(uart1,0x5a); - } -} - -int libuc_main() -{ - int32_t data[8]; - char test=0; - for(int i=0;i<500;i++) - { - ads1278readOut(spi1,data); - delay_100us(10); - } - sample(); - //while(1) - //{ - // uartputc(uart1,test++); - //} - -// while(1) -// { -// ads1278readOut(spi1,data); -// gpioclr(LED2); -// //delay_100us(100); -//// for(volatile int i=0;i<100;i++); -// pushData(data); -// gpioset(LED2); -// //delay_100us(100); -// } -} - - - - - - - - - - - - diff --git a/examples/M4stick/M4stick.pro b/examples/M4stick/M4stick.pro deleted file mode 100644 --- a/examples/M4stick/M4stick.pro +++ /dev/null @@ -1,18 +0,0 @@ -TEMPLATE = app -M4Stick.ARCH = stm32f4-arm-none-eabi-gcc -M4Stick.TARGET = M4stickBlink -M4Stick.BSP = M4Stick - -STM32F4Disc.ARCH = stm32f4-arm-none-eabi-gcc -STM32F4Disc.TARGET = STM32F4DiscoveryBlink -STM32F4Disc.BSP = STM32F4Discovery - -*.LIBS += SPI UART GPIO STREAMDEVICES UHANDLE UCSTRINGS CPU STLIB - -*.SOURCES += main.c - - - -*.HEADERS += - - diff --git a/examples/M4stick/bin/STM32F4DiscoveryBlink.elf b/examples/M4stick/bin/STM32F4DiscoveryBlink.elf deleted file mode 100644 index 4a63a05289aea576087d51981b18c8cf3ef5ff07..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 GIT binary patch literal 0 Hc$@ -#include -#include - - - -int main() -{ - bsp_init(); - gpio_t gpio1 = gpioopen(PD12);//gpioopen(LED1); //PD9 D=> 0x0300 9 => 0x0009 - gpio_t gpio2 = gpioopen(PD13);//gpioopen(LED2); - gpiosetdir(&gpio1,gpiooutdir); - gpiosetdir(&gpio2,gpiooutdir); - - while(1) - { - for(volatile int i=0;i<1024*1024*4;i++); - gpioset(gpio1); - gpioclr(gpio2); - for(volatile int i=0;i<1024*1024*16;i++); - gpioclr(gpio1); - gpioset(gpio2); - } -} diff --git a/examples/N25Q128_test/N25Q128_test.pro b/examples/N25Q128_test/N25Q128_test.pro deleted file mode 100644 --- a/examples/N25Q128_test/N25Q128_test.pro +++ /dev/null @@ -1,16 +0,0 @@ -!isEmpty( UCMODEL ) { - contains( UCMODEL, stm32f4 ){ - TEMPLATE = app - - BSP = SOLAR_LFR_PSU - - LIBS += -lN25Q128 - - SOURCES += \ - main.c - - } -} - - - diff --git a/examples/N25Q128_test/main.c b/examples/N25Q128_test/main.c deleted file mode 100644 --- a/examples/N25Q128_test/main.c +++ /dev/null @@ -1,93 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern streamdevice* __opnfiles__[]; - -/* - N25Q128 pinout: - MISO => PB14 - MOSI => PB15 - SCK => PB13 - CS => PB12 - WP => PC1 - RESET/HOLD => PC2 -*/ -void cs(int csstate) -{ - gpiosetval(PB12,csstate); -} - -void wp(int wpstate) -{ - gpiosetval(PC1,wpstate); -} - -void resetHold(int rhstate) -{ - gpiosetval(PC2,rhstate); -} - -int libuc_main() -{ - spiopenandconfig(spi2,spiclkfirstedge|spimaster|spimsbfirst|spi8bits,10000,PB15,PB14,PB13,-1); - //spiopenandconfig(spi2,spiclkfirstedge|spimaster|spimsbfirst|spi8bits,10000,PB15,PB14,PB13,PB12); - gpio_t PC1pin= gpioopen(PC1); - gpiosetdir(&PC1pin,gpiooutdir); - gpio_t PC2pin= gpioopen(PC2); - gpiosetdir(&PC2pin,gpiooutdir); - gpio_t PB12pin= gpioopen(PB12); - gpiosetdir(&PB12pin,gpiooutdir); - gpioset(PC1); - gpioset(PB12); - gpioclr(PC2); - eepromN25Q128Dev eeprom; - eepromN25Q128open(&eeprom,spi2,&cs,&wp,&resetHold); - //eepromN25Q128open(&eeprom,spi2,NULL,&wp,&resetHold); - delay_100us(10); - gpioset(PC2); - gpioclr(PB12); - spiputw(spi2,0x9E); - char res[22]; - spigetnc(spi2,res,22); - gpioset(PB12); - for(int i=0;i<22;i++) - { - printf("res[%d] = 0x%x\n\r",i,(int)res[i]); - } - eepromN25Q128enablewrite(&eeprom); - delay_100us(10); - eepromN25Q128writen(&eeprom,0,"hello World",11); - delay_100us(10); - eepromN25Q128readn(&eeprom,0,res,11); - res[11]='\n'; - res[12]='\r'; - res[13]=0; - printf("read: %s",res); - printf("\n"); - for(int i=0;i<11;i++) - { - printf("res[%d] = 0x%x\n\r",i,(int)res[i]); - } - while(1) - { - gpioset(LED3); - delay_100us(10000); - gpioclr(LED3); - delay_100us(10000); - } - printf("hello world\n\r"); - return 0; -} - - - - - - diff --git a/examples/PWM/PWM.pro b/examples/PWM/PWM.pro new file mode 100644 --- /dev/null +++ b/examples/PWM/PWM.pro @@ -0,0 +1,18 @@ +TEMPLATE = app + +eval(UCMODEL = simulator) { + BSP = SIMULATOR +} +eval(UCMODEL = stm32f4) { + BSP = STM32F4Eval +} + +SOURCES += \ + main.c + + + + + + + diff --git a/examples/PWM/main.c b/examples/PWM/main.c new file mode 100644 --- /dev/null +++ b/examples/PWM/main.c @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2013, Alexis Jeandet +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/** @author Alexis Jeandet alexis.jeandet@member.fsf.org +-------------------------------------------------------------------------------*/ +/** +* This file is a simple hello world example it should run on any supported +* board/architecture couple. To change target board and architecture modify +* the project file. The value BSP contains the board name, and UCMODEL contain +* the target architecture. +*/ + +int libuc_main() +{ + /** + Depending on the board the printf can be directed on one uart or LCD screen or + any other stream device. + */ + printf("hello world\n\r"); + return 0; +} + + + + + + + + + diff --git a/examples/QtTest/main.c b/examples/QtTest/main.c deleted file mode 100644 --- a/examples/QtTest/main.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include - -int libuc_main() -{ - gpio_t gpio1 = gpioopen(PD12);//gpioopen(LED1); //PD9 D=> 0x0300 9 => 0x0009 - gpio_t gpio2 = gpioopen(PD13);//gpioopen(LED2); - gpiosetdir(&gpio1,gpiooutdir); - gpiosetdir(&gpio2,gpiooutdir); - volatile int i=0; - while(1) - { - for(i=0;i<1024*1024*4;i++); - gpioset(gpio1); - gpioclr(gpio2); - for(i=0;i<1024*1024*16;i++); - gpioclr(gpio1); - gpioset(gpio2); - } - return 0; -} diff --git a/examples/QtTest/test.pro b/examples/QtTest/test.pro deleted file mode 100644 --- a/examples/QtTest/test.pro +++ /dev/null @@ -1,13 +0,0 @@ -!isEmpty( UCMODEL ) { - contains( UCMODEL, stm32f4 ){ - TEMPLATE = app - - BSP = SOLAR_LFR_PSU - - SOURCES += \ - main.c - } -} - - - diff --git a/examples/SDCARD/SDCARD b/examples/SDCARD/SDCARD deleted file mode 100644 index 49bdc8fd764070b95d71173819bdb4710d2b1c42..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 GIT binary patch literal 0 Hc$@ -#include -#include -#include -#include -#include -#include - - -int libuc_main() -{ - blkdevice dev; - dikpartition part; - ucdirent dirent; - FAT32fs fs; - sdcardDev sdcard; - //sdcardmake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,uint32_t),void (*xmit_mmc) (UHANDLE,const char *,uint32_t ),void (*setspeed) (UHANDLE phy,uint32_t speed),uint32_t (*getspeed) (UHANDLE phy)) - //sdcardmakeblkdev(&dev); - - // mbropen(&dev,&part,1); - spi_t spi = spiopenandconfig(spi2,spi8bits | spimaster |spiclkinhlow | spiclkfirstedge | spimsbfirst,10000,PB15,PB14,PB13,-1); - while(1) - { - spiputw(spi,0x15); - for(volatile int i=0;i<1024*1024;i++); - } - printf("Hello world from project 'SDCARD'! %f\n\r",2.986*4.565); - return 0; -} - - - - - - - - - - - - diff --git a/examples/SOLAR_PSU_HELLO/hello.pro b/examples/SOLAR_PSU_HELLO/hello.pro deleted file mode 100644 --- a/examples/SOLAR_PSU_HELLO/hello.pro +++ /dev/null @@ -1,19 +0,0 @@ -!isEmpty( UCMODEL ) { - contains( UCMODEL, stm32f4 ){ - TEMPLATE = app - CONFIG += cpu - - BSP = OPLAYER - #BSP = STM32F4Discovery-ILI9328-8bits - - DEFINES += CPUFREQ=40000000 - - - SOURCES += \ - main.c \ - test_lcd.c - - } -} - - diff --git a/examples/SOLAR_PSU_HELLO/main.c b/examples/SOLAR_PSU_HELLO/main.c deleted file mode 100644 --- a/examples/SOLAR_PSU_HELLO/main.c +++ /dev/null @@ -1,230 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -extern streamdevice* __opnfiles__[]; -extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); -extern void test_all_colors(LCD_t* LCD); -extern void test_small_lines(LCD_t* LCD); -extern void test_lines(LCD_t* LCD); -extern void test_address(LCD_t* LCD); -extern void test_TC(); -void test_uniform_rw(LCD_t* LCD); -char buffer[512]; - -void randBoxesDemo() -{ - int16_t x,y,w,h,t,r; - x=rand()%240; - y=rand()%320; - w=rand()%(240-x); - if(x>y) - r=(rand()%(y))%(320-y); - else - r=(rand()%(x))%(240-x); - h=rand()%(320-y); - t=rand()%(10); - ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); - //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); - //delay_100us(10); - //for(volatile int i=0;i<(1024*2);i++); -} - -void randTextDemo() -{ - int16_t x,y,w,h,t,r; - char buf[2]; - buf[1]='\0'; - x=rand()%240; - y=rand()%320; - if(x>y) - r=(rand()%(y))%(320-y); - else - r=(rand()%(x))%(240-x); - h=rand()%(320-y); - buf[0]=rand()%(255); - //ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); - ili9328paintText(&lcd0,buf,x,y,&ComicSansMS_18,rand()); - //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); - delay_100us(5000); - //for(volatile int i=0;i<(1024*2);i++); -} - -void tryToplay2() -{ - - extern blkdevice sdcard2blkdev; - int i=0,l=0; - - spisetspeed(audioCodec0.SPIdev,4000000); - printf("Streaming File\n"); - - //printf("New LBA=0x%X\n",nextLba); - - while(sdcard2blkdev.read(&sdcard2blkdev,buffer,l++,1)==RES_OK) - { - - for(i=0;i<512;i+=32) - { - vs10XXstream32bytes(&audioCodec0,buffer+i); - } - } -} - -void playFile(ucdirent* file,FAT32fs* part) -{ - extern volatile vs10XXDev audioCodec0; - char direntName[]=" \n"; - uint32_t fileLba,nextLba; - int i=0; - fat32getdirentname(file,direntName); - //gpioset(LCD_BACKL); - printf("%s\n",direntName); - nextLba=fat32getdirentlba(file); - //printf("Streaming File\n"); - //gpioclr(LCD_BACKL); - do - { - fileLba = nextLba; - if(sdcard2FAT32part1.part->phy->read(part->part->phy,buffer,fileLba,1)==RES_OK) - { - for(i=0;i<512;i+=32) - { - vs10XXstream32bytes(&audioCodec0,buffer+i); - } - } - }while ((fat32nextsectorlba(part,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3))); - vs10XXsoftReset(&audioCodec0); - while (gpiogetval(BP3))delay_100us(1000); -} - -void playAllparts() -{ - extern FAT32fs sdcard2FAT32part1,sdcard2FAT32part2,sdcard2FAT32part3,sdcard2FAT32part4; - ucdirent root; - if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root)) - { - printf("Reading on SDCARD2 part1\n"); - if(DIRENT_noErr==fat32getrootfirstent(&root)) - { - do{ - playFile(&root,&sdcard2FAT32part1); - }while (DIRENT_noErr==fat32nextdirent(&root)); - } - } - gpioset(LED2); - if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root)) - { - printf("Reading on SDCARD2 part2\n"); - if(DIRENT_noErr==fat32getrootfirstent(&root)) - { - do{ - playFile(&root,&sdcard2FAT32part2); - }while (DIRENT_noErr==fat32nextdirent(&root)); - } - } -} - -int main1() -{ - delay_100us(30000); - int i=0; - int color=0; - // test_all_colors(&lcd0); - // test_small_lines(&lcd0); - // test_uniform_rw(&lcd0); - - printf("LCD ID REG = 0x%X\n\r",lcd0.interface->readreg(ILI9328_REGISTER_DRIVERCODEREAD)); - printf("LCD ENTRY MODE REG = 0x%X\n\r",lcd0.interface->readreg(ILI9328_REGISTER_ENTRYMODE)); - uint16_t test[16]; - for(int i=0;i<16;i++) - { - test[i]=0xF00F; - } - lcd0.paint(&lcd0,test,10,100,4,4); - lcd0.getPix(&lcd0,test,10,100,4,4); - for(int i=0;i<16;i++) - { - printf("@%d=0x%X\n",i,test[i]); - } -// test_lines(&lcd0); - test_TC(); - while(1)test_address(&lcd0); - for(i=0;i<240;i++) - { - if(i>(240/3)) - { - color= (i<<5) + 0x1F; - } - else - { - color = i; - } - if(i>(2*240/3)) - { - color= (i<<10) + 0x3FF; - } - lcd0.paintFilRect(&lcd0,i,0,1,100,0,0,color); - } - while(1)printf("test "); -// for(i=0;i<240;i++) -// { -// if(i>(240/3)) -// { -// color= (i<<5) + 0x1F; -// } -// else -// { -// color = i; -// } -// if(i>(2*240/3)) -// { -// color= (i<<10) + 0x3FF; -// } -// lcd0.paintFilRect(&lcd0,i,220,1,100,0,0,color); -// } - for(i=0;i<240;i++) - { - ili9328setFrame(&lcd0,i,0,1,100); - lcd0.interface->readGRAM(buffer,100); - lcd0.paint(&lcd0,buffer,i,200,1,100); - } - while(1); -} - -int libuc_main() -{ - extern terminal_t terminal0; - extern volatile vs10XXDev audioCodec0; - printf("Volume=0x%x\n",vs10XXcmdread(&audioCodec0,VSVOL)); - vs10XXcmdwrite(&audioCodec0,VSCLOCKF,0x2000); - delay_100us(1000); - //vs10XXcmdwrite(&audioCodec0,VSVOL,0x2020); - printf("VSCLOCKF=0x%x\n",vs10XXcmdread(&audioCodec0,VSCLOCKF)); - printf("VSMODE=0x%x\n",vs10XXcmdread(&audioCodec0,VSMODE)); - //terminal_clear(&terminal0); - // gpioclr(LCD_BACKL); - playAllparts(); - return 0; -} - - - - - - diff --git a/examples/SOLAR_PSU_HELLO/test_lcd.c b/examples/SOLAR_PSU_HELLO/test_lcd.c deleted file mode 100644 --- a/examples/SOLAR_PSU_HELLO/test_lcd.c +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -uint16_t buff[50*50]; -void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color) -{ - LCD->paintFilRect(LCD,x,y,w,h,0,0,color); -} - -void test_small_lines(LCD_t* LCD) -{ - int i=0; - for(i=0;iheight;i+=2) - { - LCD->paintFilRect(LCD,0,i,LCD->width,1,0,0,0xaa00); - } - for(i=1;iheight;i+=2) - { - LCD->paintFilRect(LCD,0,i,LCD->width,1,0,0,0x5500); - } - -} - -void test_uniform_rw(LCD_t* LCD) -{ - uint16_t buffer[50*50]; - LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height/2,0,0,0xfaa0); - delay_100us(10000); - LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xfaa0); - ili9328setFrame(LCD,10,100,50,50); - while(1) - { -// LCD->interface->readGRAM((void*)buffer,50*50); - LCD->getPix(LCD,buffer,10,100,50,50); - LCD->paint(LCD,buffer,10,100,50,50); - delay_100us(10000); - //ili9328setFrame(LCD,10,100,50,50); - //LCD->interface->writeGRAM((void*)buffer,50*50); - } - -} - -void test_all_colors(LCD_t* LCD) -{ - uint16_t color=0; - char colorch[]=" "; - while(1) - { - LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,color); - sprintf(colorch,"0x%x",0xFFFF & ((int)color)); - LCD->paintText(LCD,colorch,10,100,&ComicSansMS_18,color^-1); - //delay_100us(10); - color+=1; - } -} - -void test_address(LCD_t* LCD) -{ - LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF); - uint16_t color[1]; - for(int y=0;y<320;y++) - { - for(int x=0;x<240;x++) - { - color[0]=x*y; - LCD->paint(LCD,color,x,y,1,1); - //delay_100us(100); - } - } - LCD->getPix(LCD,buff,50,50,50,50); - delay_100us(5000); - for(int i=0;i<50*50;i++) - { - buff[i]=i; - } - LCD->paint(LCD,buff,50,50,50,50); - delay_100us(5000); -} - -void test_lines(LCD_t* LCD) -{ - uint16_t color[2];//=0x0FF0; - int x=0; - LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF); - for(int l=0;l<0xFFFF;l++) - { - color[0]=l; - color[1]=l; - for(int i=0;i<320;i++) - { - x=i*240/320; - LCD->paint(LCD,color,x,i,2,1); - } - for(int i=0;i<320;i++) - { - x=239-(i*240/320); - LCD->paint(LCD,color,x,i,2,1); - } - } -} - - -void test_TC() -{ - int x,y; - char coord[256]=""; - while(1) - { - ads7843read(&TC0,&x,&y); - sprintf(coord,"%d;%d",x,y); - lcd0.paintFilRect(&lcd0,0,0,240,100,0,0,0xF0F0); - lcd0.paintText(&lcd0,coord,10,50,&ComicSansMS_18,0); - for(int i =0;i<256;i++)coord[i]=' '; - delay_100us(100); - x=0; - y=0; - } -} diff --git a/examples/STM32F4Discovery/STM32F4Discovery.pro b/examples/STM32F4Discovery/STM32F4Discovery.pro deleted file mode 100644 --- a/examples/STM32F4Discovery/STM32F4Discovery.pro +++ /dev/null @@ -1,8 +0,0 @@ -TEMPLATE = dir -SUBDIRS += blink - - - - - - diff --git a/examples/STM32F4Discovery/TestSpi/TestSpi.pro b/examples/STM32F4Discovery/TestSpi/TestSpi.pro deleted file mode 100644 --- a/examples/STM32F4Discovery/TestSpi/TestSpi.pro +++ /dev/null @@ -1,14 +0,0 @@ -TEMPLATE = app -ARCH = stm32f4-arm-none-eabi-gcc -TARGET = stm32f4DiscoveryTestSpi -BSP = STM32F4Discovery - -LIBS += STLIB - -SOURCES += main.c - - - -HEADERS += - - diff --git a/examples/STM32F4Discovery/TestSpi/bin/stm32f4DiscoveryTestSpi.elf b/examples/STM32F4Discovery/TestSpi/bin/stm32f4DiscoveryTestSpi.elf deleted file mode 100644 index 733a7cf940811a80617d18db99d2feb898edf032..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 GIT binary patch literal 0 Hc$@ -#include -#include -#include -#include -#define CODEC_I2C_GPIO_AF GPIO_AF_I2C1 -#define CODEC_I2C_GPIO GPIOB -#define CODEC_I2C_SCL_PIN GPIO_Pin_6 -#define CODEC_I2C_SDA_PIN GPIO_Pin_9 -#define CODEC_I2S_SCL_PINSRC GPIO_PinSource6 -#define CODEC_I2S_SDA_PINSRC GPIO_PinSource9 - -int main() -{ - GPIO_InitTypeDef GPIO_InitStructure; - SPI_InitTypeDef SPI_InitStructure; - bsp_init(); - RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOB, &GPIO_InitStructure); - GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2); - GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_SPI2); - GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2); - - SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; - SPI_InitStructure.SPI_Mode = SPI_Mode_Master; - SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; - SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; - SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; - SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; - SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; - SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; - SPI_InitStructure.SPI_CRCPolynomial = 7; - SPI_Init(SPI2, &SPI_InitStructure); - SPI_Cmd(SPI2, ENABLE); - while(1) - { - while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); - SPI_I2S_SendData(SPI2, 0x5a); - } -} diff --git a/examples/STM32F4Discovery/TestSpi/startup_stm32f4xx.s b/examples/STM32F4Discovery/TestSpi/startup_stm32f4xx.s deleted file mode 100644 --- a/examples/STM32F4Discovery/TestSpi/startup_stm32f4xx.s +++ /dev/null @@ -1,509 +0,0 @@ -/** - ****************************************************************************** - * @file startup_stm32f4xx.s - * @author MCD Application Team - * @version V1.0.0 - * @date 30-September-2011 - * @brief STM32F4xx Devices vector table for RIDE7 toolchain. - * This module performs: - * - Set the initial SP - * - Set the initial PC == Reset_Handler, - * - Set the vector table entries with the exceptions ISR address - * - Configure the clock system and the external SRAM mounted on - * STM324xG-EVAL board to be used as data memory (optional, - * to be enabled by user) - * - Branches to main in the C library (which eventually - * calls main()). - * After Reset the Cortex-M4 processor is in Thread mode, - * priority is Privileged, and the Stack is set to Main. - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - - .syntax unified - .cpu cortex-m3 - .fpu softvfp - .thumb - -.global g_pfnVectors -.global Default_Handler - -/* start address for the initialization values of the .data section. -defined in linker script */ -.word _sidata -/* start address for the .data section. defined in linker script */ -.word _sdata -/* end address for the .data section. defined in linker script */ -.word _edata -/* start address for the .bss section. defined in linker script */ -.word _sbss -/* end address for the .bss section. defined in linker script */ -.word _ebss -/* stack used for SystemInit_ExtMemCtl; always internal RAM used */ - -/** - * @brief This is the code that gets called when the processor first - * starts execution following a reset event. Only the absolutely - * necessary set is performed, after which the application - * supplied main() routine is called. - * @param None - * @retval : None -*/ - - .section .text.Reset_Handler - .weak Reset_Handler - .type Reset_Handler, %function -Reset_Handler: - -/* Copy the data segment initializers from flash to SRAM */ - movs r1, #0 - b LoopCopyDataInit - -CopyDataInit: - ldr r3, =_sidata - ldr r3, [r3, r1] - str r3, [r0, r1] - adds r1, r1, #4 - -LoopCopyDataInit: - ldr r0, =_sdata - ldr r3, =_edata - adds r2, r0, r1 - cmp r2, r3 - bcc CopyDataInit - ldr r2, =_sbss - b LoopFillZerobss -/* Zero fill the bss segment. */ -FillZerobss: - movs r3, #0 - str r3, [r2], #4 - -LoopFillZerobss: - ldr r3, = _ebss - cmp r2, r3 - bcc FillZerobss - -/* Call the clock system intitialization function.*/ - bl SystemInit -/* Call the application's entry point.*/ - bl main - bx lr -.size Reset_Handler, .-Reset_Handler - -/** - * @brief This is the code that gets called when the processor receives an - * unexpected interrupt. This simply enters an infinite loop, preserving - * the system state for examination by a debugger. - * @param None - * @retval None -*/ - .section .text.Default_Handler,"ax",%progbits -Default_Handler: -Infinite_Loop: - b Infinite_Loop - .size Default_Handler, .-Default_Handler -/****************************************************************************** -* -* The minimal vector table for a Cortex M3. Note that the proper constructs -* must be placed on this to ensure that it ends up at physical address -* 0x0000.0000. -* -*******************************************************************************/ - .section .isr_vector,"a",%progbits - .type g_pfnVectors, %object - .size g_pfnVectors, .-g_pfnVectors - - -g_pfnVectors: - .word _estack - .word Reset_Handler - .word NMI_Handler - .word HardFault_Handler - .word MemManage_Handler - .word BusFault_Handler - .word UsageFault_Handler - .word 0 - .word 0 - .word 0 - .word 0 - .word SVC_Handler - .word DebugMon_Handler - .word 0 - .word PendSV_Handler - .word SysTick_Handler - - /* External Interrupts */ - .word WWDG_IRQHandler /* Window WatchDog */ - .word PVD_IRQHandler /* PVD through EXTI Line detection */ - .word TAMP_STAMP_IRQHandler /* Tamper and TimeStamps through the EXTI line */ - .word RTC_WKUP_IRQHandler /* RTC Wakeup through the EXTI line */ - .word FLASH_IRQHandler /* FLASH */ - .word RCC_IRQHandler /* RCC */ - .word EXTI0_IRQHandler /* EXTI Line0 */ - .word EXTI1_IRQHandler /* EXTI Line1 */ - .word EXTI2_IRQHandler /* EXTI Line2 */ - .word EXTI3_IRQHandler /* EXTI Line3 */ - .word EXTI4_IRQHandler /* EXTI Line4 */ - .word DMA1_Stream0_IRQHandler /* DMA1 Stream 0 */ - .word DMA1_Stream1_IRQHandler /* DMA1 Stream 1 */ - .word DMA1_Stream2_IRQHandler /* DMA1 Stream 2 */ - .word DMA1_Stream3_IRQHandler /* DMA1 Stream 3 */ - .word DMA1_Stream4_IRQHandler /* DMA1 Stream 4 */ - .word DMA1_Stream5_IRQHandler /* DMA1 Stream 5 */ - .word DMA1_Stream6_IRQHandler /* DMA1 Stream 6 */ - .word ADC_IRQHandler /* ADC1, ADC2 and ADC3s */ - .word CAN1_TX_IRQHandler /* CAN1 TX */ - .word CAN1_RX0_IRQHandler /* CAN1 RX0 */ - .word CAN1_RX1_IRQHandler /* CAN1 RX1 */ - .word CAN1_SCE_IRQHandler /* CAN1 SCE */ - .word EXTI9_5_IRQHandler /* External Line[9:5]s */ - .word TIM1_BRK_TIM9_IRQHandler /* TIM1 Break and TIM9 */ - .word TIM1_UP_TIM10_IRQHandler /* TIM1 Update and TIM10 */ - .word TIM1_TRG_COM_TIM11_IRQHandler /* TIM1 Trigger and Commutation and TIM11 */ - .word TIM1_CC_IRQHandler /* TIM1 Capture Compare */ - .word TIM2_IRQHandler /* TIM2 */ - .word TIM3_IRQHandler /* TIM3 */ - .word TIM4_IRQHandler /* TIM4 */ - .word I2C1_EV_IRQHandler /* I2C1 Event */ - .word I2C1_ER_IRQHandler /* I2C1 Error */ - .word I2C2_EV_IRQHandler /* I2C2 Event */ - .word I2C2_ER_IRQHandler /* I2C2 Error */ - .word SPI1_IRQHandler /* SPI1 */ - .word SPI2_IRQHandler /* SPI2 */ - .word USART1_IRQHandler /* USART1 */ - .word USART2_IRQHandler /* USART2 */ - .word USART3_IRQHandler /* USART3 */ - .word EXTI15_10_IRQHandler /* External Line[15:10]s */ - .word RTC_Alarm_IRQHandler /* RTC Alarm (A and B) through EXTI Line */ - .word OTG_FS_WKUP_IRQHandler /* USB OTG FS Wakeup through EXTI line */ - .word TIM8_BRK_TIM12_IRQHandler /* TIM8 Break and TIM12 */ - .word TIM8_UP_TIM13_IRQHandler /* TIM8 Update and TIM13 */ - .word TIM8_TRG_COM_TIM14_IRQHandler /* TIM8 Trigger and Commutation and TIM14 */ - .word TIM8_CC_IRQHandler /* TIM8 Capture Compare */ - .word DMA1_Stream7_IRQHandler /* DMA1 Stream7 */ - .word FSMC_IRQHandler /* FSMC */ - .word SDIO_IRQHandler /* SDIO */ - .word TIM5_IRQHandler /* TIM5 */ - .word SPI3_IRQHandler /* SPI3 */ - .word UART4_IRQHandler /* UART4 */ - .word UART5_IRQHandler /* UART5 */ - .word TIM6_DAC_IRQHandler /* TIM6 and DAC1&2 underrun errors */ - .word TIM7_IRQHandler /* TIM7 */ - .word DMA2_Stream0_IRQHandler /* DMA2 Stream 0 */ - .word DMA2_Stream1_IRQHandler /* DMA2 Stream 1 */ - .word DMA2_Stream2_IRQHandler /* DMA2 Stream 2 */ - .word DMA2_Stream3_IRQHandler /* DMA2 Stream 3 */ - .word DMA2_Stream4_IRQHandler /* DMA2 Stream 4 */ - .word ETH_IRQHandler /* Ethernet */ - .word ETH_WKUP_IRQHandler /* Ethernet Wakeup through EXTI line */ - .word CAN2_TX_IRQHandler /* CAN2 TX */ - .word CAN2_RX0_IRQHandler /* CAN2 RX0 */ - .word CAN2_RX1_IRQHandler /* CAN2 RX1 */ - .word CAN2_SCE_IRQHandler /* CAN2 SCE */ - .word OTG_FS_IRQHandler /* USB OTG FS */ - .word DMA2_Stream5_IRQHandler /* DMA2 Stream 5 */ - .word DMA2_Stream6_IRQHandler /* DMA2 Stream 6 */ - .word DMA2_Stream7_IRQHandler /* DMA2 Stream 7 */ - .word USART6_IRQHandler /* USART6 */ - .word I2C3_EV_IRQHandler /* I2C3 event */ - .word I2C3_ER_IRQHandler /* I2C3 error */ - .word OTG_HS_EP1_OUT_IRQHandler /* USB OTG HS End Point 1 Out */ - .word OTG_HS_EP1_IN_IRQHandler /* USB OTG HS End Point 1 In */ - .word OTG_HS_WKUP_IRQHandler /* USB OTG HS Wakeup through EXTI */ - .word OTG_HS_IRQHandler /* USB OTG HS */ - .word DCMI_IRQHandler /* DCMI */ - .word CRYP_IRQHandler /* CRYP crypto */ - .word HASH_RNG_IRQHandler /* Hash and Rng */ - .word FPU_IRQHandler /* FPU */ - -/******************************************************************************* -* -* Provide weak aliases for each Exception handler to the Default_Handler. -* As they are weak aliases, any function with the same name will override -* this definition. -* -*******************************************************************************/ - .weak NMI_Handler - .thumb_set NMI_Handler,Default_Handler - - .weak HardFault_Handler - .thumb_set HardFault_Handler,Default_Handler - - .weak MemManage_Handler - .thumb_set MemManage_Handler,Default_Handler - - .weak BusFault_Handler - .thumb_set BusFault_Handler,Default_Handler - - .weak UsageFault_Handler - .thumb_set UsageFault_Handler,Default_Handler - - .weak SVC_Handler - .thumb_set SVC_Handler,Default_Handler - - .weak DebugMon_Handler - .thumb_set DebugMon_Handler,Default_Handler - - .weak PendSV_Handler - .thumb_set PendSV_Handler,Default_Handler - - .weak SysTick_Handler - .thumb_set SysTick_Handler,Default_Handler - - .weak WWDG_IRQHandler - .thumb_set WWDG_IRQHandler,Default_Handler - - .weak PVD_IRQHandler - .thumb_set PVD_IRQHandler,Default_Handler - - .weak TAMP_STAMP_IRQHandler - .thumb_set TAMP_STAMP_IRQHandler,Default_Handler - - .weak RTC_WKUP_IRQHandler - .thumb_set RTC_WKUP_IRQHandler,Default_Handler - - .weak FLASH_IRQHandler - .thumb_set FLASH_IRQHandler,Default_Handler - - .weak RCC_IRQHandler - .thumb_set RCC_IRQHandler,Default_Handler - - .weak EXTI0_IRQHandler - .thumb_set EXTI0_IRQHandler,Default_Handler - - .weak EXTI1_IRQHandler - .thumb_set EXTI1_IRQHandler,Default_Handler - - .weak EXTI2_IRQHandler - .thumb_set EXTI2_IRQHandler,Default_Handler - - .weak EXTI3_IRQHandler - .thumb_set EXTI3_IRQHandler,Default_Handler - - .weak EXTI4_IRQHandler - .thumb_set EXTI4_IRQHandler,Default_Handler - - .weak DMA1_Stream0_IRQHandler - .thumb_set DMA1_Stream0_IRQHandler,Default_Handler - - .weak DMA1_Stream1_IRQHandler - .thumb_set DMA1_Stream1_IRQHandler,Default_Handler - - .weak DMA1_Stream2_IRQHandler - .thumb_set DMA1_Stream2_IRQHandler,Default_Handler - - .weak DMA1_Stream3_IRQHandler - .thumb_set DMA1_Stream3_IRQHandler,Default_Handler - - .weak DMA1_Stream4_IRQHandler - .thumb_set DMA1_Stream4_IRQHandler,Default_Handler - - .weak DMA1_Stream5_IRQHandler - .thumb_set DMA1_Stream5_IRQHandler,Default_Handler - - .weak DMA1_Stream6_IRQHandler - .thumb_set DMA1_Stream6_IRQHandler,Default_Handler - - .weak ADC_IRQHandler - .thumb_set ADC_IRQHandler,Default_Handler - - .weak CAN1_TX_IRQHandler - .thumb_set CAN1_TX_IRQHandler,Default_Handler - - .weak CAN1_RX0_IRQHandler - .thumb_set CAN1_RX0_IRQHandler,Default_Handler - - .weak CAN1_RX1_IRQHandler - .thumb_set CAN1_RX1_IRQHandler,Default_Handler - - .weak CAN1_SCE_IRQHandler - .thumb_set CAN1_SCE_IRQHandler,Default_Handler - - .weak EXTI9_5_IRQHandler - .thumb_set EXTI9_5_IRQHandler,Default_Handler - - .weak TIM1_BRK_TIM9_IRQHandler - .thumb_set TIM1_BRK_TIM9_IRQHandler,Default_Handler - - .weak TIM1_UP_TIM10_IRQHandler - .thumb_set TIM1_UP_TIM10_IRQHandler,Default_Handler - - .weak TIM1_TRG_COM_TIM11_IRQHandler - .thumb_set TIM1_TRG_COM_TIM11_IRQHandler,Default_Handler - - .weak TIM1_CC_IRQHandler - .thumb_set TIM1_CC_IRQHandler,Default_Handler - - .weak TIM2_IRQHandler - .thumb_set TIM2_IRQHandler,Default_Handler - - .weak TIM3_IRQHandler - .thumb_set TIM3_IRQHandler,Default_Handler - - .weak TIM4_IRQHandler - .thumb_set TIM4_IRQHandler,Default_Handler - - .weak I2C1_EV_IRQHandler - .thumb_set I2C1_EV_IRQHandler,Default_Handler - - .weak I2C1_ER_IRQHandler - .thumb_set I2C1_ER_IRQHandler,Default_Handler - - .weak I2C2_EV_IRQHandler - .thumb_set I2C2_EV_IRQHandler,Default_Handler - - .weak I2C2_ER_IRQHandler - .thumb_set I2C2_ER_IRQHandler,Default_Handler - - .weak SPI1_IRQHandler - .thumb_set SPI1_IRQHandler,Default_Handler - - .weak SPI2_IRQHandler - .thumb_set SPI2_IRQHandler,Default_Handler - - .weak USART1_IRQHandler - .thumb_set USART1_IRQHandler,Default_Handler - - .weak USART2_IRQHandler - .thumb_set USART2_IRQHandler,Default_Handler - - .weak USART3_IRQHandler - .thumb_set USART3_IRQHandler,Default_Handler - - .weak EXTI15_10_IRQHandler - .thumb_set EXTI15_10_IRQHandler,Default_Handler - - .weak RTC_Alarm_IRQHandler - .thumb_set RTC_Alarm_IRQHandler,Default_Handler - - .weak OTG_FS_WKUP_IRQHandler - .thumb_set OTG_FS_WKUP_IRQHandler,Default_Handler - - .weak TIM8_BRK_TIM12_IRQHandler - .thumb_set TIM8_BRK_TIM12_IRQHandler,Default_Handler - - .weak TIM8_UP_TIM13_IRQHandler - .thumb_set TIM8_UP_TIM13_IRQHandler,Default_Handler - - .weak TIM8_TRG_COM_TIM14_IRQHandler - .thumb_set TIM8_TRG_COM_TIM14_IRQHandler,Default_Handler - - .weak TIM8_CC_IRQHandler - .thumb_set TIM8_CC_IRQHandler,Default_Handler - - .weak DMA1_Stream7_IRQHandler - .thumb_set DMA1_Stream7_IRQHandler,Default_Handler - - .weak FSMC_IRQHandler - .thumb_set FSMC_IRQHandler,Default_Handler - - .weak SDIO_IRQHandler - .thumb_set SDIO_IRQHandler,Default_Handler - - .weak TIM5_IRQHandler - .thumb_set TIM5_IRQHandler,Default_Handler - - .weak SPI3_IRQHandler - .thumb_set SPI3_IRQHandler,Default_Handler - - .weak UART4_IRQHandler - .thumb_set UART4_IRQHandler,Default_Handler - - .weak UART5_IRQHandler - .thumb_set UART5_IRQHandler,Default_Handler - - .weak TIM6_DAC_IRQHandler - .thumb_set TIM6_DAC_IRQHandler,Default_Handler - - .weak TIM7_IRQHandler - .thumb_set TIM7_IRQHandler,Default_Handler - - .weak DMA2_Stream0_IRQHandler - .thumb_set DMA2_Stream0_IRQHandler,Default_Handler - - .weak DMA2_Stream1_IRQHandler - .thumb_set DMA2_Stream1_IRQHandler,Default_Handler - - .weak DMA2_Stream2_IRQHandler - .thumb_set DMA2_Stream2_IRQHandler,Default_Handler - - .weak DMA2_Stream3_IRQHandler - .thumb_set DMA2_Stream3_IRQHandler,Default_Handler - - .weak DMA2_Stream4_IRQHandler - .thumb_set DMA2_Stream4_IRQHandler,Default_Handler - - .weak ETH_IRQHandler - .thumb_set ETH_IRQHandler,Default_Handler - - .weak ETH_WKUP_IRQHandler - .thumb_set ETH_WKUP_IRQHandler,Default_Handler - - .weak CAN2_TX_IRQHandler - .thumb_set CAN2_TX_IRQHandler,Default_Handler - - .weak CAN2_RX0_IRQHandler - .thumb_set CAN2_RX0_IRQHandler,Default_Handler - - .weak CAN2_RX1_IRQHandler - .thumb_set CAN2_RX1_IRQHandler,Default_Handler - - .weak CAN2_SCE_IRQHandler - .thumb_set CAN2_SCE_IRQHandler,Default_Handler - - .weak OTG_FS_IRQHandler - .thumb_set OTG_FS_IRQHandler,Default_Handler - - .weak DMA2_Stream5_IRQHandler - .thumb_set DMA2_Stream5_IRQHandler,Default_Handler - - .weak DMA2_Stream6_IRQHandler - .thumb_set DMA2_Stream6_IRQHandler,Default_Handler - - .weak DMA2_Stream7_IRQHandler - .thumb_set DMA2_Stream7_IRQHandler,Default_Handler - - .weak USART6_IRQHandler - .thumb_set USART6_IRQHandler,Default_Handler - - .weak I2C3_EV_IRQHandler - .thumb_set I2C3_EV_IRQHandler,Default_Handler - - .weak I2C3_ER_IRQHandler - .thumb_set I2C3_ER_IRQHandler,Default_Handler - - .weak OTG_HS_EP1_OUT_IRQHandler - .thumb_set OTG_HS_EP1_OUT_IRQHandler,Default_Handler - - .weak OTG_HS_EP1_IN_IRQHandler - .thumb_set OTG_HS_EP1_IN_IRQHandler,Default_Handler - - .weak OTG_HS_WKUP_IRQHandler - .thumb_set OTG_HS_WKUP_IRQHandler,Default_Handler - - .weak OTG_HS_IRQHandler - .thumb_set OTG_HS_IRQHandler,Default_Handler - - .weak DCMI_IRQHandler - .thumb_set DCMI_IRQHandler,Default_Handler - - .weak CRYP_IRQHandler - .thumb_set CRYP_IRQHandler,Default_Handler - - .weak HASH_RNG_IRQHandler - .thumb_set HASH_RNG_IRQHandler,Default_Handler - - .weak FPU_IRQHandler - .thumb_set FPU_IRQHandler,Default_Handler - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/TestSpi/stm32f4xx_it.c b/examples/STM32F4Discovery/TestSpi/stm32f4xx_it.c deleted file mode 100644 --- a/examples/STM32F4Discovery/TestSpi/stm32f4xx_it.c +++ /dev/null @@ -1,179 +0,0 @@ -/** - ****************************************************************************** - * @file stm32f4xx_it.c - * @author MCD Application Team - * @version V1.0.0 - * @date 19-September-2011 - * @brief Main Interrupt Service Routines. - * This file provides all exceptions handler and peripherals interrupt - * service routine. - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx_it.h" - - - -/******************************************************************************/ -/* Cortex-M3 Processor Exceptions Handlers */ -/******************************************************************************/ - -/** - * @brief This function handles NMI exception. - * @param None - * @retval None - */ -void NMI_Handler(void) -{ -} - -/** - * @brief This function handles Hard Fault exception. - * @param None - * @retval None - */ -void HardFault_Handler(void) -{ - /* Go to infinite loop when Hard Fault exception occurs */ - while (1) - { - } -} - -/** - * @brief This function handles Memory Manage exception. - * @param None - * @retval None - */ -void MemManage_Handler(void) -{ - /* Go to infinite loop when Memory Manage exception occurs */ - while (1) - { - } -} - -/** - * @brief This function handles Bus Fault exception. - * @param None - * @retval None - */ -void BusFault_Handler(void) -{ - /* Go to infinite loop when Bus Fault exception occurs */ - while (1) - { - } -} - -/** - * @brief This function handles Usage Fault exception. - * @param None - * @retval None - */ -void UsageFault_Handler(void) -{ - /* Go to infinite loop when Usage Fault exception occurs */ - while (1) - { - } -} - -/** - * @brief This function handles SVCall exception. - * @param None - * @retval None - */ -void SVC_Handler(void) -{ -} - -/** - * @brief This function handles Debug Monitor exception. - * @param None - * @retval None - */ -void DebugMon_Handler(void) -{ -} - -/** - * @brief This function handles PendSVC exception. - * @param None - * @retval None - */ -void PendSV_Handler(void) -{ -} - -/** - * @brief This function handles SysTick Handler. - * @param None - * @retval None - */ -void SysTick_Handler(void) -{ -} - -/******************************************************************************/ -/* STM32Fxxx Peripherals Interrupt Handlers */ -/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ -/* available peripheral interrupt handler's name please refer to the startup */ -/* file (startup_stm32fxxx.s). */ -/******************************************************************************/ - -/** - * @brief This function handles PPP interrupt request. - * @param None - * @retval None - */ -/*void PPP_IRQHandler(void) -{ -}*/ - -/** - * @brief This function handles EXTI0_IRQ Handler. - * @param None - * @retval None - */ -void EXTI0_IRQHandler(void) -{ -} - -/** - * @brief This function handles EXTI15_10_IRQ Handler. - * @param None - * @retval None - */ -void OTG_FS_WKUP_IRQHandler(void) -{ -} - -/** - * @brief This function handles OTG_HS Handler. - * @param None - * @retval None - */ -void OTG_FS_IRQHandler(void) -{ -} - -/** -* @brief USBD_HID_GetPos -* @param None -* @retval Pointer to report -*/ - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/TestSpi/syscalls.c b/examples/STM32F4Discovery/TestSpi/syscalls.c deleted file mode 100644 --- a/examples/STM32F4Discovery/TestSpi/syscalls.c +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#undef errno - - -#ifdef __cplusplus -extern "C" { -#endif -extern int errno; - -char *__env[1] = { 0 }; -char **environ = __env; - -int _exit() -{ - while(1); -} - -int _close(int file) { -return -1; -} - -int _write(int file, char *ptr, int len) { -int todo; -for (todo = 0; todo < len; todo++) { -//outbyte (*ptr++); -} -return len; -} - -int _execve(char *name, char **argv, char **env) { -errno = ENOMEM; -return -1; -} - - -int _fork(void) { -errno = EAGAIN; -return -1; -} - -int _fstat(int file, struct stat *st) { -st->st_mode = S_IFCHR; -return 0; -} - - -int _getpid(void) { -return 1; -} - - -int _isatty(int file) { -return 1; -} - - -int _kill(int pid, int sig) { -errno = EINVAL; -return -1; -} - - -int _link(char *old, char *new) { -errno = EMLINK; -return -1; -} - - -int _lseek(int file, int ptr, int dir) { -return 0; -} - -int _open(const char *name, int flags, int mode) { -return -1; -} - -int _read(int file, char *ptr, int len) { -return 0; -} - - - -caddr_t _sbrk(int incr) { -register char * stack_ptr __asm__ ("sp"); -extern char _end; /* Defined by the linker */ -static char *heap_end; -char *prev_heap_end; -if (heap_end == 0) { -heap_end = &_end; -} -prev_heap_end = heap_end; -if (heap_end + incr > stack_ptr) { -_write (1, "Heap and stack collision\n", 25); -abort (); -} -heap_end += incr; -return (caddr_t) prev_heap_end; -} - - - -int _stat(char *file, struct stat *st) { -st->st_mode = S_IFCHR; -return 0; -} - - -int _times(struct tms *buf) { -return -1; -} - - -int _unlink(char *name) { -errno = ENOENT; -return -1; -} - -int _wait(int *status) { -errno = ECHILD; -return -1; -} - - -#ifdef __cplusplus -} -#endif - - diff --git a/examples/STM32F4Discovery/TestSpi/system_stm32f4xx.c b/examples/STM32F4Discovery/TestSpi/system_stm32f4xx.c deleted file mode 100644 --- a/examples/STM32F4Discovery/TestSpi/system_stm32f4xx.c +++ /dev/null @@ -1,566 +0,0 @@ -/** - ****************************************************************************** - * @file system_stm32f4xx.c - * @author MCD Application Team - * @version V1.0.0 - * @date 19-September-2011 - * @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File. - * This file contains the system clock configuration for STM32F4xx devices, - * and is generated by the clock configuration tool - * stm32f4xx_Clock_Configuration_V1.0.0.xls - * - * 1. This file provides two functions and one global variable to be called from - * user application: - * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier - * and Divider factors, AHB/APBx prescalers and Flash settings), - * depending on the configuration made in the clock xls tool. - * This function is called at startup just after reset and - * before branch to main program. This call is made inside - * the "startup_stm32f4xx.s" file. - * - * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used - * by the user application to setup the SysTick - * timer or configure other parameters. - * - * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must - * be called whenever the core clock is changed - * during program execution. - * - * 2. After each device reset the HSI (16 MHz) is used as system clock source. - * Then SystemInit() function is called, in "startup_stm32f4xx.s" file, to - * configure the system clock before to branch to main program. - * - * 3. If the system clock source selected by user fails to startup, the SystemInit() - * function will do nothing and HSI still used as system clock source. User can - * add some code to deal with this issue inside the SetSysClock() function. - * - * 4. The default value of HSE crystal is set to 8 MHz, refer to "HSE_VALUE" define - * in "stm32f4xx.h" file. When HSE is used as system clock source, directly or - * through PLL, and you are using different crystal you have to adapt the HSE - * value to your own configuration. - * - * 5. This file configures the system clock as follows: - *============================================================================= - *============================================================================= - * Supported STM32F4xx device revision | Rev A - *----------------------------------------------------------------------------- - * System Clock source | PLL (HSE) - *----------------------------------------------------------------------------- - * SYSCLK(Hz) | 168000000 - *----------------------------------------------------------------------------- - * HCLK(Hz) | 168000000 - *----------------------------------------------------------------------------- - * AHB Prescaler | 1 - *----------------------------------------------------------------------------- - * APB1 Prescaler | 4 - *----------------------------------------------------------------------------- - * APB2 Prescaler | 2 - *----------------------------------------------------------------------------- - * HSE Frequency(Hz) | 8000000 - *----------------------------------------------------------------------------- - * PLL_M | 8 - *----------------------------------------------------------------------------- - * PLL_N | 336 - *----------------------------------------------------------------------------- - * PLL_P | 2 - *----------------------------------------------------------------------------- - * PLL_Q | 7 - *----------------------------------------------------------------------------- - * PLLI2S_N | 192 - *----------------------------------------------------------------------------- - * PLLI2S_R | 5 - *----------------------------------------------------------------------------- - * I2S input clock(Hz) | 38400000 - *----------------------------------------------------------------------------- - * VDD(V) | 3.3 - *----------------------------------------------------------------------------- - * High Performance mode | Enabled - *----------------------------------------------------------------------------- - * Flash Latency(WS) | 5 - *----------------------------------------------------------------------------- - * Prefetch Buffer | OFF - *----------------------------------------------------------------------------- - * Instruction cache | ON - *----------------------------------------------------------------------------- - * Data cache | ON - *----------------------------------------------------------------------------- - * Require 48MHz for USB OTG FS, | Enabled - * SDIO and RNG clock | - *----------------------------------------------------------------------------- - *============================================================================= - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - -/** @addtogroup CMSIS - * @{ - */ - -/** @addtogroup stm32f4xx_system - * @{ - */ - -/** @addtogroup STM32F4xx_System_Private_Includes - * @{ - */ - -#include "stm32f4xx.h" - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_TypesDefinitions - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Defines - * @{ - */ - -/*!< Uncomment the following line if you need to use external SRAM mounted - on STM324xG_EVAL board as data memory */ -/* #define DATA_IN_ExtSRAM */ - -/*!< Uncomment the following line if you need to relocate your vector Table in - Internal SRAM. */ -/* #define VECT_TAB_SRAM */ -#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. - This value must be a multiple of 0x200. */ - - -/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */ -#define PLL_M 8 -#define PLL_N 336 - -/* SYSCLK = PLL_VCO / PLL_P */ -#define PLL_P 2 - -/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */ -#define PLL_Q 7 - -/* PLLI2S_VCO = (HSE_VALUE Or HSI_VALUE / PLL_M) * PLLI2S_N - I2SCLK = PLLI2S_VCO / PLLI2S_R */ -#define PLLI2S_N 192 -#define PLLI2S_R 5 - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Macros - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Variables - * @{ - */ - - uint32_t SystemCoreClock = 168000000; - - __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_FunctionPrototypes - * @{ - */ - -static void SetSysClock(void); -#ifdef DATA_IN_ExtSRAM - static void SystemInit_ExtMemCtl(void); -#endif /* DATA_IN_ExtSRAM */ - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Functions - * @{ - */ - -/** - * @brief Setup the microcontroller system - * Initialize the Embedded Flash Interface, the PLL and update the - * SystemFrequency variable. - * @param None - * @retval None - */ -void SystemInit(void) -{ - /* Reset the RCC clock configuration to the default reset state ------------*/ - /* Set HSION bit */ - RCC->CR |= (uint32_t)0x00000001; - - /* Reset CFGR register */ - RCC->CFGR = 0x00000000; - - /* Reset HSEON, CSSON and PLLON bits */ - RCC->CR &= (uint32_t)0xFEF6FFFF; - - /* Reset PLLCFGR register */ - RCC->PLLCFGR = 0x24003010; - - /* Reset HSEBYP bit */ - RCC->CR &= (uint32_t)0xFFFBFFFF; - - /* Disable all interrupts */ - RCC->CIR = 0x00000000; - -#ifdef DATA_IN_ExtSRAM - SystemInit_ExtMemCtl(); -#endif /* DATA_IN_ExtSRAM */ - - /* Configure the System clock source, PLL Multiplier and Divider factors, - AHB/APBx prescalers and Flash settings ----------------------------------*/ - SetSysClock(); - - /* Configure the Vector Table location add offset address ------------------*/ -#ifdef VECT_TAB_SRAM - SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ -#else - SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ -#endif -} - -/** - * @brief Update SystemCoreClock variable according to Clock Register Values. - * The SystemCoreClock variable contains the core clock (HCLK), it can - * be used by the user application to setup the SysTick timer or configure - * other parameters. - * - * @note Each time the core clock (HCLK) changes, this function must be called - * to update SystemCoreClock variable value. Otherwise, any configuration - * based on this variable will be incorrect. - * - * @note - The system frequency computed by this function is not the real - * frequency in the chip. It is calculated based on the predefined - * constant and the selected clock source: - * - * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) - * - * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) - * - * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) - * or HSI_VALUE(*) multiplied/divided by the PLL factors. - * - * (*) HSI_VALUE is a constant defined in stm32f4xx.h file (default value - * 16 MHz) but the real value may vary depending on the variations - * in voltage and temperature. - * - * (**) HSE_VALUE is a constant defined in stm32f4xx.h file (default value - * 25 MHz), user has to ensure that HSE_VALUE is same as the real - * frequency of the crystal used. Otherwise, this function may - * have wrong result. - * - * - The result of this function could be not correct when using fractional - * value for HSE crystal. - * - * @param None - * @retval None - */ -void SystemCoreClockUpdate(void) -{ - uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2; - - /* Get SYSCLK source -------------------------------------------------------*/ - tmp = RCC->CFGR & RCC_CFGR_SWS; - - switch (tmp) - { - case 0x00: /* HSI used as system clock source */ - SystemCoreClock = HSI_VALUE; - break; - case 0x04: /* HSE used as system clock source */ - SystemCoreClock = HSE_VALUE; - break; - case 0x08: /* PLL used as system clock source */ - - /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N - SYSCLK = PLL_VCO / PLL_P - */ - pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22; - pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM; - - if (pllsource != 0) - { - /* HSE used as PLL clock source */ - pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6); - } - else - { - /* HSI used as PLL clock source */ - pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6); - } - - pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2; - SystemCoreClock = pllvco/pllp; - break; - default: - SystemCoreClock = HSI_VALUE; - break; - } - /* Compute HCLK frequency --------------------------------------------------*/ - /* Get HCLK prescaler */ - tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; - /* HCLK frequency */ - SystemCoreClock >>= tmp; -} - -/** - * @brief Configures the System clock source, PLL Multiplier and Divider factors, - * AHB/APBx prescalers and Flash settings - * @Note This function should be called only once the RCC clock configuration - * is reset to the default reset state (done in SystemInit() function). - * @param None - * @retval None - */ -static void SetSysClock(void) -{ -/******************************************************************************/ -/* PLL (clocked by HSE) used as System clock source */ -/******************************************************************************/ - __IO uint32_t StartUpCounter = 0, HSEStatus = 0; - - /* Enable HSE */ - RCC->CR |= ((uint32_t)RCC_CR_HSEON); - - /* Wait till HSE is ready and if Time out is reached exit */ - do - { - HSEStatus = RCC->CR & RCC_CR_HSERDY; - StartUpCounter++; - } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); - - if ((RCC->CR & RCC_CR_HSERDY) != RESET) - { - HSEStatus = (uint32_t)0x01; - } - else - { - HSEStatus = (uint32_t)0x00; - } - - if (HSEStatus == (uint32_t)0x01) - { - /* Enable high performance mode, System frequency up to 168 MHz */ - RCC->APB1ENR |= RCC_APB1ENR_PWREN; - PWR->CR |= PWR_CR_PMODE; - - /* HCLK = SYSCLK / 1*/ - RCC->CFGR |= RCC_CFGR_HPRE_DIV1; - - /* PCLK2 = HCLK / 2*/ - RCC->CFGR |= RCC_CFGR_PPRE2_DIV2; - - /* PCLK1 = HCLK / 4*/ - RCC->CFGR |= RCC_CFGR_PPRE1_DIV4; - - /* Configure the main PLL */ - RCC->PLLCFGR = PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) | - (RCC_PLLCFGR_PLLSRC_HSE) | (PLL_Q << 24); - - /* Enable the main PLL */ - RCC->CR |= RCC_CR_PLLON; - - /* Wait till the main PLL is ready */ - while((RCC->CR & RCC_CR_PLLRDY) == 0) - { - } - - /* Configure Flash prefetch, Instruction cache, Data cache and wait state */ - FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS; - - /* Select the main PLL as system clock source */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); - RCC->CFGR |= RCC_CFGR_SW_PLL; - - /* Wait till the main PLL is used as system clock source */ - while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL); - { - } - } - else - { /* If HSE fails to start-up, the application will have wrong clock - configuration. User can add here some code to deal with this error */ - } - -/******************************************************************************/ -/* I2S clock configuration */ -/******************************************************************************/ - /* PLLI2S clock used as I2S clock source */ - RCC->CFGR &= ~RCC_CFGR_I2SSRC; - - /* Configure PLLI2S */ - RCC->PLLI2SCFGR = (PLLI2S_N << 6) | (PLLI2S_R << 28); - - /* Enable PLLI2S */ - RCC->CR |= ((uint32_t)RCC_CR_PLLI2SON); - - /* Wait till PLLI2S is ready */ - while((RCC->CR & RCC_CR_PLLI2SRDY) == 0) - { - } -} - -/** - * @brief Setup the external memory controller. Called in startup_stm32f4xx.s - * before jump to __main - * @param None - * @retval None - */ -#ifdef DATA_IN_ExtSRAM -/** - * @brief Setup the external memory controller. - * Called in startup_stm32f4xx.s before jump to main. - * This function configures the external SRAM mounted on STM324xG_EVAL board - * This SRAM will be used as program data memory (including heap and stack). - * @param None - * @retval None - */ -void SystemInit_ExtMemCtl(void) -{ -/*-- GPIOs Configuration -----------------------------------------------------*/ -/* - +-------------------+--------------------+------------------+------------------+ - + SRAM pins assignment + - +-------------------+--------------------+------------------+------------------+ - | PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 | - | PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 | - | PD4 <-> FSMC_NOE | PE3 <-> FSMC_A19 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 | - | PD5 <-> FSMC_NWE | PE4 <-> FSMC_A20 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 | - | PD8 <-> FSMC_D13 | PE7 <-> FSMC_D4 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 | - | PD9 <-> FSMC_D14 | PE8 <-> FSMC_D5 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 | - | PD10 <-> FSMC_D15 | PE9 <-> FSMC_D6 | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 | - | PD11 <-> FSMC_A16 | PE10 <-> FSMC_D7 | PF13 <-> FSMC_A7 |------------------+ - | PD12 <-> FSMC_A17 | PE11 <-> FSMC_D8 | PF14 <-> FSMC_A8 | - | PD13 <-> FSMC_A18 | PE12 <-> FSMC_D9 | PF15 <-> FSMC_A9 | - | PD14 <-> FSMC_D0 | PE13 <-> FSMC_D10 |------------------+ - | PD15 <-> FSMC_D1 | PE14 <-> FSMC_D11 | - | | PE15 <-> FSMC_D12 | - +-------------------+--------------------+ -*/ - /* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */ - RCC->AHB1ENR = 0x00000078; - - /* Connect PDx pins to FSMC Alternate function */ - GPIOD->AFR[0] = 0x00cc00cc; - GPIOD->AFR[1] = 0xcc0ccccc; - /* Configure PDx pins in Alternate function mode */ - GPIOD->MODER = 0xaaaa0a0a; - /* Configure PDx pins speed to 100 MHz */ - GPIOD->OSPEEDR = 0xffff0f0f; - /* Configure PDx pins Output type to push-pull */ - GPIOD->OTYPER = 0x00000000; - /* No pull-up, pull-down for PDx pins */ - GPIOD->PUPDR = 0x00000000; - - /* Connect PEx pins to FSMC Alternate function */ - GPIOE->AFR[0] = 0xc00cc0cc; - GPIOE->AFR[1] = 0xcccccccc; - /* Configure PEx pins in Alternate function mode */ - GPIOE->MODER = 0xaaaa828a; - /* Configure PEx pins speed to 100 MHz */ - GPIOE->OSPEEDR = 0xffffc3cf; - /* Configure PEx pins Output type to push-pull */ - GPIOE->OTYPER = 0x00000000; - /* No pull-up, pull-down for PEx pins */ - GPIOE->PUPDR = 0x00000000; - - /* Connect PFx pins to FSMC Alternate function */ - GPIOF->AFR[0] = 0x00cccccc; - GPIOF->AFR[1] = 0xcccc0000; - /* Configure PFx pins in Alternate function mode */ - GPIOF->MODER = 0xaa000aaa; - /* Configure PFx pins speed to 100 MHz */ - GPIOF->OSPEEDR = 0xff000fff; - /* Configure PFx pins Output type to push-pull */ - GPIOF->OTYPER = 0x00000000; - /* No pull-up, pull-down for PFx pins */ - GPIOF->PUPDR = 0x00000000; - - /* Connect PGx pins to FSMC Alternate function */ - GPIOG->AFR[0] = 0x00cccccc; - GPIOG->AFR[1] = 0x000000c0; - /* Configure PGx pins in Alternate function mode */ - GPIOG->MODER = 0x00080aaa; - /* Configure PGx pins speed to 100 MHz */ - GPIOG->OSPEEDR = 0x000c0fff; - /* Configure PGx pins Output type to push-pull */ - GPIOG->OTYPER = 0x00000000; - /* No pull-up, pull-down for PGx pins */ - GPIOG->PUPDR = 0x00000000; - -/*-- FSMC Configuration ------------------------------------------------------*/ - /* Enable the FSMC interface clock */ - RCC->AHB3ENR = 0x00000001; - - /* Configure and enable Bank1_SRAM2 */ - FSMC_Bank1->BTCR[2] = 0x00001015; - FSMC_Bank1->BTCR[3] = 0x00010603;//0x00010400; - FSMC_Bank1E->BWTR[2] = 0x0fffffff; -/* - Bank1_SRAM2 is configured as follow: - - p.FSMC_AddressSetupTime = 3;//0; - p.FSMC_AddressHoldTime = 0; - p.FSMC_DataSetupTime = 6;//4; - p.FSMC_BusTurnAroundDuration = 1; - p.FSMC_CLKDivision = 0; - p.FSMC_DataLatency = 0; - p.FSMC_AccessMode = FSMC_AccessMode_A; - - FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; - FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; - FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; - FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; - FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; - FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; - FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; - FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; - FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; - FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; - FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; - FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; - FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; - FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; - FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; -*/ - -} -#endif /* DATA_IN_ExtSRAM */ - - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ - diff --git a/examples/STM32F4Discovery/TestStdUart/TestStdUart.pro b/examples/STM32F4Discovery/TestStdUart/TestStdUart.pro deleted file mode 100644 --- a/examples/STM32F4Discovery/TestStdUart/TestStdUart.pro +++ /dev/null @@ -1,14 +0,0 @@ -TEMPLATE = app -ARCH = stm32f4-arm-none-eabi-gcc -TARGET = stm32f4DiscoveryTestStdUart -BSP = STM32F4Discovery - -LIBS += UART GPIO STREAMDEVICES UHANDLE UCSTRINGS CPU - -SOURCES += main.c - - - -HEADERS += - - diff --git a/examples/STM32F4Discovery/TestStdUart/bin/stm32f4DiscoveryTestStdUart.elf b/examples/STM32F4Discovery/TestStdUart/bin/stm32f4DiscoveryTestStdUart.elf deleted file mode 100644 index 2018e13254ae91afcd3a7a1b4158a8f75182fa17..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 GIT binary patch literal 0 Hc$@ -#include -#include -#include -#include -#include -#include -#include -#define delay for(volatile int i=0;i<1024*256;i++) -//streamdevice* stdo; - -int main() -{ - - gpio_t gpio1,gpio2,gpio3; - gpio1 = gpioopen(PD13); - gpio2 = gpioopen(PD14); - gpio3 = gpioopen(PD15); - gpiosetdir(&gpio1,gpiooutdir); - gpiosetdir(&gpio2,gpiooutdir); - gpiosetdir(&gpio3,gpiooutdir); - //libucprintf("test\n\r"); - int i=0; - printf("hello world\n\r"); - printf("hello world\n\r"); - printf("Value Float=%f\n\r",0.23); - uart_t* uart1 = malloc(sizeof(uart_t)); - free(uart1); - FILE *test=fopen("UART3","w+"); - uartopenandconfig(2,uart1,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); - fprintf(test,"Value Float=%f\n\r",0.23); - while(1) - { - gpioset(gpio1); - delay; - gpioset(gpio2); - delay; - gpioset(gpio3); - delay; - gpioclr(gpio1); - delay; - gpioclr(gpio2); - delay; - gpioclr(gpio3); - delay; - //uartputc(&uart1,0x5A); - //spiputw(&spi1,0x0F); - //libucfprintf(&fd1,"i= %d 0x%x\n\r",i,i); - i++; - //uartputc(&Xbee,i++); - } - return 0; -} - - - - - - diff --git a/examples/STM32F4Discovery/blink/bin/stm32f4DiscoveryBlink.elf b/examples/STM32F4Discovery/blink/bin/stm32f4DiscoveryBlink.elf deleted file mode 100644 index 14aa6ae962d71d2aea2571bffec5880a01ad1d6b..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 GIT binary patch literal 0 Hc$@ - - - -int main() -{ - while(1) - { - for(volatile int i=0;i<1024*1024;i++); - GREENLEDON; - ORANGELEDOFF; - REDLEDOFF; - BLUELEDOFF; - for(volatile int i=0;i<1024*1024;i++); - GREENLEDOFF; - ORANGELEDON; - REDLEDOFF; - BLUELEDOFF; - for(volatile int i=0;i<1024*1024;i++); - GREENLEDOFF; - ORANGELEDOFF; - REDLEDON; - BLUELEDOFF; - for(volatile int i=0;i<1024*1024;i++); - GREENLEDOFF; - ORANGELEDOFF; - REDLEDOFF; - BLUELEDON; - } -} diff --git a/examples/STM32F4Discovery/blink2/bin/stm32f4DiscoveryBlink.elf b/examples/STM32F4Discovery/blink2/bin/stm32f4DiscoveryBlink.elf deleted file mode 100644 index 7d268ab0ee2324f066cfd503257a05a2a2a214d3..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 GIT binary patch literal 0 Hc$@
© COPYRIGHT 2011 STMicroelectronics
- ****************************************************************************** - */ -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - - -//Library config for this project!!!!!!!!!!! -#include "stm32f4xx_conf.h" - -/** @addtogroup STM32F4-Discovery_Demo - * @{ - */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ - -#define TESTRESULT_ADDRESS 0x080FFFFC -#define ALLTEST_PASS 0x00000000 -#define ALLTEST_FAIL 0x55555555 - -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED - #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment = 4 - #endif -#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ -//__ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev __ALIGN_END; - -uint16_t PrescalerValue = 0; - -__IO uint32_t TimingDelay; -__IO uint8_t DemoEnterCondition = 0x00; -__IO uint8_t UserButtonPressed = 0x00; -//LIS302DL_InitTypeDef LIS302DL_InitStruct; -LIS302DL_FilterConfigTypeDef LIS302DL_FilterStruct; -__IO int8_t X_Offset, Y_Offset, Z_Offset = 0x00; -uint8_t Buffer[6]; - -/* Private function prototypes -----------------------------------------------*/ -//static uint32_t Demo_USBConfig(void); -static void TIM4_Config(void); -static void Demo_Exec(void); - -/* Private functions ---------------------------------------------------------*/ - -/** - * @brief Main program. - * @param None - * @retval None - */ -int main(void) -{ - RCC_ClocksTypeDef RCC_Clocks; - - /* Initialize LEDs and User_Button on STM32F4-Discovery --------------------*/ - STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI); - - STM_EVAL_LEDInit(LED4); - STM_EVAL_LEDInit(LED3); - STM_EVAL_LEDInit(LED5); - STM_EVAL_LEDInit(LED6); - - /* SysTick end of count event each 10ms */ - /*RCC_GetClocksFreq(&RCC_Clocks); - SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);*/ - STM_EVAL_LEDOn(LED4); - STM_EVAL_LEDOn(LED3); - STM_EVAL_LEDOn(LED5); - STM_EVAL_LEDOn(LED6); - - while(1) - { - for(volatile int i =0;i<1024*1024;i++); - STM_EVAL_LEDOn(LED4); - STM_EVAL_LEDOn(LED3); - STM_EVAL_LEDOn(LED5); - STM_EVAL_LEDOn(LED6); - for(volatile int i =0;i<1024*1024;i++); - STM_EVAL_LEDOff(LED4); - STM_EVAL_LEDOff(LED3); - STM_EVAL_LEDOff(LED5); - STM_EVAL_LEDOff(LED6); - } -} - -/** - * @brief Execute the demo application. - * @param None - * @retval None - */ -static void Demo_Exec(void) -{ - RCC_ClocksTypeDef RCC_Clocks; - uint8_t togglecounter = 0x00; - - while(1) - { - DemoEnterCondition = 0x00; - - /* Reset UserButton_Pressed variable */ - UserButtonPressed = 0x00; - - /* Initialize LEDs to be managed by GPIO */ - STM_EVAL_LEDInit(LED4); - STM_EVAL_LEDInit(LED3); - STM_EVAL_LEDInit(LED5); - STM_EVAL_LEDInit(LED6); - - /* SysTick end of count event each 10ms */ - RCC_GetClocksFreq(&RCC_Clocks); - SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); - - /* Turn OFF all LEDs */ - STM_EVAL_LEDOff(LED4); - STM_EVAL_LEDOff(LED3); - STM_EVAL_LEDOff(LED5); - STM_EVAL_LEDOff(LED6); - - /* Waiting User Button is pressed */ - while (UserButtonPressed == 0x00) - { - /* Toggle LED4 */ - STM_EVAL_LEDToggle(LED4); - Delay(10); - /* Toggle LED4 */ - STM_EVAL_LEDToggle(LED3); - Delay(10); - /* Toggle LED4 */ - STM_EVAL_LEDToggle(LED5); - Delay(10); - /* Toggle LED4 */ - STM_EVAL_LEDToggle(LED6); - Delay(10); - togglecounter ++; - if (togglecounter == 0x10) - { - togglecounter = 0x00; - while (togglecounter < 0x10) - { - STM_EVAL_LEDToggle(LED4); - STM_EVAL_LEDToggle(LED3); - STM_EVAL_LEDToggle(LED5); - STM_EVAL_LEDToggle(LED6); - Delay(10); - togglecounter ++; - } - togglecounter = 0x00; - } - } - - /* Waiting User Button is Released */ - while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET) - {} - UserButtonPressed = 0x00; - - /* TIM4 channels configuration */ - TIM4_Config(); - - /* Disable all Timer4 channels */ - TIM_CCxCmd(TIM4, TIM_Channel_1, DISABLE); - TIM_CCxCmd(TIM4, TIM_Channel_2, DISABLE); - TIM_CCxCmd(TIM4, TIM_Channel_3, DISABLE); - TIM_CCxCmd(TIM4, TIM_Channel_4, DISABLE); - - /* MEMS configuration */ - /* LIS302DL_InitStruct.Power_Mode = LIS302DL_LOWPOWERMODE_ACTIVE; - LIS302DL_InitStruct.Output_DataRate = LIS302DL_DATARATE_100; - LIS302DL_InitStruct.Axes_Enable = LIS302DL_XYZ_ENABLE; - LIS302DL_InitStruct.Full_Scale = LIS302DL_FULLSCALE_2_3; - LIS302DL_InitStruct.Self_Test = LIS302DL_SELFTEST_NORMAL; - LIS302DL_Init(&LIS302DL_InitStruct);*/ - - /* Required delay for the MEMS Accelerometre: Turn-on time = 3/Output data Rate - = 3/100 = 30ms */ - Delay(30); - - DemoEnterCondition = 0x01; - /* MEMS High Pass Filter configuration */ - /*LIS302DL_FilterStruct.HighPassFilter_Data_Selection = LIS302DL_FILTEREDDATASELECTION_OUTPUTREGISTER; - LIS302DL_FilterStruct.HighPassFilter_CutOff_Frequency = LIS302DL_HIGHPASSFILTER_LEVEL_1; - LIS302DL_FilterStruct.HighPassFilter_Interrupt = LIS302DL_HIGHPASSFILTERINTERRUPT_1_2; - LIS302DL_FilterConfig(&LIS302DL_FilterStruct); - - LIS302DL_Read(Buffer, LIS302DL_OUT_X_ADDR, 6); - X_Offset = Buffer[0]; - Y_Offset = Buffer[2]; - Z_Offset = Buffer[4];*/ - - /* USB configuration */ -// Demo_USBConfig(); - - /* Waiting User Button is pressed */ - while (UserButtonPressed == 0x00) - {} - - /* Waiting User Button is Released */ - while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET) - {} - - /* Disable SPI1 used to drive the MEMS accelerometre */ - SPI_Cmd(LIS302DL_SPI, DISABLE); - - /* Disconnect the USB device */ - //DCD_DevDisconnect(&USB_OTG_dev); - //USB_OTG_StopDevice(&USB_OTG_dev); - } -} - -/** - * @brief Initializes the USB for the demonstration application. - * @param None - * @retval None - */ -/*static uint32_t Demo_USBConfig(void) -{ - USBD_Init(&USB_OTG_dev, - USB_OTG_FS_CORE_ID, - &USR_desc, - &USBD_HID_cb, - &USR_cb); - - return 0; -}*/ - -/** - * @brief Configures the TIM Peripheral. - * @param None - * @retval None - */ -static void TIM4_Config(void) -{ - GPIO_InitTypeDef GPIO_InitStructure; - TIM_OCInitTypeDef TIM_OCInitStructure; - TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; - - /* --------------------------- System Clocks Configuration -----------------*/ - /* TIM4 clock enable */ - RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); - - /* GPIOD clock enable */ - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); - - /*-------------------------- GPIO Configuration ----------------------------*/ - /* GPIOD Configuration: Pins 12, 13, 14 and 15 in output push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_Init(GPIOD, &GPIO_InitStructure); - - /* Connect TIM4 pins to AF2 */ - GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_TIM4); - GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_TIM4); - GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_TIM4); - GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_TIM4); - - /* ----------------------------------------------------------------------- - TIM4 Configuration: Output Compare Timing Mode: - - In this example TIM4 input clock (TIM4CLK) is set to 2 * APB1 clock (PCLK1), - since APB1 prescaler is different from 1 (APB1 Prescaler = 4, see system_stm32f4xx.c file). - TIM4CLK = 2 * PCLK1 - PCLK1 = HCLK / 4 - => TIM4CLK = 2*(HCLK / 4) = HCLK/2 = SystemCoreClock/2 - - To get TIM4 counter clock at 2 KHz, the prescaler is computed as follows: - Prescaler = (TIM4CLK / TIM1 counter clock) - 1 - Prescaler = (168 MHz/(2 * 2 KHz)) - 1 = 41999 - - To get TIM4 output clock at 1 Hz, the period (ARR)) is computed as follows: - ARR = (TIM4 counter clock / TIM4 output clock) - 1 - = 1999 - - TIM4 Channel1 duty cycle = (TIM4_CCR1/ TIM4_ARR)* 100 = 50% - TIM4 Channel2 duty cycle = (TIM4_CCR2/ TIM4_ARR)* 100 = 50% - TIM4 Channel3 duty cycle = (TIM4_CCR3/ TIM4_ARR)* 100 = 50% - TIM4 Channel4 duty cycle = (TIM4_CCR4/ TIM4_ARR)* 100 = 50% - - ==> TIM4_CCRx = TIM4_ARR/2 = 1000 (where x = 1, 2, 3 and 4). - - Note: - SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file. - Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate() - function to update SystemCoreClock variable value. Otherwise, any configuration - based on this variable will be incorrect. - ----------------------------------------------------------------------- */ - - - /* Compute the prescaler value */ - PrescalerValue = (uint16_t) ((SystemCoreClock /2) / 2000) - 1; - - /* Time base configuration */ - TIM_TimeBaseStructure.TIM_Period = TIM_ARR; - TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; - TIM_TimeBaseStructure.TIM_ClockDivision = 0; - TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; - TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); - - /* Enable TIM4 Preload register on ARR */ - TIM_ARRPreloadConfig(TIM4, ENABLE); - - /* TIM PWM1 Mode configuration: Channel */ - TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; - TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; - TIM_OCInitStructure.TIM_Pulse = TIM_CCR; - TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; - - /* Output Compare PWM1 Mode configuration: Channel1 */ - TIM_OC1Init(TIM4, &TIM_OCInitStructure); - TIM_CCxCmd(TIM4, TIM_Channel_1, DISABLE); - - TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable); - - /* Output Compare PWM1 Mode configuration: Channel2 */ - TIM_OC2Init(TIM4, &TIM_OCInitStructure); - TIM_CCxCmd(TIM4, TIM_Channel_2, DISABLE); - - TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable); - - /* Output Compare PWM1 Mode configuration: Channel3 */ - TIM_OC3Init(TIM4, &TIM_OCInitStructure); - TIM_CCxCmd(TIM4, TIM_Channel_3, DISABLE); - - TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable); - - /* Output Compare PWM1 Mode configuration: Channel4 */ - TIM_OC4Init(TIM4, &TIM_OCInitStructure); - TIM_CCxCmd(TIM4, TIM_Channel_4, DISABLE); - - TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable); - - /* TIM4 enable counter */ - TIM_Cmd(TIM4, ENABLE); -} - -/** - * @brief Inserts a delay time. - * @param nTime: specifies the delay time length, in 10 ms. - * @retval None - */ -void Delay(__IO uint32_t nTime) -{ - TimingDelay = nTime; - - while(TimingDelay != 0); -} - -/** - * @brief Decrements the TimingDelay variable. - * @param None - * @retval None - */ -void TimingDelay_Decrement(void) -{ - if (TimingDelay != 0x00) - { - TimingDelay--; - } -} - -/** - * @brief This function handles the test program fail. - * @param None - * @retval None - */ -void Fail_Handler(void) -{ - /* Erase last sector */ - FLASH_EraseSector(FLASH_Sector_11, VoltageRange_3); - /* Write FAIL code at last word in the flash memory */ - FLASH_ProgramWord(TESTRESULT_ADDRESS, ALLTEST_FAIL); - - while(1) - { - /* Toggle Red LED */ - STM_EVAL_LEDToggle(LED5); - Delay(5); - } -} - -/** - * @brief MEMS accelerometre management of the timeout situation. - * @param None. - * @retval None. - */ -uint32_t LIS302DL_TIMEOUT_UserCallback(void) -{ - /* MEMS Accelerometer Timeout error occured during Test program execution */ - if (DemoEnterCondition == 0x00) - { - /* Timeout error occured for SPI TXE/RXNE flags waiting loops.*/ - Fail_Handler(); - } - /* MEMS Accelerometer Timeout error occured during Demo execution */ - else - { - while (1) - { - } - } - return 0; -} - -#ifdef USE_FULL_ASSERT - -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t* file, uint32_t line) -{ - /* User can add his own implementation to report the file name and line number, - ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - - /* Infinite loop */ - while (1) - { - } -} -#endif - -/** - * @} - */ - - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/blink2/main.h b/examples/STM32F4Discovery/blink2/main.h deleted file mode 100644 --- a/examples/STM32F4Discovery/blink2/main.h +++ /dev/null @@ -1,62 +0,0 @@ -/** - ****************************************************************************** - * @file main.h - * @author MCD Application Team - * @version V1.0.0 - * @date 19-September-2011 - * @brief Header for main.c module - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F4_DISCOVERY_DEMO_H -#define __STM32F4_DISCOVERY_DEMO_H - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4_discovery.h" -#include "stm32f4_discovery_audio_codec.h" -#include "stm32f4_discovery_lis302dl.h" -#include "selftest.h" -#include - - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* TIM2 Autoreload and Capture Compare register values */ -#define TIM_ARR (uint16_t)1999 -#define TIM_CCR (uint16_t)1000 - -/* MEMS Microphone SPI Interface */ -#define SPI_SCK_PIN GPIO_Pin_10 -#define SPI_SCK_GPIO_PORT GPIOB -#define SPI_SCK_GPIO_CLK RCC_AHB1Periph_GPIOB -#define SPI_SCK_SOURCE GPIO_PinSource10 -#define SPI_SCK_AF GPIO_AF_SPI2 - -#define SPI_MOSI_PIN GPIO_Pin_3 -#define SPI_MOSI_GPIO_PORT GPIOC -#define SPI_MOSI_GPIO_CLK RCC_AHB1Periph_GPIOC -#define SPI_MOSI_SOURCE GPIO_PinSource3 -#define SPI_MOSI_AF GPIO_AF_SPI2 - -/* Exported macro ------------------------------------------------------------*/ -#define ABS(x) (x < 0) ? (-x) : x -#define MAX(a,b) (a < b) ? (b) : a -/* Exported functions ------------------------------------------------------- */ -void TimingDelay_Decrement(void); -void Delay(__IO uint32_t nTime); -void Fail_Handler(void); -#endif /* __STM32F4_DISCOVERY_DEMO_H */ - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/blink2/selftest.c b/examples/STM32F4Discovery/blink2/selftest.c deleted file mode 100644 --- a/examples/STM32F4Discovery/blink2/selftest.c +++ /dev/null @@ -1,808 +0,0 @@ -/** - ****************************************************************************** - * @file selftest.c - * @author MCD Application Team - * @version V1.0.0 - * @date 19-September-2011 - * @brief This file provides the hardware tests - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- */ - -/* Includes ------------------------------------------------------------------*/ -#include "selftest.h" - -//Library config for this project!!!!!!!!!!! -#include "stm32f4xx_conf.h" - - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -#define MEMS_PASSCONDITION 15 -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -/* Init Structure definition */ -RCC_ClocksTypeDef RCC_Clocks; -ADC_InitTypeDef ADC_InitStructure; -ADC_CommonInitTypeDef ADC_CommonInitStructure; - -__IO uint16_t ConvData1, ConvData2; -__IO uint16_t counter0 = 0, counter1 = 0, Idx = 0; -uint8_t ADC_Channel[2] = {ADC_Channel_2, ADC_Channel_3}; -uint8_t DACTest = 0; -uint8_t GPIO_Pin [2] = {GPIO_Pin_2, GPIO_Pin_3}; - -uint16_t count = 0, count1 = 24, Left_Right = 0; -const int16_t sinebuf[48] = {0, 4276, 8480, 12539, 16383, 19947, 23169, 25995, - 28377, 30272, 31650, 32486, 32767, 32486, 31650, 30272, - 28377, 25995, 23169, 19947, 16383, 12539, 8480, 4276, - 0, -4276, -8480, -12539, -16383, -19947, -23169, -25995, - -28377, -30272, -31650, -32486, -32767, -32486, -31650, -30272, - -28377, -25995, -23169, -19947, -16383, -12539, -8480, -4276 - }; -extern __IO uint32_t TimingDelay; - -extern LIS302DL_InitTypeDef LIS302DL_InitStruct; -extern LIS302DL_FilterConfigTypeDef LIS302DL_FilterStruct; - -extern __IO int8_t X_Offset, Y_Offset, Z_Offset; -extern uint8_t Buffer[6]; -/* Private function prototypes -----------------------------------------------*/ -/* Private functions ---------------------------------------------------------*/ -/** - * @brief Test MEMS Hardware. - * The main objectif of this test is to check the hardware connection of the - * MEMS peripheral. - * @param None - * @retval None - */ -void Accelerometer_MEMS_Test(void) -{ - uint8_t temp, memsteststatus = 0x00; - uint8_t xdata, ydata = 0; - - /* MEMS configuration ------------------------------------------------------*/ - /* Set configuration of LIS302DL*/ - /*LIS302DL_InitStruct.Power_Mode = LIS302DL_LOWPOWERMODE_ACTIVE; - LIS302DL_InitStruct.Output_DataRate = LIS302DL_DATARATE_100; - LIS302DL_InitStruct.Axes_Enable = LIS302DL_X_ENABLE | LIS302DL_Y_ENABLE; - LIS302DL_InitStruct.Full_Scale = LIS302DL_FULLSCALE_2_3; - LIS302DL_InitStruct.Self_Test = LIS302DL_SELFTEST_NORMAL; - LIS302DL_Init(&LIS302DL_InitStruct);*/ - - /* Set configuration of Internal High Pass Filter of LIS302DL*/ - /* LIS302DL_FilterStruct.HighPassFilter_Data_Selection = LIS302DL_FILTEREDDATASELECTION_OUTPUTREGISTER; - LIS302DL_FilterStruct.HighPassFilter_CutOff_Frequency = LIS302DL_HIGHPASSFILTER_LEVEL_1; - LIS302DL_FilterStruct.HighPassFilter_Interrupt = LIS302DL_HIGHPASSFILTERINTERRUPT_1_2; - LIS302DL_FilterConfig(&LIS302DL_FilterStruct);*/ - - /* Required delay for the MEMS Accelerometre: Turn-on time = 3/Output data Rate - = 3/100 = 30ms */ - Delay(30); - - /* Read WHO_AM_I register */ - //LIS302DL_Read(&temp, LIS302DL_WHO_AM_I_ADDR, 1); - - /* Check device identification register, this register should contains - the device identifier that for LIS302DL is set to 0x3B */ - if (temp != 0x3B) - { - Fail_Handler(); - } - - TimingDelay = 500; - /* Wait until detecting all MEMS direction or timeout */ - while((memsteststatus == 0x00)&&(TimingDelay != 0x00)) - { - //LIS302DL_Read(Buffer, LIS302DL_OUT_X_ADDR, 4); - xdata = ABS((int8_t)(Buffer[0])); - ydata = ABS((int8_t)(Buffer[2])); - /* Check test PASS condition */ - if ((xdata > MEMS_PASSCONDITION) || (ydata > MEMS_PASSCONDITION)) - { - /* MEMS Test PASS */ - memsteststatus = 0x01; - } - } - - /* MEMS test status: PASS */ - if(memsteststatus != 0x00) - { - /* Turn Green LED ON: signaling MEMS Test PASS */ - STM_EVAL_LEDOn(LED4); - - /* Waiting User Button is pressed */ - while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_RESET) - {} - - /* Waiting User Button is Released */ - while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET) - {} - - /* Turn Green LED OFF: signaling the end of MEMS Test and switching to - the next Sub Test */ - STM_EVAL_LEDOff(LED4); - } - /* MEMS test status: Timeout occurs */ - else - { - Fail_Handler(); - } -} - -/** - * @brief Test USB Hardware. - * The main objectif of this test is to check the hardware connection of the - * Audio and USB peripheral. - * @param None - * @retval None - */ -void USB_Test(void) -{ - GPIO_InitTypeDef GPIO_InitStructure; - - /******************************** USB Test **********************************/ - - /*----------------- Part1: without cables connected ------------------------*/ - - /* GPIOA, GPIOC and GPIOD clock enable */ - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC | \ - RCC_AHB1Periph_GPIOD, ENABLE); - - /* GPIOD Configuration: Pins 5 in output push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOD, &GPIO_InitStructure); - - /* Turn LED8 ON using PD5 */ - GPIO_ResetBits(GPIOD, GPIO_Pin_5); - - /* GPIOC Configuration: Pin 0 in output push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOC, &GPIO_InitStructure); - - /* GPIOA Configuration: Pin 9 in input pull-up */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* Turn LED7 ON using PC0 (5v) */ - GPIO_ResetBits(GPIOC, GPIO_Pin_0); - - /* Waiting delay 10ms */ - Delay(1); - - if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_9) == Bit_RESET) - { - Fail_Handler(); - } - - /* GPIOA Configuration: Pins 10 in output push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* Waiting delay 10ms */ - Delay(1); - - /* Check the ID level without cable connected */ - if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_10) == Bit_RESET) - { - Fail_Handler(); - } - - /* Turn LED7 OFF using PC0 */ - GPIO_SetBits(GPIOC, GPIO_Pin_0); - - /* GPIOA Configuration: Pins 11, 12 in input pull-up */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* GPIOA Configuration: Pin 9 in output push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - GPIO_ResetBits(GPIOA, GPIO_Pin_9); - - /* Waiting delay 10ms */ - Delay(1); - - /* Check PA11 and PA12 level without cable connected */ - if ((GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_11) == Bit_RESET) || \ - (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12) == Bit_RESET)) - { - Fail_Handler(); - } - - /* GPIOA Configuration: Pins 12 in input pull-up */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* GPIOA Configuration: Pin 11 in output push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - GPIO_ResetBits(GPIOA, GPIO_Pin_11); - - /* Waiting delay 10ms */ - Delay(1); - - /* Check PA12 level without cable connected */ - if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12) == Bit_RESET) - { - Fail_Handler(); - } - - /* GPIOA Configuration: Pins 11 in input pull-up */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* GPIOA Configuration: Pin 12 in output push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - GPIO_ResetBits(GPIOA, GPIO_Pin_12); - - /* Waiting delay 10ms */ - Delay(1); - - /* Check PA12 level without cable connected */ - if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_11) == Bit_RESET) - { - Fail_Handler(); - } - - /* GPIOA Configuration: Pins 9 in output push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* Turn LED7 ON using PA9 */ - GPIO_SetBits(GPIOA, GPIO_Pin_9); - - /* Turn Green LED ON: signaling Audio USB Test part1 PASS */ - STM_EVAL_LEDOn(LED4); - - /* Waiting User Button is pressed */ - while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_RESET) - {} - - /* Waiting User Button is Released */ - while (STM_EVAL_PBGetState(BUTTON_USER) != Bit_RESET) - {} - - /* Turn Green LED OFF: signaling the end of Audio USB Test part1 and switching to - the part2 */ - STM_EVAL_LEDOff(LED4); - - /* Turn LED7 OFF using PA9 */ - GPIO_ResetBits(GPIOA, GPIO_Pin_9); - - /* Turn LED8 OFF using PD5 */ - GPIO_SetBits(GPIOD, GPIO_Pin_5); - - /*--------------- Part2: with Audio USB cables connected ------------------*/ - - /*********************************** USB Test *******************************/ - /* Check the ID level with cable connected */ - if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_10) != Bit_RESET) - { - Fail_Handler(); - } - - /* GPIOA Configuration: Pins 11, 12 in input pull-down */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* GPIOA Configuration: Pin 9 in output push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - GPIO_SetBits(GPIOA, GPIO_Pin_9); - - /* Waiting delay 10ms */ - Delay(1); - - /* Check PA11 and PA12 level with cable connected */ - if ((GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_11) == Bit_RESET) || \ - (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12) == Bit_RESET)) - { - Fail_Handler(); - } - - /* GPIOA Configuration: Pins 9, 12 in input pull-down */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_12; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* GPIOA Configuration: Pin 11 in output push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - GPIO_SetBits(GPIOA, GPIO_Pin_11); - - /* Waiting delay 10ms */ - Delay(1); - - /* Check PA9 and PA12 level with cable connected */ - if ((GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_9) == Bit_RESET)|| \ - (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12) == Bit_RESET)) - { - Fail_Handler(); - } - - /* GPIOA Configuration: Pins 9, 11 in input pull-down */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_11; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* GPIOA Configuration: Pin 12 in output push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - GPIO_SetBits(GPIOA, GPIO_Pin_12); - - /* Waiting delay 10ms */ - Delay(1); - - /* Check PA9 and PA12 level with cable connected */ - if ((GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_9) == Bit_RESET)|| \ - (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_11) == Bit_RESET)) - { - Fail_Handler(); - } - - /* GPIOA Configuration: Pins 11, 12 in input pull-down */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* GPIOA Configuration: Pin 9 in output push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* Turn LED7 OFF using PA9 */ - GPIO_ResetBits(GPIOA, GPIO_Pin_9); -} - -/** - * @brief Test Audio Hardware. - * The main objectif of this test is to check the hardware connection of the - * Audio peripheral. - * @param None - * @retval None - */ -void Audio_Test(void) -{ - GPIO_InitTypeDef GPIO_InitStructure; - uint8_t audioteststatus = 0x00; - - RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); - RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE); - - /* Set the current audio interface: I2S or DAC */ - // EVAL_AUDIO_SetAudioInterface(AUDIO_INTERFACE_I2S); - - /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOs...) */ - /*if (EVAL_AUDIO_Init(OUTPUT_DEVICE_HEADPHONE, 87, I2S_AudioFreq_48k) !=0) - { - Fail_Handler(); - }*/ - /* I2S code to be exectued under the I2S interrupt */ - DACTest = 0; - - /* ADC Common Init */ - ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; - ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div8; - ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; - ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_20Cycles; - ADC_CommonInit(&ADC_CommonInitStructure); - - /* ADC peripherals Init */ - ADC_StructInit(&ADC_InitStructure); - ADC_InitStructure.ADC_Resolution = ADC_Resolution_8b; - ADC_InitStructure.ADC_ScanConvMode = DISABLE; - ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; - ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; - ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; - ADC_InitStructure.ADC_NbrOfConversion = 1; - ADC_Init(ADC1, &ADC_InitStructure); - - ADC_Init(ADC2, &ADC_InitStructure); - - /* Configure ADC Channels pin as analog input */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 ; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - counter1 = 0; - counter0 = 0; - audioteststatus = 0; - /* ADCperipheral[PerIdx] Regular Channel Config */ - ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 1, ADC_SampleTime_56Cycles); - /* ADCperipheral[PerIdx] Regular Channel Config */ - ADC_RegularChannelConfig(ADC2, ADC_Channel_3, 1, ADC_SampleTime_56Cycles); - /* Enable ADC1 */ - ADC_Cmd(ADC1, ENABLE); - ADC_Cmd(ADC2, ENABLE); - - TimingDelay = 500; - /* Wait until detecting 500 data*/ - while((audioteststatus == 0)&&(TimingDelay != 0)) - { - ADC_SoftwareStartConv(ADC1); - while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); - ConvData1 = ADC_GetConversionValue(ADC1); - - ADC_SoftwareStartConv(ADC2); - while(ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC) == RESET); - ConvData2 = ADC_GetConversionValue(ADC2); - - /* 1.75V equals to 150 */ - if ((ConvData1 > 150) && (ConvData2 < 10) && (counter1 != 500)) - { - counter1 ++; - } - if ((ConvData1 < 10) && (ConvData2 > 150) && (counter0 != 500)) - { - counter0 ++; - } - if((counter1 == 500) && (counter0 == 500)) - { - audioteststatus = 1; - } - } - - /* Disable ADC Peripherals */ - ADC_Cmd(ADC1, DISABLE); - ADC_Cmd(ADC2, DISABLE); - - /* Audio test status: FAIL */ - if(audioteststatus == 0) - { - Fail_Handler(); - } - - /*EVAL_AUDIO_DeInit(); - EVAL_AUDIO_SetAudioInterface(AUDIO_INTERFACE_DAC);*/ - /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOs...) */ - /* if (EVAL_AUDIO_Init(OUTPUT_DEVICE_HEADPHONE, 100, I2S_AudioFreq_48k) !=0) - { - Fail_Handler(); - }*/ - - /* DAC code to be exectued under the I2S interrupt */ - DACTest = 1; - counter1 = 0; - counter0 = 0; - audioteststatus = 0; - - /* Enable ADC1 */ - ADC_Cmd(ADC1, ENABLE); - ADC_Cmd(ADC2, ENABLE); - - TimingDelay = 500; - /* Wait until detecting 50 data*/ - while((audioteststatus == 0)&&(TimingDelay != 0)) - { - - ADC_SoftwareStartConv(ADC1); - while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); - - ConvData1 = ADC_GetConversionValue(ADC1); - - ADC_SoftwareStartConv(ADC2); - while(ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC) == RESET); - - ConvData2 = ADC_GetConversionValue(ADC2); - - /* 2.0V equals to 170 */ - if ((ConvData1 > 170) && (ConvData2 > 170) &&(counter1 != 500)) - { - counter1 ++; - } - if ((ConvData1 < 10) && (ConvData2 < 10) && (counter0 != 500)) - { - counter0 ++; - } - if((counter1 == 500) && (counter0 == 500)) - { - audioteststatus = 1; - } - } - - /* Audio test status: FAIL */ - if(audioteststatus == 0x00) - { - Fail_Handler(); - } - - /* Turn Green LED ON: signaling Audio USB Test part2 PASS */ - STM_EVAL_LEDOn(LED4); - - /* Waiting User_Button pressed */ - while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_RESET) - {} - - /* Turn Green LED OFF: signaling the end of Audio USB Test part2 */ - STM_EVAL_LEDOff(LED4); -} - -/** - * @brief Test Micophone MEMS Hardware. - * The main objectif of this test is to check the hardware connection of the - * Microphone MEMS peripheral. - * @param None - * @retval None - */ -void Microphone_MEMS_Test(void) -{ - uint16_t data = 0x00; - uint8_t index = 0x00; - I2S_InitTypeDef I2S_InitStructure; - GPIO_InitTypeDef GPIO_InitStructure; - - /* Enable the SPI clock */ - RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); - - /* Enable GPIO clocks */ - RCC_AHB1PeriphClockCmd(SPI_SCK_GPIO_CLK | SPI_MOSI_GPIO_CLK, ENABLE); - - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; - - /* SPI SCK pin configuration */ - GPIO_InitStructure.GPIO_Pin = SPI_SCK_PIN; - GPIO_Init(SPI_SCK_GPIO_PORT, &GPIO_InitStructure); - - /* Connect SPI pins to AF5 */ - GPIO_PinAFConfig(SPI_SCK_GPIO_PORT, SPI_SCK_SOURCE, SPI_SCK_AF); - - /* SPI MOSI pin configuration */ - GPIO_InitStructure.GPIO_Pin = SPI_MOSI_PIN; - GPIO_Init(SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); - - GPIO_PinAFConfig(SPI_MOSI_GPIO_PORT, SPI_MOSI_SOURCE, SPI_MOSI_AF); - - /* I2S configuration -------------------------------------------------------*/ - SPI_I2S_DeInit(SPI2); - I2S_InitStructure.I2S_AudioFreq = 64000; - I2S_InitStructure.I2S_Standard = I2S_Standard_MSB; - I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b; - I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low; - I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx; - I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable; - /* Initialize the I2S peripheral with the structure above */ - I2S_Init(SPI2, &I2S_InitStructure); - - /* Enable the I2S peripheral */ - I2S_Cmd(SPI2, ENABLE); - - /* Waiting until MEMS microphone ready : Wake-up Time */ - Delay(10); - - TimingDelay = 500; - /* Wait until detect the click on the MEMS microphone or TimeOut delay*/ - while((index < 30) && (TimingDelay != 0x00)) - { - /* Waiting RXNE Flag or TimeOut delay */ - while((SPI_I2S_GetFlagStatus(SPI2, SPI_FLAG_RXNE) == RESET)&& (TimingDelay != 0x00)) - {} - data = SPI_I2S_ReceiveData(SPI2); - if (data == 0xFFFF) - { - index++; - } - } - - /* MEMS microphone test status: Timeout occurs */ - if(index != 30) - { - Fail_Handler(); - } -} - -/*-------------------------------- - Callbacks implementation: - the callbacks prototypes are defined in the stm324xg_eval_audio_codec.h file - and their implementation should be done in the user code if they are needed. - Below some examples of callback implementations. - --------------------------------------------------------*/ -/** - * @brief Calculates the remaining file size and new position of the pointer. - * @param None - * @retval None - */ -void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size) -{ - /* Calculate the remaining audio data in the file and the new size - for the DMA transfer. If the Audio files size is less than the DMA max - data transfer size, so there is no calculation to be done, just restart - from the beginning of the file ... */ - /* Check if the end of file has been reached */ - -} - -/** - * @brief Manages the DMA Half Transfer complete interrupt. - * @param None - * @retval None - */ -void EVAL_AUDIO_HalfTransfer_CallBack(uint32_t pBuffer, uint32_t Size) -{ -#ifdef AUDIO_MAL_MODE_CIRCULAR - - /* Display message on the LCD screen */ - LCD_DisplayStringLine(Line8, " 1/2 Buffer Reached "); - -#endif /* AUDIO_MAL_MODE_CIRCULAR */ - - /* Generally this interrupt routine is used to load the buffer when - a streaming scheme is used: When first Half buffer is already transferred load - the new data to the first half of buffer while DMA is transferring data from - the second half. And when Transfer complete occurs, load the second half of - the buffer while the DMA is transferring from the first half ... */ - /* - ........... - */ -} -/** - * @brief Get next data sample callback - * @param None - * @retval Next data sample to be sent - */ -uint16_t EVAL_AUDIO_GetSampleCallBack(void) -{ - uint16_t data = 0; - - if (DACTest == 0) - { - if (Left_Right==0) - { - /* Get the next sample to be sent */ - data = sinebuf[count++]; - - if (count == 48) - { - count = 0x00; - } - Left_Right = 1; - } - else - { - /* Get the next sample to be sent */ - data = sinebuf[count1++]; - - if (count1 == 48) - { - count1 = 0x00; - } - Left_Right = 0; - } - } - else - { - /* Get the next sample to be sent */ - data = 32768 + sinebuf[count++]; - - if (count == 48) - { - count = 0x00; - } - } - return data; -} - - -/** - * @brief Manages the DMA FIFO error interrupt. - * @param None - * @retval None - */ -void EVAL_AUDIO_Error_CallBack(void* pData) -{ - /* Stop the program with an infinite loop */ - while (1) - {} - - /* could also generate a system reset to recover from the error */ - /* .... */ -} - -#ifndef USE_DEFAULT_TIMEOUT_CALLBACK -/** - * @brief Basic management of the timeout situation. - * @param None. - * @retval None. - */ -uint32_t Codec_TIMEOUT_UserCallback(void) -{ - /* Block communication and all processes */ - while (1) - { - } -} -#endif /* USE_DEFAULT_TIMEOUT_CALLBACK */ -/*----------------------------------------------------------------------------*/ - - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/blink2/selftest.h b/examples/STM32F4Discovery/blink2/selftest.h deleted file mode 100644 --- a/examples/STM32F4Discovery/blink2/selftest.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - ****************************************************************************** - * @file selftest.h - * @author MCD Application Team - * @version V1.0.0 - * @date 19-September-2011 - * @brief Header for selftest.c module - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __SELFTEST_H -#define __SELFTEST_H - -/* Includes ------------------------------------------------------------------*/ -#include -#include "main.h" -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ - -void Audio_Test(void); -void Accelerometer_MEMS_Test(void); -void USB_Test(void); -void Microphone_MEMS_Test(void); - -#endif /* __SELFTEST_H */ - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/blink2/startup_stm32f4xx.s b/examples/STM32F4Discovery/blink2/startup_stm32f4xx.s deleted file mode 100644 --- a/examples/STM32F4Discovery/blink2/startup_stm32f4xx.s +++ /dev/null @@ -1,509 +0,0 @@ -/** - ****************************************************************************** - * @file startup_stm32f4xx.s - * @author MCD Application Team - * @version V1.0.0 - * @date 30-September-2011 - * @brief STM32F4xx Devices vector table for RIDE7 toolchain. - * This module performs: - * - Set the initial SP - * - Set the initial PC == Reset_Handler, - * - Set the vector table entries with the exceptions ISR address - * - Configure the clock system and the external SRAM mounted on - * STM324xG-EVAL board to be used as data memory (optional, - * to be enabled by user) - * - Branches to main in the C library (which eventually - * calls main()). - * After Reset the Cortex-M4 processor is in Thread mode, - * priority is Privileged, and the Stack is set to Main. - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - - .syntax unified - .cpu cortex-m3 - .fpu softvfp - .thumb - -.global g_pfnVectors -.global Default_Handler - -/* start address for the initialization values of the .data section. -defined in linker script */ -.word _sidata -/* start address for the .data section. defined in linker script */ -.word _sdata -/* end address for the .data section. defined in linker script */ -.word _edata -/* start address for the .bss section. defined in linker script */ -.word _sbss -/* end address for the .bss section. defined in linker script */ -.word _ebss -/* stack used for SystemInit_ExtMemCtl; always internal RAM used */ - -/** - * @brief This is the code that gets called when the processor first - * starts execution following a reset event. Only the absolutely - * necessary set is performed, after which the application - * supplied main() routine is called. - * @param None - * @retval : None -*/ - - .section .text.Reset_Handler - .weak Reset_Handler - .type Reset_Handler, %function -Reset_Handler: - -/* Copy the data segment initializers from flash to SRAM */ - movs r1, #0 - b LoopCopyDataInit - -CopyDataInit: - ldr r3, =_sidata - ldr r3, [r3, r1] - str r3, [r0, r1] - adds r1, r1, #4 - -LoopCopyDataInit: - ldr r0, =_sdata - ldr r3, =_edata - adds r2, r0, r1 - cmp r2, r3 - bcc CopyDataInit - ldr r2, =_sbss - b LoopFillZerobss -/* Zero fill the bss segment. */ -FillZerobss: - movs r3, #0 - str r3, [r2], #4 - -LoopFillZerobss: - ldr r3, = _ebss - cmp r2, r3 - bcc FillZerobss - -/* Call the clock system intitialization function.*/ - bl SystemInit -/* Call the application's entry point.*/ - bl main - bx lr -.size Reset_Handler, .-Reset_Handler - -/** - * @brief This is the code that gets called when the processor receives an - * unexpected interrupt. This simply enters an infinite loop, preserving - * the system state for examination by a debugger. - * @param None - * @retval None -*/ - .section .text.Default_Handler,"ax",%progbits -Default_Handler: -Infinite_Loop: - b Infinite_Loop - .size Default_Handler, .-Default_Handler -/****************************************************************************** -* -* The minimal vector table for a Cortex M3. Note that the proper constructs -* must be placed on this to ensure that it ends up at physical address -* 0x0000.0000. -* -*******************************************************************************/ - .section .isr_vector,"a",%progbits - .type g_pfnVectors, %object - .size g_pfnVectors, .-g_pfnVectors - - -g_pfnVectors: - .word _estack - .word Reset_Handler - .word NMI_Handler - .word HardFault_Handler - .word MemManage_Handler - .word BusFault_Handler - .word UsageFault_Handler - .word 0 - .word 0 - .word 0 - .word 0 - .word SVC_Handler - .word DebugMon_Handler - .word 0 - .word PendSV_Handler - .word SysTick_Handler - - /* External Interrupts */ - .word WWDG_IRQHandler /* Window WatchDog */ - .word PVD_IRQHandler /* PVD through EXTI Line detection */ - .word TAMP_STAMP_IRQHandler /* Tamper and TimeStamps through the EXTI line */ - .word RTC_WKUP_IRQHandler /* RTC Wakeup through the EXTI line */ - .word FLASH_IRQHandler /* FLASH */ - .word RCC_IRQHandler /* RCC */ - .word EXTI0_IRQHandler /* EXTI Line0 */ - .word EXTI1_IRQHandler /* EXTI Line1 */ - .word EXTI2_IRQHandler /* EXTI Line2 */ - .word EXTI3_IRQHandler /* EXTI Line3 */ - .word EXTI4_IRQHandler /* EXTI Line4 */ - .word DMA1_Stream0_IRQHandler /* DMA1 Stream 0 */ - .word DMA1_Stream1_IRQHandler /* DMA1 Stream 1 */ - .word DMA1_Stream2_IRQHandler /* DMA1 Stream 2 */ - .word DMA1_Stream3_IRQHandler /* DMA1 Stream 3 */ - .word DMA1_Stream4_IRQHandler /* DMA1 Stream 4 */ - .word DMA1_Stream5_IRQHandler /* DMA1 Stream 5 */ - .word DMA1_Stream6_IRQHandler /* DMA1 Stream 6 */ - .word ADC_IRQHandler /* ADC1, ADC2 and ADC3s */ - .word CAN1_TX_IRQHandler /* CAN1 TX */ - .word CAN1_RX0_IRQHandler /* CAN1 RX0 */ - .word CAN1_RX1_IRQHandler /* CAN1 RX1 */ - .word CAN1_SCE_IRQHandler /* CAN1 SCE */ - .word EXTI9_5_IRQHandler /* External Line[9:5]s */ - .word TIM1_BRK_TIM9_IRQHandler /* TIM1 Break and TIM9 */ - .word TIM1_UP_TIM10_IRQHandler /* TIM1 Update and TIM10 */ - .word TIM1_TRG_COM_TIM11_IRQHandler /* TIM1 Trigger and Commutation and TIM11 */ - .word TIM1_CC_IRQHandler /* TIM1 Capture Compare */ - .word TIM2_IRQHandler /* TIM2 */ - .word TIM3_IRQHandler /* TIM3 */ - .word TIM4_IRQHandler /* TIM4 */ - .word I2C1_EV_IRQHandler /* I2C1 Event */ - .word I2C1_ER_IRQHandler /* I2C1 Error */ - .word I2C2_EV_IRQHandler /* I2C2 Event */ - .word I2C2_ER_IRQHandler /* I2C2 Error */ - .word SPI1_IRQHandler /* SPI1 */ - .word SPI2_IRQHandler /* SPI2 */ - .word USART1_IRQHandler /* USART1 */ - .word USART2_IRQHandler /* USART2 */ - .word USART3_IRQHandler /* USART3 */ - .word EXTI15_10_IRQHandler /* External Line[15:10]s */ - .word RTC_Alarm_IRQHandler /* RTC Alarm (A and B) through EXTI Line */ - .word OTG_FS_WKUP_IRQHandler /* USB OTG FS Wakeup through EXTI line */ - .word TIM8_BRK_TIM12_IRQHandler /* TIM8 Break and TIM12 */ - .word TIM8_UP_TIM13_IRQHandler /* TIM8 Update and TIM13 */ - .word TIM8_TRG_COM_TIM14_IRQHandler /* TIM8 Trigger and Commutation and TIM14 */ - .word TIM8_CC_IRQHandler /* TIM8 Capture Compare */ - .word DMA1_Stream7_IRQHandler /* DMA1 Stream7 */ - .word FSMC_IRQHandler /* FSMC */ - .word SDIO_IRQHandler /* SDIO */ - .word TIM5_IRQHandler /* TIM5 */ - .word SPI3_IRQHandler /* SPI3 */ - .word UART4_IRQHandler /* UART4 */ - .word UART5_IRQHandler /* UART5 */ - .word TIM6_DAC_IRQHandler /* TIM6 and DAC1&2 underrun errors */ - .word TIM7_IRQHandler /* TIM7 */ - .word DMA2_Stream0_IRQHandler /* DMA2 Stream 0 */ - .word DMA2_Stream1_IRQHandler /* DMA2 Stream 1 */ - .word DMA2_Stream2_IRQHandler /* DMA2 Stream 2 */ - .word DMA2_Stream3_IRQHandler /* DMA2 Stream 3 */ - .word DMA2_Stream4_IRQHandler /* DMA2 Stream 4 */ - .word ETH_IRQHandler /* Ethernet */ - .word ETH_WKUP_IRQHandler /* Ethernet Wakeup through EXTI line */ - .word CAN2_TX_IRQHandler /* CAN2 TX */ - .word CAN2_RX0_IRQHandler /* CAN2 RX0 */ - .word CAN2_RX1_IRQHandler /* CAN2 RX1 */ - .word CAN2_SCE_IRQHandler /* CAN2 SCE */ - .word OTG_FS_IRQHandler /* USB OTG FS */ - .word DMA2_Stream5_IRQHandler /* DMA2 Stream 5 */ - .word DMA2_Stream6_IRQHandler /* DMA2 Stream 6 */ - .word DMA2_Stream7_IRQHandler /* DMA2 Stream 7 */ - .word USART6_IRQHandler /* USART6 */ - .word I2C3_EV_IRQHandler /* I2C3 event */ - .word I2C3_ER_IRQHandler /* I2C3 error */ - .word OTG_HS_EP1_OUT_IRQHandler /* USB OTG HS End Point 1 Out */ - .word OTG_HS_EP1_IN_IRQHandler /* USB OTG HS End Point 1 In */ - .word OTG_HS_WKUP_IRQHandler /* USB OTG HS Wakeup through EXTI */ - .word OTG_HS_IRQHandler /* USB OTG HS */ - .word DCMI_IRQHandler /* DCMI */ - .word CRYP_IRQHandler /* CRYP crypto */ - .word HASH_RNG_IRQHandler /* Hash and Rng */ - .word FPU_IRQHandler /* FPU */ - -/******************************************************************************* -* -* Provide weak aliases for each Exception handler to the Default_Handler. -* As they are weak aliases, any function with the same name will override -* this definition. -* -*******************************************************************************/ - .weak NMI_Handler - .thumb_set NMI_Handler,Default_Handler - - .weak HardFault_Handler - .thumb_set HardFault_Handler,Default_Handler - - .weak MemManage_Handler - .thumb_set MemManage_Handler,Default_Handler - - .weak BusFault_Handler - .thumb_set BusFault_Handler,Default_Handler - - .weak UsageFault_Handler - .thumb_set UsageFault_Handler,Default_Handler - - .weak SVC_Handler - .thumb_set SVC_Handler,Default_Handler - - .weak DebugMon_Handler - .thumb_set DebugMon_Handler,Default_Handler - - .weak PendSV_Handler - .thumb_set PendSV_Handler,Default_Handler - - .weak SysTick_Handler - .thumb_set SysTick_Handler,Default_Handler - - .weak WWDG_IRQHandler - .thumb_set WWDG_IRQHandler,Default_Handler - - .weak PVD_IRQHandler - .thumb_set PVD_IRQHandler,Default_Handler - - .weak TAMP_STAMP_IRQHandler - .thumb_set TAMP_STAMP_IRQHandler,Default_Handler - - .weak RTC_WKUP_IRQHandler - .thumb_set RTC_WKUP_IRQHandler,Default_Handler - - .weak FLASH_IRQHandler - .thumb_set FLASH_IRQHandler,Default_Handler - - .weak RCC_IRQHandler - .thumb_set RCC_IRQHandler,Default_Handler - - .weak EXTI0_IRQHandler - .thumb_set EXTI0_IRQHandler,Default_Handler - - .weak EXTI1_IRQHandler - .thumb_set EXTI1_IRQHandler,Default_Handler - - .weak EXTI2_IRQHandler - .thumb_set EXTI2_IRQHandler,Default_Handler - - .weak EXTI3_IRQHandler - .thumb_set EXTI3_IRQHandler,Default_Handler - - .weak EXTI4_IRQHandler - .thumb_set EXTI4_IRQHandler,Default_Handler - - .weak DMA1_Stream0_IRQHandler - .thumb_set DMA1_Stream0_IRQHandler,Default_Handler - - .weak DMA1_Stream1_IRQHandler - .thumb_set DMA1_Stream1_IRQHandler,Default_Handler - - .weak DMA1_Stream2_IRQHandler - .thumb_set DMA1_Stream2_IRQHandler,Default_Handler - - .weak DMA1_Stream3_IRQHandler - .thumb_set DMA1_Stream3_IRQHandler,Default_Handler - - .weak DMA1_Stream4_IRQHandler - .thumb_set DMA1_Stream4_IRQHandler,Default_Handler - - .weak DMA1_Stream5_IRQHandler - .thumb_set DMA1_Stream5_IRQHandler,Default_Handler - - .weak DMA1_Stream6_IRQHandler - .thumb_set DMA1_Stream6_IRQHandler,Default_Handler - - .weak ADC_IRQHandler - .thumb_set ADC_IRQHandler,Default_Handler - - .weak CAN1_TX_IRQHandler - .thumb_set CAN1_TX_IRQHandler,Default_Handler - - .weak CAN1_RX0_IRQHandler - .thumb_set CAN1_RX0_IRQHandler,Default_Handler - - .weak CAN1_RX1_IRQHandler - .thumb_set CAN1_RX1_IRQHandler,Default_Handler - - .weak CAN1_SCE_IRQHandler - .thumb_set CAN1_SCE_IRQHandler,Default_Handler - - .weak EXTI9_5_IRQHandler - .thumb_set EXTI9_5_IRQHandler,Default_Handler - - .weak TIM1_BRK_TIM9_IRQHandler - .thumb_set TIM1_BRK_TIM9_IRQHandler,Default_Handler - - .weak TIM1_UP_TIM10_IRQHandler - .thumb_set TIM1_UP_TIM10_IRQHandler,Default_Handler - - .weak TIM1_TRG_COM_TIM11_IRQHandler - .thumb_set TIM1_TRG_COM_TIM11_IRQHandler,Default_Handler - - .weak TIM1_CC_IRQHandler - .thumb_set TIM1_CC_IRQHandler,Default_Handler - - .weak TIM2_IRQHandler - .thumb_set TIM2_IRQHandler,Default_Handler - - .weak TIM3_IRQHandler - .thumb_set TIM3_IRQHandler,Default_Handler - - .weak TIM4_IRQHandler - .thumb_set TIM4_IRQHandler,Default_Handler - - .weak I2C1_EV_IRQHandler - .thumb_set I2C1_EV_IRQHandler,Default_Handler - - .weak I2C1_ER_IRQHandler - .thumb_set I2C1_ER_IRQHandler,Default_Handler - - .weak I2C2_EV_IRQHandler - .thumb_set I2C2_EV_IRQHandler,Default_Handler - - .weak I2C2_ER_IRQHandler - .thumb_set I2C2_ER_IRQHandler,Default_Handler - - .weak SPI1_IRQHandler - .thumb_set SPI1_IRQHandler,Default_Handler - - .weak SPI2_IRQHandler - .thumb_set SPI2_IRQHandler,Default_Handler - - .weak USART1_IRQHandler - .thumb_set USART1_IRQHandler,Default_Handler - - .weak USART2_IRQHandler - .thumb_set USART2_IRQHandler,Default_Handler - - .weak USART3_IRQHandler - .thumb_set USART3_IRQHandler,Default_Handler - - .weak EXTI15_10_IRQHandler - .thumb_set EXTI15_10_IRQHandler,Default_Handler - - .weak RTC_Alarm_IRQHandler - .thumb_set RTC_Alarm_IRQHandler,Default_Handler - - .weak OTG_FS_WKUP_IRQHandler - .thumb_set OTG_FS_WKUP_IRQHandler,Default_Handler - - .weak TIM8_BRK_TIM12_IRQHandler - .thumb_set TIM8_BRK_TIM12_IRQHandler,Default_Handler - - .weak TIM8_UP_TIM13_IRQHandler - .thumb_set TIM8_UP_TIM13_IRQHandler,Default_Handler - - .weak TIM8_TRG_COM_TIM14_IRQHandler - .thumb_set TIM8_TRG_COM_TIM14_IRQHandler,Default_Handler - - .weak TIM8_CC_IRQHandler - .thumb_set TIM8_CC_IRQHandler,Default_Handler - - .weak DMA1_Stream7_IRQHandler - .thumb_set DMA1_Stream7_IRQHandler,Default_Handler - - .weak FSMC_IRQHandler - .thumb_set FSMC_IRQHandler,Default_Handler - - .weak SDIO_IRQHandler - .thumb_set SDIO_IRQHandler,Default_Handler - - .weak TIM5_IRQHandler - .thumb_set TIM5_IRQHandler,Default_Handler - - .weak SPI3_IRQHandler - .thumb_set SPI3_IRQHandler,Default_Handler - - .weak UART4_IRQHandler - .thumb_set UART4_IRQHandler,Default_Handler - - .weak UART5_IRQHandler - .thumb_set UART5_IRQHandler,Default_Handler - - .weak TIM6_DAC_IRQHandler - .thumb_set TIM6_DAC_IRQHandler,Default_Handler - - .weak TIM7_IRQHandler - .thumb_set TIM7_IRQHandler,Default_Handler - - .weak DMA2_Stream0_IRQHandler - .thumb_set DMA2_Stream0_IRQHandler,Default_Handler - - .weak DMA2_Stream1_IRQHandler - .thumb_set DMA2_Stream1_IRQHandler,Default_Handler - - .weak DMA2_Stream2_IRQHandler - .thumb_set DMA2_Stream2_IRQHandler,Default_Handler - - .weak DMA2_Stream3_IRQHandler - .thumb_set DMA2_Stream3_IRQHandler,Default_Handler - - .weak DMA2_Stream4_IRQHandler - .thumb_set DMA2_Stream4_IRQHandler,Default_Handler - - .weak ETH_IRQHandler - .thumb_set ETH_IRQHandler,Default_Handler - - .weak ETH_WKUP_IRQHandler - .thumb_set ETH_WKUP_IRQHandler,Default_Handler - - .weak CAN2_TX_IRQHandler - .thumb_set CAN2_TX_IRQHandler,Default_Handler - - .weak CAN2_RX0_IRQHandler - .thumb_set CAN2_RX0_IRQHandler,Default_Handler - - .weak CAN2_RX1_IRQHandler - .thumb_set CAN2_RX1_IRQHandler,Default_Handler - - .weak CAN2_SCE_IRQHandler - .thumb_set CAN2_SCE_IRQHandler,Default_Handler - - .weak OTG_FS_IRQHandler - .thumb_set OTG_FS_IRQHandler,Default_Handler - - .weak DMA2_Stream5_IRQHandler - .thumb_set DMA2_Stream5_IRQHandler,Default_Handler - - .weak DMA2_Stream6_IRQHandler - .thumb_set DMA2_Stream6_IRQHandler,Default_Handler - - .weak DMA2_Stream7_IRQHandler - .thumb_set DMA2_Stream7_IRQHandler,Default_Handler - - .weak USART6_IRQHandler - .thumb_set USART6_IRQHandler,Default_Handler - - .weak I2C3_EV_IRQHandler - .thumb_set I2C3_EV_IRQHandler,Default_Handler - - .weak I2C3_ER_IRQHandler - .thumb_set I2C3_ER_IRQHandler,Default_Handler - - .weak OTG_HS_EP1_OUT_IRQHandler - .thumb_set OTG_HS_EP1_OUT_IRQHandler,Default_Handler - - .weak OTG_HS_EP1_IN_IRQHandler - .thumb_set OTG_HS_EP1_IN_IRQHandler,Default_Handler - - .weak OTG_HS_WKUP_IRQHandler - .thumb_set OTG_HS_WKUP_IRQHandler,Default_Handler - - .weak OTG_HS_IRQHandler - .thumb_set OTG_HS_IRQHandler,Default_Handler - - .weak DCMI_IRQHandler - .thumb_set DCMI_IRQHandler,Default_Handler - - .weak CRYP_IRQHandler - .thumb_set CRYP_IRQHandler,Default_Handler - - .weak HASH_RNG_IRQHandler - .thumb_set HASH_RNG_IRQHandler,Default_Handler - - .weak FPU_IRQHandler - .thumb_set FPU_IRQHandler,Default_Handler - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/blink2/stm32f4_discovery.c b/examples/STM32F4Discovery/blink2/stm32f4_discovery.c deleted file mode 100644 --- a/examples/STM32F4Discovery/blink2/stm32f4_discovery.c +++ /dev/null @@ -1,257 +0,0 @@ -/** - ****************************************************************************** - * @file stm32f4_discovery.c - * @author MCD Application Team - * @version V1.0.0 - * @date 19-September-2011 - * @brief This file provides set of firmware functions to manage Leds and - * push-button available on STM32F4-Discovery Kit from STMicroelectronics. - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4_discovery.h" - -//ADDED BY ME!!!!!!!!!!!!!!!!!!!! -#include "stm32f4xx_conf.h" - - -/** @addtogroup Utilities - * @{ - */ - -/** @addtogroup STM32F4_DISCOVERY - * @{ - */ - -/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL - * @brief This file provides set of firmware functions to manage Leds and push-button - * available on STM32F4-Discovery Kit from STMicroelectronics. - * @{ - */ - -/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_TypesDefinitions - * @{ - */ -/** - * @} - */ - - -/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Defines - * @{ - */ -/** - * @} - */ - - -/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Macros - * @{ - */ -/** - * @} - */ - - -/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Variables - * @{ - */ -GPIO_TypeDef* GPIO_PORT[LEDn] = {LED4_GPIO_PORT, LED3_GPIO_PORT, LED5_GPIO_PORT, - LED6_GPIO_PORT}; -const uint16_t GPIO_PIN[LEDn] = {LED4_PIN, LED3_PIN, LED5_PIN, - LED6_PIN}; -const uint32_t GPIO_CLK[LEDn] = {LED4_GPIO_CLK, LED3_GPIO_CLK, LED5_GPIO_CLK, - LED6_GPIO_CLK}; - -GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_GPIO_PORT }; - -const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN }; - -const uint32_t BUTTON_CLK[BUTTONn] = {USER_BUTTON_GPIO_CLK }; - -const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {USER_BUTTON_EXTI_LINE }; - -const uint8_t BUTTON_PORT_SOURCE[BUTTONn] = {USER_BUTTON_EXTI_PORT_SOURCE}; - -const uint8_t BUTTON_PIN_SOURCE[BUTTONn] = {USER_BUTTON_EXTI_PIN_SOURCE }; -const uint8_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn }; - -NVIC_InitTypeDef NVIC_InitStructure; - -/** - * @} - */ - - -/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_FunctionPrototypes - * @{ - */ - -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Functions - * @{ - */ - -/** - * @brief Configures LED GPIO. - * @param Led: Specifies the Led to be configured. - * This parameter can be one of following parameters: - * @arg LED4 - * @arg LED3 - * @arg LED5 - * @arg LED6 - * @retval None - */ -void STM_EVAL_LEDInit(Led_TypeDef Led) -{ - GPIO_InitTypeDef GPIO_InitStructure; - - /* Enable the GPIO_LED Clock */ - RCC_AHB1PeriphClockCmd(GPIO_CLK[Led], ENABLE); - - /* Configure the GPIO_LED pin */ - GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led]; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure); -} - -/** - * @brief Turns selected LED On. - * @param Led: Specifies the Led to be set on. - * This parameter can be one of following parameters: - * @arg LED4 - * @arg LED3 - * @arg LED5 - * @arg LED6 - * @retval None - */ -void STM_EVAL_LEDOn(Led_TypeDef Led) -{ - GPIO_PORT[Led]->BSRRL = GPIO_PIN[Led]; -} - -/** - * @brief Turns selected LED Off. - * @param Led: Specifies the Led to be set off. - * This parameter can be one of following parameters: - * @arg LED4 - * @arg LED3 - * @arg LED5 - * @arg LED6 - * @retval None - */ -void STM_EVAL_LEDOff(Led_TypeDef Led) -{ - GPIO_PORT[Led]->BSRRH = GPIO_PIN[Led]; -} - -/** - * @brief Toggles the selected LED. - * @param Led: Specifies the Led to be toggled. - * This parameter can be one of following parameters: - * @arg LED4 - * @arg LED3 - * @arg LED5 - * @arg LED6 - * @retval None - */ -void STM_EVAL_LEDToggle(Led_TypeDef Led) -{ - GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led]; -} - -/** - * @brief Configures Button GPIO and EXTI Line. - * @param Button: Specifies the Button to be configured. - * This parameter should be: BUTTON_USER - * @param Button_Mode: Specifies Button mode. - * This parameter can be one of following parameters: - * @arg BUTTON_MODE_GPIO: Button will be used as simple IO - * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt - * generation capability - * @retval None - */ -void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode) -{ - GPIO_InitTypeDef GPIO_InitStructure; - EXTI_InitTypeDef EXTI_InitStructure; - NVIC_InitTypeDef NVIC_InitStructure; - - /* Enable the BUTTON Clock */ - RCC_AHB1PeriphClockCmd(BUTTON_CLK[Button], ENABLE); - RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); - - /* Configure Button pin as input */ - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button]; - GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure); - - if (Button_Mode == BUTTON_MODE_EXTI) - { - /* Connect Button EXTI Line to Button GPIO Pin */ - SYSCFG_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]); - - /* Configure Button EXTI line */ - /* EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button]; - EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; - EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; - EXTI_InitStructure.EXTI_LineCmd = ENABLE; - EXTI_Init(&EXTI_InitStructure);*/ - - /* Enable and set Button EXTI Interrupt to the lowest priority */ - /* NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button]; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - - NVIC_Init(&NVIC_InitStructure); */ - } -} - -/** - * @brief Returns the selected Button state. - * @param Button: Specifies the Button to be checked. - * This parameter should be: BUTTON_USER - * @retval The Button GPIO pin value. - */ -uint32_t STM_EVAL_PBGetState(Button_TypeDef Button) -{ - return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]); -} - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/blink2/stm32f4_discovery.h b/examples/STM32F4Discovery/blink2/stm32f4_discovery.h deleted file mode 100644 --- a/examples/STM32F4Discovery/blink2/stm32f4_discovery.h +++ /dev/null @@ -1,158 +0,0 @@ -/** - ****************************************************************************** - * @file stm32f4_discovery.h - * @author MCD Application Team - * @version V1.0.0 - * @date 19-September-2011 - * @brief This file contains definitions for STM32F4-Discovery Kit's Leds and - * push-button hardware resources. - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F4_DISCOVERY_H -#define __STM32F4_DISCOVERY_H - -#ifdef __cplusplus - extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ - #include "stm32f4xx.h" - -/** @addtogroup Utilities - * @{ - */ - -/** @addtogroup STM32F4_DISCOVERY - * @{ - */ - -/** @addtogroup STM32F4_DISCOVERY_LOW_LEVEL - * @{ - */ - -/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Exported_Types - * @{ - */ -typedef enum -{ - LED4 = 0, - LED3 = 1, - LED5 = 2, - LED6 = 3 -} Led_TypeDef; - -typedef enum -{ - BUTTON_USER = 0, -} Button_TypeDef; - -typedef enum -{ - BUTTON_MODE_GPIO = 0, - BUTTON_MODE_EXTI = 1 -} ButtonMode_TypeDef; -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Exported_Constants - * @{ - */ - -/** @addtogroup STM32F4_DISCOVERY_LOW_LEVEL_LED - * @{ - */ -#define LEDn 4 - -#define LED4_PIN GPIO_Pin_12 -#define LED4_GPIO_PORT GPIOD -#define LED4_GPIO_CLK RCC_AHB1Periph_GPIOD - -#define LED3_PIN GPIO_Pin_13 -#define LED3_GPIO_PORT GPIOD -#define LED3_GPIO_CLK RCC_AHB1Periph_GPIOD - -#define LED5_PIN GPIO_Pin_14 -#define LED5_GPIO_PORT GPIOD -#define LED5_GPIO_CLK RCC_AHB1Periph_GPIOD - -#define LED6_PIN GPIO_Pin_15 -#define LED6_GPIO_PORT GPIOD -#define LED6_GPIO_CLK RCC_AHB1Periph_GPIOD -/** - * @} - */ - -/** @addtogroup STM32F4_DISCOVERY_LOW_LEVEL_BUTTON - * @{ - */ -#define BUTTONn 1 - -/** - * @brief Wakeup push-button - */ -#define USER_BUTTON_PIN GPIO_Pin_0 -#define USER_BUTTON_GPIO_PORT GPIOA -#define USER_BUTTON_GPIO_CLK RCC_AHB1Periph_GPIOA -#define USER_BUTTON_EXTI_LINE EXTI_Line0 -#define USER_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOA -#define USER_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource0 -#define USER_BUTTON_EXTI_IRQn EXTI0_IRQn -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Exported_Macros - * @{ - */ -/** - * @} - */ - - -/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Exported_Functions - * @{ - */ -void STM_EVAL_LEDInit(Led_TypeDef Led); -void STM_EVAL_LEDOn(Led_TypeDef Led); -void STM_EVAL_LEDOff(Led_TypeDef Led); -void STM_EVAL_LEDToggle(Led_TypeDef Led); -void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode); -uint32_t STM_EVAL_PBGetState(Button_TypeDef Button); -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32F4_DISCOVERY_H */ -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - - - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/blink2/stm32f4_discovery_audio_codec.c b/examples/STM32F4Discovery/blink2/stm32f4_discovery_audio_codec.c deleted file mode 100644 --- a/examples/STM32F4Discovery/blink2/stm32f4_discovery_audio_codec.c +++ /dev/null @@ -1,1651 +0,0 @@ -/** - ****************************************************************************** - * @file stm32f4_discovery_audio_codec.c - * @author MCD Application Team - * @version V1.0.0 - * @date 19-September-2011 - * @brief This file includes the low layer driver for CS43L22 Audio Codec - * available on STM32F4-Discovery Kit. - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - -/*============================================================================================================================== - User NOTES -1. How To use this driver: --------------------------- - - This driver supports STM32F4xx devices on STM32F4-Discovery Kit. - - - Configure the options in file stm32f4_discovery_audio_codec.h in the section CONFIGURATION. - Refer to the sections 2 and 3 to have more details on the possible configurations. - - - Call the function EVAL_AUDIO_Init( - OutputDevice: physical output mode (OUTPUT_DEVICE_SPEAKER, - OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_AUTO or - OUTPUT_DEVICE_BOTH) - Volume: initial volume to be set (0 is min (mute), 100 is max (100%) - AudioFreq: Audio frequency in Hz (8000, 16000, 22500, 32000 ...) - this parameter is relative to the audio file/stream type. - ) - This function configures all the hardware required for the audio application (codec, I2C, I2S, - GPIOs, DMA and interrupt if needed). This function returns 0 if configuration is OK. - if the returned value is different from 0 or the function is stuck then the communication with - the codec (try to un-plug the power or reset device in this case). - + OUTPUT_DEVICE_SPEAKER: only speaker will be set as output for the audio stream. - + OUTPUT_DEVICE_HEADPHONE: only headphones will be set as output for the audio stream. - + OUTPUT_DEVICE_AUTO: Selection of output device is made through external switch (implemented - into the audio jack on the evaluation board). When the Headphone is connected it is used - as output. When the headphone is disconnected from the audio jack, the output is - automatically switched to Speaker. - + OUTPUT_DEVICE_BOTH: both Speaker and Headphone are used as outputs for the audio stream - at the same time. - - - Call the function EVAL_AUDIO_Play( - pBuffer: pointer to the audio data file address - Size: size of the buffer to be sent in Bytes - ) - to start playing (for the first time) from the audio file/stream. - - - Call the function EVAL_AUDIO_PauseResume( - Cmd: AUDIO_PAUSE (or 0) to pause playing or AUDIO_RESUME (or - any value different from 0) to resume playing. - ) - Note. After calling EVAL_AUDIO_PauseResume() function for pause, only EVAL_AUDIO_PauseResume() should be called - for resume (it is not allowed to call EVAL_AUDIO_Play() in this case). - Note. This function should be called only when the audio file is played or paused (not stopped). - - - For each mode, you may need to implement the relative callback functions into your code. - The Callback functions are named EVAL_AUDIO_XXX_CallBack() and only their prototypes are declared in - the stm32f4_discovery_audio_codec.h file. (refer to the example for more details on the callbacks implementations) - - - To Stop playing, to modify the volume level or to mute, use the functions - EVAL_AUDIO_Stop(), EVAL_AUDIO_VolumeCtl() and EVAL_AUDIO_Mute(). - - - The driver API and the callback functions are at the end of the stm32f4_discovery_audio_codec.h file. - - - Driver architecture: - -------------------- - This driver is composed of three main layers: - o High Audio Layer: consists of the function API exported in the stm32f4_discovery_audio_codec.h file - (EVAL_AUDIO_Init(), EVAL_AUDIO_Play() ...) - o Codec Control layer: consists of the functions API controlling the audio codec (CS43L22) and - included as local functions in file stm32f4_discovery_audio_codec.c (Codec_Init(), Codec_Play() ...) - o Media Access Layer (MAL): which consists of functions allowing to access the media containing/ - providing the audio file/stream. These functions are also included as local functions into - the stm32f4_discovery_audio_codec.c file (Audio_MAL_Init(), Audio_MAL_Play() ...) - Each set of functions (layer) may be implemented independently of the others and customized when - needed. - -2. Modes description: ---------------------- - + AUDIO_MAL_MODE_NORMAL : is suitable when the audio file is in a memory location. - + AUDIO_MAL_MODE_CIRCULAR: is suitable when the audio data are read either from a - memory location or from a device at real time (double buffer could be used). - -3. DMA interrupts description: ------------------------------- - + EVAL_AUDIO_IT_TC_ENABLE: Enable this define to use the DMA end of transfer interrupt. - then, a callback should be implemented by user to perform specific actions - when the DMA has finished the transfer. - + EVAL_AUDIO_IT_HT_ENABLE: Enable this define to use the DMA end of half transfer interrupt. - then, a callback should be implemented by user to perform specific actions - when the DMA has reached the half of the buffer transfer (generally, it is useful - to load the first half of buffer while DMA is loading from the second half). - + EVAL_AUDIO_IT_ER_ENABLE: Enable this define to manage the cases of error on DMA transfer. - -4. Known Limitations: ---------------------- - 1- When using the Speaker, if the audio file quality is not high enough, the speaker output - may produce high and uncomfortable noise level. To avoid this issue, to use speaker - output properly, try to increase audio file sampling rate (typically higher than 48KHz). - This operation will lead to larger file size. - 2- Communication with the audio codec (through I2C) may be corrupted if it is interrupted by some - user interrupt routines (in this case, interrupts could be disabled just before the start of - communication then re-enabled when it is over). Note that this communication is only done at - the configuration phase (EVAL_AUDIO_Init() or EVAL_AUDIO_Stop()) and when Volume control modification is - performed (EVAL_AUDIO_VolumeCtl() or EVAL_AUDIO_Mute()). When the audio data is played, no communication is - required with the audio codec. - 3- Parsing of audio file is not implemented (in order to determine audio file properties: Mono/Stereo, Data size, - File size, Audio Frequency, Audio Data header size ...). The configuration is fixed for the given audio file. - 4- Mono audio streaming is not supported (in order to play mono audio streams, each data should be sent twice - on the I2S or should be duplicated on the source buffer. Or convert the stream in stereo before playing). - 5- Supports only 16-bit audio data size. -===============================================================================================================================*/ - - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4_discovery_audio_codec.h" -//ADDED BY ME!!!!!!!!!!!!!!!!!!!! -#include "stm32f4xx_conf.h" - -/** @addtogroup Utilities - * @{ - */ - -/** @addtogroup STM32F4_DISCOVERY - * @{ - */ - -/** @addtogroup STM32F4_DISCOVERY_AUDIO_CODEC - * @brief This file includes the low layer driver for CS43L22 Audio Codec - * available on STM32F4-Discovery Kit. - * @{ - */ - -/** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC_Private_Types - * @{ - */ -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC_Private_Defines - * @{ - */ - -/* Mask for the bit EN of the I2S CFGR register */ -#define I2S_ENABLE_MASK 0x0400 - -/* Delay for the Codec to be correctly reset */ -#define CODEC_RESET_DELAY 0x4FFF - -/* Codec audio Standards */ -#ifdef I2S_STANDARD_PHILLIPS - #define CODEC_STANDARD 0x04 - #define I2S_STANDARD I2S_Standard_Phillips -#elif defined(I2S_STANDARD_MSB) - #define CODEC_STANDARD 0x00 - #define I2S_STANDARD I2S_Standard_MSB -#elif defined(I2S_STANDARD_LSB) - #define CODEC_STANDARD 0x08 - #define I2S_STANDARD I2S_Standard_LSB -#else - #error "Error: No audio communication standard selected !" -#endif /* I2S_STANDARD */ - -/* The 7 bits Codec address (sent through I2C interface) */ -#define CODEC_ADDRESS 0x94 /* b00100111 */ -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC_Private_Macros - * @{ - */ -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC_Private_Variables - * @{ - */ -/* This structure is declared global because it is handled by two different functions */ -static DMA_InitTypeDef DMA_InitStructure; -DMA_InitTypeDef AUDIO_MAL_DMA_InitStructure; - -uint32_t AudioTotalSize = 0xFFFF; /* This variable holds the total size of the audio file */ -uint32_t AudioRemSize = 0xFFFF; /* This variable holds the remaining data in audio file */ -uint16_t *CurrentPos; /* This variable holds the current position of audio pointer */ - -__IO uint32_t CODECTimeout = CODEC_LONG_TIMEOUT; -__IO uint8_t OutputDev = 0; - - -__IO uint32_t CurrAudioInterface = AUDIO_INTERFACE_I2S; //AUDIO_INTERFACE_DAC -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC_Private_Function_Prototypes - * @{ - */ -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC_Private_Functions - * @{ - */ -static void Audio_MAL_IRQHandler(void); -/*----------------------------------- - Audio Codec functions - ------------------------------------------*/ -/* High Layer codec functions */ -static uint32_t Codec_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq); -static uint32_t Codec_DeInit(void); -static uint32_t Codec_Play(void); -static uint32_t Codec_PauseResume(uint32_t Cmd); -static uint32_t Codec_Stop(uint32_t Cmd); -static uint32_t Codec_VolumeCtrl(uint8_t Volume); -static uint32_t Codec_Mute(uint32_t Cmd); -/* Low layer codec functions */ -static void Codec_CtrlInterface_Init(void); -static void Codec_CtrlInterface_DeInit(void); -static void Codec_AudioInterface_Init(uint32_t AudioFreq); -static void Codec_AudioInterface_DeInit(void); -static void Codec_Reset(void); -static uint32_t Codec_WriteRegister(uint8_t RegisterAddr, uint8_t RegisterValue); -static uint32_t Codec_ReadRegister(uint8_t RegisterAddr); -static void Codec_GPIO_Init(void); -static void Codec_GPIO_DeInit(void); -static void Delay(__IO uint32_t nCount); -/*----------------------------------------------------------------------------*/ - -/*----------------------------------- - MAL (Media Access Layer) functions - ------------------------------------------*/ -/* Peripherals configuration functions */ -static void Audio_MAL_Init(void); -static void Audio_MAL_DeInit(void); -static void Audio_MAL_Play(uint32_t Addr, uint32_t Size); -static void Audio_MAL_PauseResume(uint32_t Cmd, uint32_t Addr); -static void Audio_MAL_Stop(void); -/*----------------------------------------------------------------------------*/ - - /* DMA Stream definitions */ - uint32_t AUDIO_MAL_DMA_CLOCK = AUDIO_I2S_DMA_CLOCK; - DMA_Stream_TypeDef * AUDIO_MAL_DMA_STREAM = AUDIO_I2S_DMA_STREAM ; - uint32_t AUDIO_MAL_DMA_DREG = AUDIO_I2S_DMA_DREG; - uint32_t AUDIO_MAL_DMA_CHANNEL = AUDIO_I2S_DMA_CHANNEL; - uint32_t AUDIO_MAL_DMA_IRQ = AUDIO_I2S_DMA_IRQ ; - uint32_t AUDIO_MAL_DMA_FLAG_TC = AUDIO_I2S_DMA_FLAG_TC; - uint32_t AUDIO_MAL_DMA_FLAG_HT = AUDIO_I2S_DMA_FLAG_HT; - uint32_t AUDIO_MAL_DMA_FLAG_FE = AUDIO_I2S_DMA_FLAG_FE; - uint32_t AUDIO_MAL_DMA_FLAG_TE = AUDIO_I2S_DMA_FLAG_TE; - uint32_t AUDIO_MAL_DMA_FLAG_DME = AUDIO_I2S_DMA_FLAG_DME; - -/** - * @brief Set the current audio interface (I2S or DAC). - * @param Interface: AUDIO_INTERFACE_I2S or AUDIO_INTERFACE_DAC - * @retval None - */ -void EVAL_AUDIO_SetAudioInterface(uint32_t Interface) -{ - CurrAudioInterface = Interface; - - if (CurrAudioInterface == AUDIO_INTERFACE_I2S) - { - /* DMA Stream definitions */ - AUDIO_MAL_DMA_CLOCK = AUDIO_I2S_DMA_CLOCK; - AUDIO_MAL_DMA_STREAM = AUDIO_I2S_DMA_STREAM; - AUDIO_MAL_DMA_DREG = AUDIO_I2S_DMA_DREG; - AUDIO_MAL_DMA_CHANNEL = AUDIO_I2S_DMA_CHANNEL; - AUDIO_MAL_DMA_IRQ = AUDIO_I2S_DMA_IRQ ; - AUDIO_MAL_DMA_FLAG_TC = AUDIO_I2S_DMA_FLAG_TC; - AUDIO_MAL_DMA_FLAG_HT = AUDIO_I2S_DMA_FLAG_HT; - AUDIO_MAL_DMA_FLAG_FE = AUDIO_I2S_DMA_FLAG_FE; - AUDIO_MAL_DMA_FLAG_TE = AUDIO_I2S_DMA_FLAG_TE; - AUDIO_MAL_DMA_FLAG_DME = AUDIO_I2S_DMA_FLAG_DME; - } - else if (Interface == AUDIO_INTERFACE_DAC) - { - /* DMA Stream definitions */ - AUDIO_MAL_DMA_CLOCK = AUDIO_DAC_DMA_CLOCK; - AUDIO_MAL_DMA_STREAM = AUDIO_DAC_DMA_STREAM; - AUDIO_MAL_DMA_DREG = AUDIO_DAC_DMA_DREG; - AUDIO_MAL_DMA_CHANNEL = AUDIO_DAC_DMA_CHANNEL; - AUDIO_MAL_DMA_IRQ = AUDIO_DAC_DMA_IRQ ; - AUDIO_MAL_DMA_FLAG_TC = AUDIO_DAC_DMA_FLAG_TC; - AUDIO_MAL_DMA_FLAG_HT = AUDIO_DAC_DMA_FLAG_HT; - AUDIO_MAL_DMA_FLAG_FE = AUDIO_DAC_DMA_FLAG_FE; - AUDIO_MAL_DMA_FLAG_TE = AUDIO_DAC_DMA_FLAG_TE; - AUDIO_MAL_DMA_FLAG_DME = AUDIO_DAC_DMA_FLAG_DME; - } -} - -/** - * @brief Configure the audio peripherals. - * @param OutputDevice: OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE, - * OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO . - * @param Volume: Initial volume level (from 0 (Mute) to 100 (Max)) - * @param AudioFreq: Audio frequency used to play the audio stream. - * @retval 0 if correct communication, else wrong communication - */ -uint32_t EVAL_AUDIO_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq) -{ - /* Perform low layer Codec initialization */ - if (Codec_Init(OutputDevice, VOLUME_CONVERT(Volume), AudioFreq) != 0) - { - return 1; - } - else - { - /* I2S data transfer preparation: - Prepare the Media to be used for the audio transfer from memory to I2S peripheral */ - Audio_MAL_Init(); - - /* Return 0 when all operations are OK */ - return 0; - } -} - -/** - * @brief Deinitializes all the resources used by the codec (those initialized - * by EVAL_AUDIO_Init() function). - * @param None - * @retval 0 if correct communication, else wrong communication - */ -uint32_t EVAL_AUDIO_DeInit(void) -{ - /* DeInitialize the Media layer */ - Audio_MAL_DeInit(); - - /* DeInitialize Codec */ - Codec_DeInit(); - - return 0; -} - -/** - * @brief Starts playing audio stream from a data buffer for a determined size. - * @param pBuffer: Pointer to the buffer - * @param Size: Number of audio data BYTES. - * @retval 0 if correct communication, else wrong communication - */ -uint32_t EVAL_AUDIO_Play(uint16_t* pBuffer, uint32_t Size) -{ - /* Set the total number of data to be played (count in half-word) */ - AudioTotalSize = Size/2; - - /* Call the audio Codec Play function */ - Codec_Play(); - - /* Update the Media layer and enable it for play */ - Audio_MAL_Play((uint32_t)pBuffer, (uint32_t)(DMA_MAX(AudioTotalSize / 2))); - - /* Update the remaining number of data to be played */ - AudioRemSize = (Size/2) - DMA_MAX(AudioTotalSize); - - /* Update the current audio pointer position */ - CurrentPos = pBuffer + DMA_MAX(AudioTotalSize); - - return 0; -} - -/** - * @brief This function Pauses or Resumes the audio file stream. In case - * of using DMA, the DMA Pause feature is used. In all cases the I2S - * peripheral is disabled. - * - * @WARNING When calling EVAL_AUDIO_PauseResume() function for pause, only - * this function should be called for resume (use of EVAL_AUDIO_Play() - * function for resume could lead to unexpected behavior). - * - * @param Cmd: AUDIO_PAUSE (or 0) to pause, AUDIO_RESUME (or any value different - * from 0) to resume. - * @retval 0 if correct communication, else wrong communication - */ -uint32_t EVAL_AUDIO_PauseResume(uint32_t Cmd) -{ - /* Call the Audio Codec Pause/Resume function */ - if (Codec_PauseResume(Cmd) != 0) - { - return 1; - } - else - { - /* Call the Media layer pause/resume function */ - Audio_MAL_PauseResume(Cmd, 0); - - /* Return 0 if all operations are OK */ - return 0; - } -} - -/** - * @brief Stops audio playing and Power down the Audio Codec. - * @param Option: could be one of the following parameters - * - CODEC_PDWN_SW: for software power off (by writing registers). - * Then no need to reconfigure the Codec after power on. - * - CODEC_PDWN_HW: completely shut down the codec (physically). - * Then need to reconfigure the Codec after power on. - * @retval 0 if correct communication, else wrong communication - */ -uint32_t EVAL_AUDIO_Stop(uint32_t Option) -{ - /* Call Audio Codec Stop function */ - if (Codec_Stop(Option) != 0) - { - return 1; - } - else - { - /* Call Media layer Stop function */ - Audio_MAL_Stop(); - - /* Update the remaining data number */ - AudioRemSize = AudioTotalSize; - - /* Return 0 when all operations are correctly done */ - return 0; - } -} - -/** - * @brief Controls the current audio volume level. - * @param Volume: Volume level to be set in percentage from 0% to 100% (0 for - * Mute and 100 for Max volume level). - * @retval 0 if correct communication, else wrong communication - */ -uint32_t EVAL_AUDIO_VolumeCtl(uint8_t Volume) -{ - /* Call the codec volume control function with converted volume value */ - return (Codec_VolumeCtrl(VOLUME_CONVERT(Volume))); -} - -/** - * @brief Enables or disables the MUTE mode by software - * @param Command: could be AUDIO_MUTE_ON to mute sound or AUDIO_MUTE_OFF to - * unmute the codec and restore previous volume level. - * @retval 0 if correct communication, else wrong communication - */ -uint32_t EVAL_AUDIO_Mute(uint32_t Cmd) -{ - /* Call the Codec Mute function */ - return (Codec_Mute(Cmd)); -} - -/** - * @brief This function handles main Media layer interrupt. - * @param None - * @retval 0 if correct communication, else wrong communication - */ -static void Audio_MAL_IRQHandler(void) -{ -#ifndef AUDIO_MAL_MODE_NORMAL - uint16_t *pAddr = (uint16_t *)CurrentPos; - uint32_t Size = AudioRemSize; -#endif /* AUDIO_MAL_MODE_NORMAL */ - -#ifdef AUDIO_MAL_DMA_IT_TC_EN - /* Transfer complete interrupt */ - if (DMA_GetFlagStatus(AUDIO_MAL_DMA_STREAM, AUDIO_MAL_DMA_FLAG_TC) != RESET) - { - #ifdef AUDIO_MAL_MODE_NORMAL - /* Check if the end of file has been reached */ - if (AudioRemSize > 0) - { - /* Wait the DMA Stream to be effectively disabled */ - while (DMA_GetCmdStatus(AUDIO_MAL_DMA_STREAM) != DISABLE) - {} - - /* Clear the Interrupt flag */ - DMA_ClearFlag(AUDIO_MAL_DMA_STREAM, AUDIO_MAL_DMA_FLAG_TC); - - /* Re-Configure the buffer address and size */ - DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t) CurrentPos; - DMA_InitStructure.DMA_BufferSize = (uint32_t) (DMA_MAX(AudioRemSize)); - - /* Configure the DMA Stream with the new parameters */ - DMA_Init(AUDIO_MAL_DMA_STREAM, &DMA_InitStructure); - - /* Enable the I2S DMA Stream*/ - DMA_Cmd(AUDIO_MAL_DMA_STREAM, ENABLE); - - /* Update the current pointer position */ - CurrentPos += DMA_MAX(AudioRemSize); - - /* Update the remaining number of data to be played */ - AudioRemSize -= DMA_MAX(AudioRemSize); - } - else - { - /* Disable the I2S DMA Stream*/ - DMA_Cmd(AUDIO_MAL_DMA_STREAM, DISABLE); - - /* Clear the Interrupt flag */ - DMA_ClearFlag(AUDIO_MAL_DMA_STREAM, AUDIO_MAL_DMA_FLAG_TC); - - /* Manage the remaining file size and new address offset: This function - should be coded by user (its prototype is already declared in stm32f4_discovery_audio_codec.h) */ - EVAL_AUDIO_TransferComplete_CallBack((uint32_t)CurrentPos, 0); - } - - #elif defined(AUDIO_MAL_MODE_CIRCULAR) - /* Manage the remaining file size and new address offset: This function - should be coded by user (its prototype is already declared in stm32f4_discovery_audio_codec.h) */ - EVAL_AUDIO_TransferComplete_CallBack(pAddr, Size); - - /* Clear the Interrupt flag */ - DMA_ClearFlag(AUDIO_MAL_DMA_STREAM, AUDIO_MAL_DMA_FLAG_TC); - #endif /* AUDIO_MAL_MODE_NORMAL */ - } -#endif /* AUDIO_MAL_DMA_IT_TC_EN */ - -#ifdef AUDIO_MAL_DMA_IT_HT_EN - /* Half Transfer complete interrupt */ - if (DMA_GetFlagStatus(AUDIO_MAL_DMA_STREAM, AUDIO_MAL_DMA_FLAG_HT) != RESET) - { - /* Manage the remaining file size and new address offset: This function - should be coded by user (its prototype is already declared in stm32f4_discovery_audio_codec.h) */ - EVAL_AUDIO_HalfTransfer_CallBack((uint32_t)pAddr, Size); - - /* Clear the Interrupt flag */ - DMA_ClearFlag(AUDIO_MAL_DMA_STREAM, AUDIO_MAL_DMA_FLAG_HT); - } -#endif /* AUDIO_MAL_DMA_IT_HT_EN */ - -#ifdef AUDIO_MAL_DMA_IT_TE_EN - /* FIFO Error interrupt */ - if ((DMA_GetFlagStatus(AUDIO_MAL_DMA_STREAM, AUDIO_MAL_DMA_FLAG_TE) != RESET) || \ - (DMA_GetFlagStatus(AUDIO_MAL_DMA_STREAM, AUDIO_MAL_DMA_FLAG_FE) != RESET) || \ - (DMA_GetFlagStatus(AUDIO_MAL_DMA_STREAM, AUDIO_MAL_DMA_FLAG_DME) != RESET)) - - { - /* Manage the error generated on DMA FIFO: This function - should be coded by user (its prototype is already declared in stm32f4_discovery_audio_codec.h) */ - EVAL_AUDIO_Error_CallBack((uint32_t*)&pAddr); - - /* Clear the Interrupt flag */ - DMA_ClearFlag(AUDIO_MAL_DMA_STREAM, AUDIO_MAL_DMA_FLAG_TE | AUDIO_MAL_DMA_FLAG_FE | \ - AUDIO_MAL_DMA_FLAG_DME); - } -#endif /* AUDIO_MAL_DMA_IT_TE_EN */ -} - -/** - * @brief This function handles main I2S interrupt. - * @param None - * @retval 0 if correct communication, else wrong communication - */ -void Audio_MAL_I2S_IRQHandler(void) -{ - Audio_MAL_IRQHandler(); -} - -/** - * @brief This function handles main DAC interrupt. - * @param None - * @retval 0 if correct communication, else wrong communication - */ -void Audio_MAL_DAC_IRQHandler(void) -{ - Audio_MAL_IRQHandler(); -} - -/** - * @brief I2S interrupt management - * @param None - * @retval None - */ -void Audio_I2S_IRQHandler(void) -{ - /* Check on the I2S TXE flag */ - if (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE) != RESET) - { - if (CurrAudioInterface == AUDIO_INTERFACE_DAC) - { - /* Wirte data to the DAC interface */ - DAC_SetChannel1Data(DAC_Align_12b_L, EVAL_AUDIO_GetSampleCallBack()); - } - - /* Send dummy data on I2S to avoid the underrun condition */ - SPI_I2S_SendData(CODEC_I2S, EVAL_AUDIO_GetSampleCallBack()); - } -} -/*======================== - - CS43L22 Audio Codec Control Functions - ==============================*/ -/** - * @brief Initializes the audio codec and all related interfaces (control - * interface: I2C and audio interface: I2S) - * @param OutputDevice: can be OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE, - * OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO . - * @param Volume: Initial volume level (from 0 (Mute) to 100 (Max)) - * @param AudioFreq: Audio frequency used to play the audio stream. - * @retval 0 if correct communication, else wrong communication - */ -static uint32_t Codec_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq) -{ - uint32_t counter = 0; - - /* Configure the Codec related IOs */ - Codec_GPIO_Init(); - - /* Reset the Codec Registers */ - Codec_Reset(); - - /* Initialize the Control interface of the Audio Codec */ - Codec_CtrlInterface_Init(); - - /* Keep Codec powered OFF */ - counter += Codec_WriteRegister(0x02, 0x01); - - counter += Codec_WriteRegister(0x04, 0xAF); /* SPK always OFF & HP always ON */ - OutputDev = 0xAF; - - /* Clock configuration: Auto detection */ - counter += Codec_WriteRegister(0x05, 0x81); - - /* Set the Slave Mode and the audio Standard */ - counter += Codec_WriteRegister(0x06, CODEC_STANDARD); - - /* Set the Master volume */ - Codec_VolumeCtrl(Volume); - - if (CurrAudioInterface == AUDIO_INTERFACE_DAC) - { - /* Enable the PassThrough on AIN1A and AIN1B */ - counter += Codec_WriteRegister(0x08, 0x01); - counter += Codec_WriteRegister(0x09, 0x01); - - /* Route the analog input to the HP line */ - counter += Codec_WriteRegister(0x0E, 0xC0); - - /* Set the Passthough volume */ - counter += Codec_WriteRegister(0x14, 0x00); - counter += Codec_WriteRegister(0x15, 0x00); - } - - /* Power on the Codec */ - counter += Codec_WriteRegister(0x02, 0x9E); - - /* Additional configuration for the CODEC. These configurations are done to reduce - the time needed for the Codec to power off. If these configurations are removed, - then a long delay should be added between powering off the Codec and switching - off the I2S peripheral MCLK clock (which is the operating clock for Codec). - If this delay is not inserted, then the codec will not shut down properly and - it results in high noise after shut down. */ - - /* Disable the analog soft ramp */ - counter += Codec_WriteRegister(0x0A, 0x00); - if (CurrAudioInterface != AUDIO_INTERFACE_DAC) - { - /* Disable the digital soft ramp */ - counter += Codec_WriteRegister(0x0E, 0x04); - } - /* Disable the limiter attack level */ - counter += Codec_WriteRegister(0x27, 0x00); - /* Adjust Bass and Treble levels */ - counter += Codec_WriteRegister(0x1F, 0x0F); - /* Adjust PCM volume level */ - counter += Codec_WriteRegister(0x1A, 0x0A); - counter += Codec_WriteRegister(0x1B, 0x0A); - - /* Configure the I2S peripheral */ - Codec_AudioInterface_Init(AudioFreq); - - /* Return communication control value */ - return counter; -} - -/** - * @brief Restore the audio codec state to default state and free all used - * resources. - * @param None - * @retval 0 if correct communication, else wrong communication - */ -static uint32_t Codec_DeInit(void) -{ - uint32_t counter = 0; - - /* Reset the Codec Registers */ - Codec_Reset(); - - /* Keep Codec powered OFF */ - counter += Codec_WriteRegister(0x02, 0x01); - - /* Deinitialize all use GPIOs */ - Codec_GPIO_DeInit(); - - /* Disable the Codec control interface */ - Codec_CtrlInterface_DeInit(); - - /* Deinitialize the Codec audio interface (I2S) */ - Codec_AudioInterface_DeInit(); - - /* Return communication control value */ - return counter; -} - -/** - * @brief Start the audio Codec play feature. - * @note For this codec no Play options are required. - * @param None - * @retval 0 if correct communication, else wrong communication - */ -static uint32_t Codec_Play(void) -{ - /* - No actions required on Codec level for play command - */ - - /* Return communication control value */ - return 0; -} - -/** - * @brief Pauses and resumes playing on the audio codec. - * @param Cmd: AUDIO_PAUSE (or 0) to pause, AUDIO_RESUME (or any value different - * from 0) to resume. - * @retval 0 if correct communication, else wrong communication - */ -static uint32_t Codec_PauseResume(uint32_t Cmd) -{ - uint32_t counter = 0; - - /* Pause the audio file playing */ - if (Cmd == AUDIO_PAUSE) - { - /* Mute the output first */ - counter += Codec_Mute(AUDIO_MUTE_ON); - - /* Put the Codec in Power save mode */ - counter += Codec_WriteRegister(0x02, 0x01); - } - else /* AUDIO_RESUME */ - { - /* Unmute the output first */ - counter += Codec_Mute(AUDIO_MUTE_OFF); - - counter += Codec_WriteRegister(0x04, OutputDev); - - /* Exit the Power save mode */ - counter += Codec_WriteRegister(0x02, 0x9E); - } - - return counter; -} - -/** - * @brief Stops audio Codec playing. It powers down the codec. - * @param CodecPdwnMode: selects the power down mode. - * - CODEC_PDWN_SW: only mutes the audio codec. When resuming from this - * mode the codec keeps the previous initialization - * (no need to re-Initialize the codec registers). - * - CODEC_PDWN_HW: Physically power down the codec. When resuming from this - * mode, the codec is set to default configuration - * (user should re-Initialize the codec in order to - * play again the audio stream). - * @retval 0 if correct communication, else wrong communication - */ -static uint32_t Codec_Stop(uint32_t CodecPdwnMode) -{ - uint32_t counter = 0; - - /* Mute the output first */ - Codec_Mute(AUDIO_MUTE_ON); - - if (CodecPdwnMode == CODEC_PDWN_SW) - { - /* Power down the DAC and the speaker (PMDAC and PMSPK bits)*/ - counter += Codec_WriteRegister(0x02, 0x9F); - } - else /* CODEC_PDWN_HW */ - { - /* Power down the DAC components */ - counter += Codec_WriteRegister(0x02, 0x9F); - - /* Wait at least 100us */ - Delay(0xFFF); - - /* Reset The pin */ - GPIO_WriteBit(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, Bit_RESET); - } - - return counter; -} - -/** - * @brief Sets higher or lower the codec volume level. - * @param Volume: a byte value from 0 to 255 (refer to codec registers - * description for more details). - * @retval 0 if correct communication, else wrong communication - */ -static uint32_t Codec_VolumeCtrl(uint8_t Volume) -{ - uint32_t counter = 0; - - if (Volume > 0xE6) - { - /* Set the Master volume */ - counter += Codec_WriteRegister(0x20, Volume - 0xE7); - counter += Codec_WriteRegister(0x21, Volume - 0xE7); - } - else - { - /* Set the Master volume */ - counter += Codec_WriteRegister(0x20, Volume + 0x19); - counter += Codec_WriteRegister(0x21, Volume + 0x19); - } - - return counter; -} - -/** - * @brief Enables or disables the mute feature on the audio codec. - * @param Cmd: AUDIO_MUTE_ON to enable the mute or AUDIO_MUTE_OFF to disable the - * mute mode. - * @retval 0 if correct communication, else wrong communication - */ -static uint32_t Codec_Mute(uint32_t Cmd) -{ - uint32_t counter = 0; - - /* Set the Mute mode */ - if (Cmd == AUDIO_MUTE_ON) - { - counter += Codec_WriteRegister(0x04, 0xFF); - } - else /* AUDIO_MUTE_OFF Disable the Mute */ - { - counter += Codec_WriteRegister(0x04, OutputDev); - } - - return counter; -} - -/** - * @brief Resets the audio codec. It restores the default configuration of the - * codec (this function shall be called before initializing the codec). - * @note This function calls an external driver function: The IO Expander driver. - * @param None - * @retval None - */ -static void Codec_Reset(void) -{ - /* Power Down the codec */ - GPIO_WriteBit(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, Bit_RESET); - - /* wait for a delay to insure registers erasing */ - Delay(CODEC_RESET_DELAY); - - /* Power on the codec */ - GPIO_WriteBit(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, Bit_SET); -} - -/** - * @brief Writes a Byte to a given register into the audio codec through the - control interface (I2C) - * @param RegisterAddr: The address (location) of the register to be written. - * @param RegisterValue: the Byte value to be written into destination register. - * @retval 0 if correct communication, else wrong communication - */ -static uint32_t Codec_WriteRegister(uint8_t RegisterAddr, uint8_t RegisterValue) -{ - uint32_t result = 0; - - /*!< While the bus is busy */ - CODECTimeout = CODEC_LONG_TIMEOUT; - while(I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_BUSY)) - { - if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback(); - } - - /* Start the config sequence */ - I2C_GenerateSTART(CODEC_I2C, ENABLE); - - /* Test on EV5 and clear it */ - CODECTimeout = CODEC_FLAG_TIMEOUT; - while (!I2C_CheckEvent(CODEC_I2C, I2C_EVENT_MASTER_MODE_SELECT)) - { - if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback(); - } - - /* Transmit the slave address and enable writing operation */ - I2C_Send7bitAddress(CODEC_I2C, CODEC_ADDRESS, I2C_Direction_Transmitter); - - /* Test on EV6 and clear it */ - CODECTimeout = CODEC_FLAG_TIMEOUT; - while (!I2C_CheckEvent(CODEC_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) - { - if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback(); - } - - /* Transmit the first address for write operation */ - I2C_SendData(CODEC_I2C, RegisterAddr); - - /* Test on EV8 and clear it */ - CODECTimeout = CODEC_FLAG_TIMEOUT; - while (!I2C_CheckEvent(CODEC_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTING)) - { - if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback(); - } - - /* Prepare the register value to be sent */ - I2C_SendData(CODEC_I2C, RegisterValue); - - /*!< Wait till all data have been physically transferred on the bus */ - CODECTimeout = CODEC_LONG_TIMEOUT; - while(!I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_BTF)) - { - if((CODECTimeout--) == 0) Codec_TIMEOUT_UserCallback(); - } - - /* End the configuration sequence */ - I2C_GenerateSTOP(CODEC_I2C, ENABLE); - -#ifdef VERIFY_WRITTENDATA - /* Verify that the data has been correctly written */ - result = (Codec_ReadRegister(RegisterAddr) == RegisterValue)? 0:1; -#endif /* VERIFY_WRITTENDATA */ - - /* Return the verifying value: 0 (Passed) or 1 (Failed) */ - return result; -} - -/** - * @brief Reads and returns the value of an audio codec register through the - * control interface (I2C). - * @param RegisterAddr: Address of the register to be read. - * @retval Value of the register to be read or dummy value if the communication - * fails. - */ -static uint32_t Codec_ReadRegister(uint8_t RegisterAddr) -{ - uint32_t result = 0; - - /*!< While the bus is busy */ - CODECTimeout = CODEC_LONG_TIMEOUT; - while(I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_BUSY)) - { - if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback(); - } - - /* Start the config sequence */ - I2C_GenerateSTART(CODEC_I2C, ENABLE); - - /* Test on EV5 and clear it */ - CODECTimeout = CODEC_FLAG_TIMEOUT; - while (!I2C_CheckEvent(CODEC_I2C, I2C_EVENT_MASTER_MODE_SELECT)) - { - if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback(); - } - - /* Transmit the slave address and enable writing operation */ - I2C_Send7bitAddress(CODEC_I2C, CODEC_ADDRESS, I2C_Direction_Transmitter); - - /* Test on EV6 and clear it */ - CODECTimeout = CODEC_FLAG_TIMEOUT; - while (!I2C_CheckEvent(CODEC_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) - { - if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback(); - } - - /* Transmit the register address to be read */ - I2C_SendData(CODEC_I2C, RegisterAddr); - - /* Test on EV8 and clear it */ - CODECTimeout = CODEC_FLAG_TIMEOUT; - while (I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_BTF) == RESET) - { - if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback(); - } - - /*!< Send START condition a second time */ - I2C_GenerateSTART(CODEC_I2C, ENABLE); - - /*!< Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */ - CODECTimeout = CODEC_FLAG_TIMEOUT; - while(!I2C_CheckEvent(CODEC_I2C, I2C_EVENT_MASTER_MODE_SELECT)) - { - if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback(); - } - - /*!< Send Codec address for read */ - I2C_Send7bitAddress(CODEC_I2C, CODEC_ADDRESS, I2C_Direction_Receiver); - - /* Wait on ADDR flag to be set (ADDR is still not cleared at this level */ - CODECTimeout = CODEC_FLAG_TIMEOUT; - while(I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_ADDR) == RESET) - { - if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback(); - } - - /*!< Disable Acknowledgment */ - I2C_AcknowledgeConfig(CODEC_I2C, DISABLE); - - /* Clear ADDR register by reading SR1 then SR2 register (SR1 has already been read) */ - (void)CODEC_I2C->SR2; - - /*!< Send STOP Condition */ - I2C_GenerateSTOP(CODEC_I2C, ENABLE); - - /* Wait for the byte to be received */ - CODECTimeout = CODEC_FLAG_TIMEOUT; - while(I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_RXNE) == RESET) - { - if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback(); - } - - /*!< Read the byte received from the Codec */ - result = I2C_ReceiveData(CODEC_I2C); - - /* Wait to make sure that STOP flag has been cleared */ - CODECTimeout = CODEC_FLAG_TIMEOUT; - while(CODEC_I2C->CR1 & I2C_CR1_STOP) - { - if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback(); - } - - /*!< Re-Enable Acknowledgment to be ready for another reception */ - I2C_AcknowledgeConfig(CODEC_I2C, ENABLE); - - /* Clear AF flag for next communication */ - I2C_ClearFlag(CODEC_I2C, I2C_FLAG_AF); - - /* Return the byte read from Codec */ - return result; -} - -/** - * @brief Initializes the Audio Codec control interface (I2C). - * @param None - * @retval None - */ -static void Codec_CtrlInterface_Init(void) -{ - I2C_InitTypeDef I2C_InitStructure; - - /* Enable the CODEC_I2C peripheral clock */ - RCC_APB1PeriphClockCmd(CODEC_I2C_CLK, ENABLE); - - /* CODEC_I2C peripheral configuration */ - I2C_DeInit(CODEC_I2C); - I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; - I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; - I2C_InitStructure.I2C_OwnAddress1 = 0x33; - I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; - I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; - I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED; - /* Enable the I2C peripheral */ - I2C_Cmd(CODEC_I2C, ENABLE); - I2C_Init(CODEC_I2C, &I2C_InitStructure); -} - -/** - * @brief Restore the Audio Codec control interface to its default state. - * This function doesn't de-initialize the I2C because the I2C peripheral - * may be used by other modules. - * @param None - * @retval None - */ -static void Codec_CtrlInterface_DeInit(void) -{ - /* Disable the I2C peripheral */ /* This step is not done here because - the I2C interface can be used by other modules */ - /* I2C_DeInit(CODEC_I2C); */ -} - -/** - * @brief Initializes the Audio Codec audio interface (I2S) - * @note This function assumes that the I2S input clock (through PLL_R in - * Devices RevA/Z and through dedicated PLLI2S_R in Devices RevB/Y) - * is already configured and ready to be used. - * @param AudioFreq: Audio frequency to be configured for the I2S peripheral. - * @retval None - */ -static void Codec_AudioInterface_Init(uint32_t AudioFreq) -{ - I2S_InitTypeDef I2S_InitStructure; - DAC_InitTypeDef DAC_InitStructure; - - /* Enable the CODEC_I2S peripheral clock */ - RCC_APB1PeriphClockCmd(CODEC_I2S_CLK, ENABLE); - - /* CODEC_I2S peripheral configuration */ - SPI_I2S_DeInit(CODEC_I2S); - I2S_InitStructure.I2S_AudioFreq = AudioFreq; - I2S_InitStructure.I2S_Standard = I2S_STANDARD; - I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b; - I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low; -#ifdef DAC_USE_I2S_DMA - if (CurrAudioInterface == AUDIO_INTERFACE_DAC) - { - I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx; - } - else - { -#else - I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx; -#endif -#ifdef DAC_USE_I2S_DMA - } -#endif /* DAC_USE_I2S_DMA */ -#ifdef CODEC_MCLK_ENABLED - I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable; -#elif defined(CODEC_MCLK_DISABLED) - I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable; -#else -#error "No selection for the MCLK output has been defined !" -#endif /* CODEC_MCLK_ENABLED */ - - /* Initialize the I2S peripheral with the structure above */ - I2S_Init(CODEC_I2S, &I2S_InitStructure); - - - /* Configure the DAC interface */ - if (CurrAudioInterface == AUDIO_INTERFACE_DAC) - { - /* DAC Periph clock enable */ - RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); - - /* DAC channel1 Configuration */ - DAC_InitStructure.DAC_Trigger = DAC_Trigger_None; - DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; - DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; - DAC_Init(AUDIO_DAC_CHANNEL, &DAC_InitStructure); - - /* Enable DAC Channel1 */ - DAC_Cmd(AUDIO_DAC_CHANNEL, ENABLE); - } - - /* The I2S peripheral will be enabled only in the EVAL_AUDIO_Play() function - or by user functions if DMA mode not enabled */ -} - -/** - * @brief Restores the Audio Codec audio interface to its default state. - * @param None - * @retval None - */ -static void Codec_AudioInterface_DeInit(void) -{ - /* Disable the CODEC_I2S peripheral (in case it hasn't already been disabled) */ - I2S_Cmd(CODEC_I2S, DISABLE); - - /* Deinitialize the CODEC_I2S peripheral */ - SPI_I2S_DeInit(CODEC_I2S); - - /* Disable the CODEC_I2S peripheral clock */ - RCC_APB1PeriphClockCmd(CODEC_I2S_CLK, DISABLE); -} - -/** - * @brief Initializes IOs used by the Audio Codec (on the control and audio - * interfaces). - * @param None - * @retval None - */ -static void Codec_GPIO_Init(void) -{ - GPIO_InitTypeDef GPIO_InitStructure; - - /* Enable Reset GPIO Clock */ - RCC_AHB1PeriphClockCmd(AUDIO_RESET_GPIO_CLK,ENABLE); - - /* Audio reset pin configuration -------------------------------------------------*/ - GPIO_InitStructure.GPIO_Pin = AUDIO_RESET_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(AUDIO_RESET_GPIO, &GPIO_InitStructure); - - /* Enable I2S and I2C GPIO clocks */ - RCC_AHB1PeriphClockCmd(CODEC_I2C_GPIO_CLOCK | CODEC_I2S_GPIO_CLOCK, ENABLE); - - /* CODEC_I2C SCL and SDA pins configuration -------------------------------------*/ - GPIO_InitStructure.GPIO_Pin = CODEC_I2C_SCL_PIN | CODEC_I2C_SDA_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(CODEC_I2C_GPIO, &GPIO_InitStructure); - /* Connect pins to I2C peripheral */ - GPIO_PinAFConfig(CODEC_I2C_GPIO, CODEC_I2S_SCL_PINSRC, CODEC_I2C_GPIO_AF); - GPIO_PinAFConfig(CODEC_I2C_GPIO, CODEC_I2S_SDA_PINSRC, CODEC_I2C_GPIO_AF); - - /* CODEC_I2S pins configuration: WS, SCK and SD pins -----------------------------*/ - GPIO_InitStructure.GPIO_Pin = CODEC_I2S_SCK_PIN | CODEC_I2S_SD_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure); - - /* Connect pins to I2S peripheral */ - GPIO_PinAFConfig(CODEC_I2S_WS_GPIO, CODEC_I2S_WS_PINSRC, CODEC_I2S_GPIO_AF); - GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SCK_PINSRC, CODEC_I2S_GPIO_AF); - - if (CurrAudioInterface != AUDIO_INTERFACE_DAC) - { - GPIO_InitStructure.GPIO_Pin = CODEC_I2S_WS_PIN ; - GPIO_Init(CODEC_I2S_WS_GPIO, &GPIO_InitStructure); - GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SD_PINSRC, CODEC_I2S_GPIO_AF); - } - else - { - /* GPIOA clock enable (to be used with DAC) */ - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); - - /* DAC channel 1 & 2 (DAC_OUT1 = PA.4) configuration */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOA, &GPIO_InitStructure); - } - -#ifdef CODEC_MCLK_ENABLED - /* CODEC_I2S pins configuration: MCK pin */ - GPIO_InitStructure.GPIO_Pin = CODEC_I2S_MCK_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(CODEC_I2S_MCK_GPIO, &GPIO_InitStructure); - /* Connect pins to I2S peripheral */ - GPIO_PinAFConfig(CODEC_I2S_MCK_GPIO, CODEC_I2S_MCK_PINSRC, CODEC_I2S_GPIO_AF); -#endif /* CODEC_MCLK_ENABLED */ -} - -/** - * @brief Restores the IOs used by the Audio Codec interface to their default state. - * @param None - * @retval None - */ -static void Codec_GPIO_DeInit(void) -{ - GPIO_InitTypeDef GPIO_InitStructure; - - /* Deinitialize all the GPIOs used by the driver */ - GPIO_InitStructure.GPIO_Pin = CODEC_I2S_SCK_PIN | CODEC_I2S_SD_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure); - - GPIO_InitStructure.GPIO_Pin = CODEC_I2S_WS_PIN ; - GPIO_Init(CODEC_I2S_WS_GPIO, &GPIO_InitStructure); - - /* Disconnect pins from I2S peripheral */ - GPIO_PinAFConfig(CODEC_I2S_WS_GPIO, CODEC_I2S_WS_PINSRC, 0x00); - GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SCK_PINSRC, 0x00); - GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SD_PINSRC, 0x00); - -#ifdef CODEC_MCLK_ENABLED - /* CODEC_I2S pins deinitialization: MCK pin */ - GPIO_InitStructure.GPIO_Pin = CODEC_I2S_MCK_PIN; - GPIO_Init(CODEC_I2S_MCK_GPIO, &GPIO_InitStructure); - /* Disconnect pins from I2S peripheral */ - GPIO_PinAFConfig(CODEC_I2S_MCK_GPIO, CODEC_I2S_MCK_PINSRC, CODEC_I2S_GPIO_AF); -#endif /* CODEC_MCLK_ENABLED */ -} - -/** - * @brief Inserts a delay time (not accurate timing). - * @param nCount: specifies the delay time length. - * @retval None - */ -static void Delay( __IO uint32_t nCount) -{ - for (; nCount != 0; nCount--); -} - -#ifdef USE_DEFAULT_TIMEOUT_CALLBACK -/** - * @brief Basic management of the timeout situation. - * @param None - * @retval None - */ -uint32_t Codec_TIMEOUT_UserCallback(void) -{ - /* Block communication and all processes */ - while (1) - { - } -} -#endif /* USE_DEFAULT_TIMEOUT_CALLBACK */ -/*======================== - - Audio MAL Interface Control Functions - - ==============================*/ - -/** - * @brief Initializes and prepares the Media to perform audio data transfer - * from Media to the I2S peripheral. - * @param None - * @retval None - */ -static void Audio_MAL_Init(void) -{ - -#ifdef I2S_INTERRUPT - NVIC_InitTypeDef NVIC_InitStructure; - - NVIC_InitStructure.NVIC_IRQChannel = SPI3_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; - NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); - - SPI_I2S_ITConfig(SPI3, SPI_I2S_IT_TXE, ENABLE); - - I2S_Cmd(SPI3, ENABLE); -#else -#if defined(AUDIO_MAL_DMA_IT_TC_EN) || defined(AUDIO_MAL_DMA_IT_HT_EN) || defined(AUDIO_MAL_DMA_IT_TE_EN) - NVIC_InitTypeDef NVIC_InitStructure; -#endif - - if (CurrAudioInterface == AUDIO_INTERFACE_I2S) - { - /* Enable the DMA clock */ - RCC_AHB1PeriphClockCmd(AUDIO_MAL_DMA_CLOCK, ENABLE); - - /* Configure the DMA Stream */ - DMA_Cmd(AUDIO_MAL_DMA_STREAM, DISABLE); - DMA_DeInit(AUDIO_MAL_DMA_STREAM); - /* Set the parameters to be configured */ - DMA_InitStructure.DMA_Channel = AUDIO_MAL_DMA_CHANNEL; - DMA_InitStructure.DMA_PeripheralBaseAddr = AUDIO_MAL_DMA_DREG; - DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)0; /* This field will be configured in play function */ - DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; - DMA_InitStructure.DMA_BufferSize = (uint32_t)0xFFFE; /* This field will be configured in play function */ - DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; - DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; - DMA_InitStructure.DMA_PeripheralDataSize = AUDIO_MAL_DMA_PERIPH_DATA_SIZE; - DMA_InitStructure.DMA_MemoryDataSize = AUDIO_MAL_DMA_MEM_DATA_SIZE; -#ifdef AUDIO_MAL_MODE_NORMAL - DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; -#elif defined(AUDIO_MAL_MODE_CIRCULAR) - DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; -#else -#error "AUDIO_MAL_MODE_NORMAL or AUDIO_MAL_MODE_CIRCULAR should be selected !!" -#endif /* AUDIO_MAL_MODE_NORMAL */ - DMA_InitStructure.DMA_Priority = DMA_Priority_High; - DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable; - DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; - DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; - DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; - DMA_Init(AUDIO_MAL_DMA_STREAM, &DMA_InitStructure); - - /* Enable the selected DMA interrupts (selected in "stm32f4_discovery_eval_audio_codec.h" defines) */ -#ifdef AUDIO_MAL_DMA_IT_TC_EN - DMA_ITConfig(AUDIO_MAL_DMA_STREAM, DMA_IT_TC, ENABLE); -#endif /* AUDIO_MAL_DMA_IT_TC_EN */ -#ifdef AUDIO_MAL_DMA_IT_HT_EN - DMA_ITConfig(AUDIO_MAL_DMA_STREAM, DMA_IT_HT, ENABLE); -#endif /* AUDIO_MAL_DMA_IT_HT_EN */ -#ifdef AUDIO_MAL_DMA_IT_TE_EN - DMA_ITConfig(AUDIO_MAL_DMA_STREAM, DMA_IT_TE | DMA_IT_FE | DMA_IT_DME, ENABLE); -#endif /* AUDIO_MAL_DMA_IT_TE_EN */ - -#if defined(AUDIO_MAL_DMA_IT_TC_EN) || defined(AUDIO_MAL_DMA_IT_HT_EN) || defined(AUDIO_MAL_DMA_IT_TE_EN) - /* I2S DMA IRQ Channel configuration */ - NVIC_InitStructure.NVIC_IRQChannel = AUDIO_MAL_DMA_IRQ; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EVAL_AUDIO_IRQ_PREPRIO; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = EVAL_AUDIO_IRQ_SUBRIO; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); -#endif - } - -#ifdef DAC_USE_I2S_DMA - else - { - /* Enable the DMA clock */ - RCC_AHB1PeriphClockCmd(AUDIO_MAL_DMA_CLOCK, ENABLE); - - /* Configure the DMA Stream */ - DMA_Cmd(AUDIO_MAL_DMA_STREAM, DISABLE); - DMA_DeInit(AUDIO_MAL_DMA_STREAM); - /* Set the parameters to be configured */ - DMA_InitStructure.DMA_Channel = AUDIO_MAL_DMA_CHANNEL; - DMA_InitStructure.DMA_PeripheralBaseAddr = AUDIO_MAL_DMA_DREG; - DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)0; /* This field will be configured in play function */ - DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; - DMA_InitStructure.DMA_BufferSize = (uint32_t)0xFFFE; /* This field will be configured in play function */ - DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; - DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; - DMA_InitStructure.DMA_PeripheralDataSize = AUDIO_MAL_DMA_PERIPH_DATA_SIZE; - DMA_InitStructure.DMA_MemoryDataSize = AUDIO_MAL_DMA_MEM_DATA_SIZE; -#ifdef AUDIO_MAL_MODE_NORMAL - DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; -#elif defined(AUDIO_MAL_MODE_CIRCULAR) - DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; -#else -#error "AUDIO_MAL_MODE_NORMAL or AUDIO_MAL_MODE_CIRCULAR should be selected !!" -#endif /* AUDIO_MAL_MODE_NORMAL */ - DMA_InitStructure.DMA_Priority = DMA_Priority_High; - DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable; - DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; - DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; - DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; - DMA_Init(AUDIO_MAL_DMA_STREAM, &DMA_InitStructure); - - /* Enable the selected DMA interrupts (selected in "stm32f4_discovery_eval_audio_codec.h" defines) */ -#ifdef AUDIO_MAL_DMA_IT_TC_EN - DMA_ITConfig(AUDIO_MAL_DMA_STREAM, DMA_IT_TC, ENABLE); -#endif /* AUDIO_MAL_DMA_IT_TC_EN */ -#ifdef AUDIO_MAL_DMA_IT_HT_EN - DMA_ITConfig(AUDIO_MAL_DMA_STREAM, DMA_IT_HT, ENABLE); -#endif /* AUDIO_MAL_DMA_IT_HT_EN */ -#ifdef AUDIO_MAL_DMA_IT_TE_EN - DMA_ITConfig(AUDIO_MAL_DMA_STREAM, DMA_IT_TE | DMA_IT_FE | DMA_IT_DME, ENABLE); -#endif /* AUDIO_MAL_DMA_IT_TE_EN */ - -#if defined(AUDIO_MAL_DMA_IT_TC_EN) || defined(AUDIO_MAL_DMA_IT_HT_EN) || defined(AUDIO_MAL_DMA_IT_TE_EN) - /* I2S DMA IRQ Channel configuration */ - NVIC_InitStructure.NVIC_IRQChannel = AUDIO_MAL_DMA_IRQ; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EVAL_AUDIO_IRQ_PREPRIO; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = EVAL_AUDIO_IRQ_SUBRIO; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); -#endif - } -#endif /* DAC_USE_I2S_DMA */ - - if (CurrAudioInterface == AUDIO_INTERFACE_I2S) - { - /* Enable the I2S DMA request */ - SPI_I2S_DMACmd(CODEC_I2S, SPI_I2S_DMAReq_Tx, ENABLE); - } - else - { - /* Configure the STM32 DAC to geenrate audio analog signal */ - DAC_Config(); - -#ifndef DAC_USE_I2S_DMA - /* Enable the I2S interrupt used to write into the DAC register */ - SPI_I2S_ITConfig(SPI3, SPI_I2S_IT_TXE, ENABLE); - - /* I2S DMA IRQ Channel configuration */ - NVIC_InitStructure.NVIC_IRQChannel = CODEC_I2S_IRQ; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EVAL_AUDIO_IRQ_PREPRIO; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = EVAL_AUDIO_IRQ_SUBRIO; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); -#else - /* Enable the I2S DMA request */ - SPI_I2S_DMACmd(CODEC_I2S, SPI_I2S_DMAReq_Rx, ENABLE); -#endif /* DAC_USE_I2S_DMA */ - } -#endif -} - -/** - * @brief Restore default state of the used Media. - * @param None - * @retval None - */ -static void Audio_MAL_DeInit(void) -{ -#if defined(AUDIO_MAL_DMA_IT_TC_EN) || defined(AUDIO_MAL_DMA_IT_HT_EN) || defined(AUDIO_MAL_DMA_IT_TE_EN) - NVIC_InitTypeDef NVIC_InitStructure; - - /* Deinitialize the NVIC interrupt for the I2S DMA Stream */ - NVIC_InitStructure.NVIC_IRQChannel = AUDIO_MAL_DMA_IRQ; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EVAL_AUDIO_IRQ_PREPRIO; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = EVAL_AUDIO_IRQ_SUBRIO; - NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE; - NVIC_Init(&NVIC_InitStructure); -#endif - - /* Disable the DMA stream before the deinit */ - DMA_Cmd(AUDIO_MAL_DMA_STREAM, DISABLE); - - /* Dinitialize the DMA Stream */ - DMA_DeInit(AUDIO_MAL_DMA_STREAM); - - /* - The DMA clock is not disabled, since it can be used by other streams - */ -} - -/** - * @brief Starts playing audio stream from the audio Media. - * @param None - * @retval None - */ -static void Audio_MAL_Play(uint32_t Addr, uint32_t Size) -{ - if (CurrAudioInterface == AUDIO_INTERFACE_I2S) - { - /* Configure the buffer address and size */ - DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Addr; - DMA_InitStructure.DMA_BufferSize = (uint32_t)Size; - - /* Configure the DMA Stream with the new parameters */ - DMA_Init(AUDIO_MAL_DMA_STREAM, &DMA_InitStructure); - - /* Enable the I2S DMA Stream*/ - DMA_Cmd(AUDIO_MAL_DMA_STREAM, ENABLE); - } -#ifndef DAC_USE_I2S_DMA - else - { - /* Configure the buffer address and size */ - DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Addr; - DMA_InitStructure.DMA_BufferSize = (uint32_t)Size; - - /* Configure the DMA Stream with the new parameters */ - DMA_Init(AUDIO_MAL_DMA_STREAM, &DMA_InitStructure); - - /* Enable the I2S DMA Stream*/ - DMA_Cmd(AUDIO_MAL_DMA_STREAM, ENABLE); - } -#endif /* DAC_USE_I2S_DMA */ - - /* If the I2S peripheral is still not enabled, enable it */ - if ((CODEC_I2S->I2SCFGR & I2S_ENABLE_MASK) == 0) - { - I2S_Cmd(CODEC_I2S, ENABLE); - } -} - -/** - * @brief Pauses or Resumes the audio stream playing from the Media. - * @param Cmd: AUDIO_PAUSE (or 0) to pause, AUDIO_RESUME (or any value different - * from 0) to resume. - * @param Addr: Address from/at which the audio stream should resume/pause. - * @retval None - */ -static void Audio_MAL_PauseResume(uint32_t Cmd, uint32_t Addr) -{ - /* Pause the audio file playing */ - if (Cmd == AUDIO_PAUSE) - { - /* Disable the I2S DMA request */ - SPI_I2S_DMACmd(CODEC_I2S, SPI_I2S_DMAReq_Tx, DISABLE); - - /* Pause the I2S DMA Stream - Note. For the STM32F4xx devices, the DMA implements a pause feature, - by disabling the stream, all configuration is preserved and data - transfer is paused till the next enable of the stream. - This feature is not available on STM32F4xx devices. */ - DMA_Cmd(AUDIO_MAL_DMA_STREAM, DISABLE); - } - else /* AUDIO_RESUME */ - { - /* Enable the I2S DMA request */ - SPI_I2S_DMACmd(CODEC_I2S, SPI_I2S_DMAReq_Tx, ENABLE); - - /* Resume the I2S DMA Stream - Note. For the STM32F4xx devices, the DMA implements a pause feature, - by disabling the stream, all configuration is preserved and data - transfer is paused till the next enable of the stream. - This feature is not available on STM32F4xx devices. */ - DMA_Cmd(AUDIO_MAL_DMA_STREAM, ENABLE); - - /* If the I2S peripheral is still not enabled, enable it */ - if ((CODEC_I2S->I2SCFGR & I2S_ENABLE_MASK) == 0) - { - I2S_Cmd(CODEC_I2S, ENABLE); - } - } -} - -/** - * @brief Stops audio stream playing on the used Media. - * @param None - * @retval None - */ -static void Audio_MAL_Stop(void) -{ - /* Stop the Transfer on the I2S side: Stop and disable the DMA stream */ - DMA_Cmd(AUDIO_MAL_DMA_STREAM, DISABLE); - - /* Clear all the DMA flags for the next transfer */ - DMA_ClearFlag(AUDIO_MAL_DMA_STREAM, AUDIO_MAL_DMA_FLAG_TC |AUDIO_MAL_DMA_FLAG_HT | \ - AUDIO_MAL_DMA_FLAG_FE | AUDIO_MAL_DMA_FLAG_TE); - - /* - The I2S DMA requests are not disabled here. - */ - - /* In all modes, disable the I2S peripheral */ - I2S_Cmd(CODEC_I2S, DISABLE); -} - -/** - * @brief DAC Channel1 Configuration - * @param None - * @retval None - */ -void DAC_Config(void) -{ - DAC_InitTypeDef DAC_InitStructure; - GPIO_InitTypeDef GPIO_InitStructure; - - /* DMA1 clock and GPIOA clock enable (to be used with DAC) */ - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1 | RCC_AHB1Periph_GPIOA, ENABLE); - - /* DAC Periph clock enable */ - RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); - - /* DAC channel 1 & 2 (DAC_OUT1 = PA.4) configuration */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* DAC channel1 Configuration */ - DAC_InitStructure.DAC_Trigger = DAC_Trigger_None; - DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; - DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; - DAC_Init(AUDIO_DAC_CHANNEL, &DAC_InitStructure); - - /* Enable DAC Channel1 */ - DAC_Cmd(AUDIO_DAC_CHANNEL, ENABLE); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/blink2/stm32f4_discovery_audio_codec.h b/examples/STM32F4Discovery/blink2/stm32f4_discovery_audio_codec.h deleted file mode 100644 --- a/examples/STM32F4Discovery/blink2/stm32f4_discovery_audio_codec.h +++ /dev/null @@ -1,304 +0,0 @@ -/** - ****************************************************************************** - * @file stm32f4_discovery_audio_codec.h - * @author MCD Application Team - * @version V1.0.0 - * @date 19-September-2011 - * @brief This file contains all the functions prototypes for the - * stm32f4_discovery_audio_codec.c driver. - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F4_DISCOVERY_AUDIOCODEC_H -#define __STM32F4_DISCOVERY_AUDIOCODEC_H - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx.h" -#include "stm32f4xx_gpio.h" - -/** @addtogroup Utilities - * @{ - */ - - -/** @addtogroup STM32F4_DISCOVERY - * @{ - */ - -/** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC - * @{ - */ - - -/** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC_Exported_Types - * @{ - */ - -/** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC_Exported_Constants - * @{ - */ - -/*------------------------------------ - CONFIGURATION: Audio Codec Driver Configuration parameters - ----------------------------------------*/ -#define I2S_INTERRUPT -/* Audio Transfer mode (DMA, Interrupt or Polling) */ -#define AUDIO_MAL_MODE_NORMAL /* Uncomment this line to enable the audio - Transfer using DMA */ -/* #define AUDIO_MAL_MODE_CIRCULAR */ /* Uncomment this line to enable the audio - Transfer using DMA */ - -/* For the DMA modes select the interrupt that will be used */ -#define AUDIO_MAL_DMA_IT_TC_EN /* Uncomment this line to enable DMA Transfer Complete interrupt */ -/* #define AUDIO_MAL_DMA_IT_HT_EN */ /* Uncomment this line to enable DMA Half Transfer Complete interrupt */ -/* #define AUDIO_MAL_DMA_IT_TE_EN */ /* Uncomment this line to enable DMA Transfer Error interrupt */ - -/* Select the interrupt preemption priority and subpriority for the DMA interrupt */ -#define EVAL_AUDIO_IRQ_PREPRIO 0 /* Select the preemption priority level(0 is the highest) */ -#define EVAL_AUDIO_IRQ_SUBRIO 0 /* Select the sub-priority level (0 is the highest) */ - -/* Uncomment the following line to use the default Codec_TIMEOUT_UserCallback() - function implemented in stm32f4_discovery_audio_codec.c file. - Codec_TIMEOUT_UserCallback() function is called whenever a timeout condition - occurs during communication (waiting on an event that doesn't occur, bus - errors, busy devices ...). */ -/* #define USE_DEFAULT_TIMEOUT_CALLBACK */ - -/* Enable this define to use the I2S DMA for writing into DAC register */ -//#define DAC_USE_I2S_DMA -/*----------------------------------------------------------------------------*/ - -/*------------------------------------ - OPTIONAL Configuration defines parameters - ----------------------------------------*/ -/* I2C clock speed configuration (in Hz) - WARNING: - Make sure that this define is not already declared in other files (ie. - stm322xg_eval.h file). It can be used in parallel by other modules. */ -#ifndef I2C_SPEED - #define I2C_SPEED 100000 -#endif /* I2C_SPEED */ - -/* Uncomment defines below to select standard for audio communication between - Codec and I2S peripheral */ -#define I2S_STANDARD_PHILLIPS -/* #define I2S_STANDARD_MSB */ -/* #define I2S_STANDARD_LSB */ - -/* Uncomment the defines below to select if the Master clock mode should be - enabled or not */ -#define CODEC_MCLK_ENABLED -/* #deine CODEC_MCLK_DISABLED */ - -/* Uncomment this line to enable verifying data sent to codec after each write - operation */ -#define VERIFY_WRITTENDATA -/*----------------------------------------------------------------------------*/ - -/*----------------------------------- - Hardware Configuration defines parameters - -----------------------------------------*/ -/* Audio Reset Pin definition */ -#define AUDIO_RESET_GPIO_CLK RCC_AHB1Periph_GPIOD -#define AUDIO_RESET_PIN GPIO_Pin_4 -#define AUDIO_RESET_GPIO GPIOD - -/* I2S peripheral configuration defines */ -#define CODEC_I2S SPI3 -#define CODEC_I2S_CLK RCC_APB1Periph_SPI3 -#define CODEC_I2S_ADDRESS 0x40003C0C -#define CODEC_I2S_GPIO_AF GPIO_AF_SPI3 -#define CODEC_I2S_IRQ SPI3_IRQn -#define CODEC_I2S_GPIO_CLOCK (RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOA) -#define CODEC_I2S_WS_PIN GPIO_Pin_4 -#define CODEC_I2S_SCK_PIN GPIO_Pin_10 -#define CODEC_I2S_SD_PIN GPIO_Pin_12 -#define CODEC_I2S_MCK_PIN GPIO_Pin_7 -#define CODEC_I2S_WS_PINSRC GPIO_PinSource4 -#define CODEC_I2S_SCK_PINSRC GPIO_PinSource10 -#define CODEC_I2S_SD_PINSRC GPIO_PinSource12 -#define CODEC_I2S_MCK_PINSRC GPIO_PinSource7 -#define CODEC_I2S_GPIO GPIOC -#define CODEC_I2S_WS_GPIO GPIOA -#define CODEC_I2S_MCK_GPIO GPIOC -#define Audio_I2S_IRQHandler SPI3_IRQHandler - - - #define AUDIO_MAL_DMA_PERIPH_DATA_SIZE DMA_PeripheralDataSize_HalfWord - #define AUDIO_MAL_DMA_MEM_DATA_SIZE DMA_MemoryDataSize_HalfWord - #define DMA_MAX_SZE 0xFFFF - - - #define DAC_DHR12L1_ADDRESS 0x4000740C - #define DAC_DHR12R1_ADDRESS 0x40007408 - #define DAC_DHR8R1_ADDRESS 0x40007410 - #define AUDIO_DAC_CHANNEL DAC_Channel_1 - - /* I2S DMA Stream definitions */ - #define AUDIO_I2S_DMA_CLOCK RCC_AHB1Periph_DMA1 - #define AUDIO_I2S_DMA_STREAM DMA1_Stream7 - #define AUDIO_I2S_DMA_DREG CODEC_I2S_ADDRESS - #define AUDIO_I2S_DMA_CHANNEL DMA_Channel_0 - #define AUDIO_I2S_DMA_IRQ DMA1_Stream7_IRQn - #define AUDIO_I2S_DMA_FLAG_TC DMA_FLAG_TCIF7 - #define AUDIO_I2S_DMA_FLAG_HT DMA_FLAG_HTIF7 - #define AUDIO_I2S_DMA_FLAG_FE DMA_FLAG_FEIF7 - #define AUDIO_I2S_DMA_FLAG_TE DMA_FLAG_TEIF7 - #define AUDIO_I2S_DMA_FLAG_DME DMA_FLAG_DMEIF7 - - #define Audio_MAL_I2S_IRQHandler DMA1_Stream7_IRQHandler - - - /* DAC DMA Stream definitions */ - #define AUDIO_DAC_DMA_CLOCK RCC_AHB1Periph_DMA1 - #define AUDIO_DAC_DMA_STREAM DMA1_Stream0 - #define AUDIO_DAC_DMA_DREG DAC_DHR12L1_ADDRESS - #define AUDIO_DAC_DMA_CHANNEL DMA_Channel_0 - #define AUDIO_DAC_DMA_IRQ DMA1_Stream0_IRQn - #define AUDIO_DAC_DMA_FLAG_TC DMA_FLAG_TCIF0 - #define AUDIO_DAC_DMA_FLAG_HT DMA_FLAG_HTIF0 - #define AUDIO_DAC_DMA_FLAG_FE DMA_FLAG_FEIF0 - #define AUDIO_DAC_DMA_FLAG_TE DMA_FLAG_TEIF0 - #define AUDIO_DAC_DMA_FLAG_DME DMA_FLAG_DMEIF0 - - #define Audio_MAL_DAC_IRQHandler DMA1_Stream0_IRQHandler - - -/* I2C peripheral configuration defines (control interface of the audio codec) */ -#define CODEC_I2C I2C1 -#define CODEC_I2C_CLK RCC_APB1Periph_I2C1 -#define CODEC_I2C_GPIO_CLOCK RCC_AHB1Periph_GPIOB -#define CODEC_I2C_GPIO_AF GPIO_AF_I2C1 -#define CODEC_I2C_GPIO GPIOB -#define CODEC_I2C_SCL_PIN GPIO_Pin_6 -#define CODEC_I2C_SDA_PIN GPIO_Pin_9 -#define CODEC_I2S_SCL_PINSRC GPIO_PinSource6 -#define CODEC_I2S_SDA_PINSRC GPIO_PinSource9 - -/* Maximum Timeout values for flags and events waiting loops. These timeouts are - not based on accurate values, they just guarantee that the application will - not remain stuck if the I2C communication is corrupted. - You may modify these timeout values depending on CPU frequency and application - conditions (interrupts routines ...). */ -#define CODEC_FLAG_TIMEOUT ((uint32_t)0x1000) -#define CODEC_LONG_TIMEOUT ((uint32_t)(300 * CODEC_FLAG_TIMEOUT)) -/*----------------------------------------------------------------------------*/ - -/*----------------------------------- - Audio Codec User defines - -----------------------------------------*/ -/* Audio interface : I2S or DAC */ -#define AUDIO_INTERFACE_I2S 1 -#define AUDIO_INTERFACE_DAC 2 - -/* Codec output DEVICE */ -#define OUTPUT_DEVICE_SPEAKER 1 -#define OUTPUT_DEVICE_HEADPHONE 2 -#define OUTPUT_DEVICE_BOTH 3 -#define OUTPUT_DEVICE_AUTO 4 - -/* Volume Levels values */ -#define DEFAULT_VOLMIN 0x00 -#define DEFAULT_VOLMAX 0xFF -#define DEFAULT_VOLSTEP 0x04 - -#define AUDIO_PAUSE 0 -#define AUDIO_RESUME 1 - -/* Codec POWER DOWN modes */ -#define CODEC_PDWN_HW 1 -#define CODEC_PDWN_SW 2 - -/* MUTE commands */ -#define AUDIO_MUTE_ON 1 -#define AUDIO_MUTE_OFF 0 -/*----------------------------------------------------------------------------*/ -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC_Exported_Macros - * @{ - */ -#define VOLUME_CONVERT(x) ((Volume > 100)? 100:((uint8_t)((Volume * 255) / 100))) -#define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE) - -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC_Exported_Functions - * @{ - */ -void EVAL_AUDIO_SetAudioInterface(uint32_t Interface); -uint32_t EVAL_AUDIO_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq); -uint32_t EVAL_AUDIO_DeInit(void); -uint32_t EVAL_AUDIO_Play(uint16_t* pBuffer, uint32_t Size); -uint32_t EVAL_AUDIO_PauseResume(uint32_t Cmd); -uint32_t EVAL_AUDIO_Stop(uint32_t CodecPowerDown_Mode); -uint32_t EVAL_AUDIO_VolumeCtl(uint8_t Volume); -uint32_t EVAL_AUDIO_Mute(uint32_t Command); -void DAC_Config(void); - -/* User Callbacks: user has to implement these functions in his code if - they are needed. -----------------------------------------------------------*/ - -uint16_t EVAL_AUDIO_GetSampleCallBack(void); - -/* This function is called when the requested data has been completely transferred. - In Normal mode (when the define AUDIO_MAL_MODE_NORMAL is enabled) this function - is called at the end of the whole audio file. - In circular mode (when the define AUDIO_MAL_MODE_CIRCULAR is enabled) this - function is called at the end of the current buffer transmission. */ -void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size); - -/* This function is called when half of the requested buffer has been transferred - This callback is useful in Circular mode only (when AUDIO_MAL_MODE_CIRCULAR - define is enabled)*/ -void EVAL_AUDIO_HalfTransfer_CallBack(uint32_t pBuffer, uint32_t Size); - -/* This function is called when an Interrupt due to transfer error on or peripheral - error occurs. */ -void EVAL_AUDIO_Error_CallBack(void* pData); - -/* Codec_TIMEOUT_UserCallback() function is called whenever a timeout condition - occurs during communication (waiting on an event that doesn't occur, bus - errors, busy devices ...) on the Codec control interface (I2C). - You can use the default timeout callback implementation by uncommenting the - define USE_DEFAULT_TIMEOUT_CALLBACK in stm32f4_discovery_audio_codec.h file. - Typically the user implementation of this callback should reset I2C peripheral - and re-initialize communication or in worst case reset all the application. */ -uint32_t Codec_TIMEOUT_UserCallback(void); - -#endif /* __STM32F4_DISCOVERY_AUDIOCODEC_H */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/blink2/stm32f4_discovery_lis302dl.c b/examples/STM32F4Discovery/blink2/stm32f4_discovery_lis302dl.c deleted file mode 100644 --- a/examples/STM32F4Discovery/blink2/stm32f4_discovery_lis302dl.c +++ /dev/null @@ -1,504 +0,0 @@ -/** - ****************************************************************************** - * @file stm32f4_discovery_lis302dl.c - * @author MCD Application Team - * @version V1.0.0 - * @date 19-September-2011 - * @brief This file provides a set of functions needed to manage the LIS302DL - * MEMS accelerometer available on STM32F4-Discovery Kit. - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4_discovery_lis302dl.h" -//ADDED BY ME!!!!!!!!!!!!!!!!!!!! -#include "stm32f4xx_conf.h" - -/** @addtogroup Utilities - * @{ - */ - -/** @addtogroup STM32F4_DISCOVERY - * @{ - */ - -/** @addtogroup STM32F4_DISCOVERY_LIS302DL - * @{ - */ - - -/** @defgroup STM32F4_DISCOVERY_LIS302DL_Private_TypesDefinitions - * @{ - */ - -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_LIS302DL_Private_Defines - * @{ - */ -__IO uint32_t LIS302DLTimeout = LIS302DL_FLAG_TIMEOUT; - -/* Read/Write command */ -#define READWRITE_CMD ((uint8_t)0x80) -/* Multiple byte read/write command */ -#define MULTIPLEBYTE_CMD ((uint8_t)0x40) -/* Dummy Byte Send by the SPI Master device in order to generate the Clock to the Slave device */ -#define DUMMY_BYTE ((uint8_t)0x00) - -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_LIS302DL_Private_Macros - * @{ - */ - -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_LIS302DL_Private_Variables - * @{ - */ - -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_LIS302DL_Private_FunctionPrototypes - * @{ - */ -static uint8_t LIS302DL_SendByte(uint8_t byte); -static void LIS302DL_LowLevel_Init(void); -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_LIS302DL_Private_Functions - * @{ - */ - - -/** - * @brief Set LIS302DL Initialization. - * @param LIS302DL_Config_Struct: pointer to a LIS302DL_Config_TypeDef structure - * that contains the configuration setting for the LIS302DL. - * @retval None - */ -void LIS302DL_Init(LIS302DL_InitTypeDef *LIS302DL_InitStruct) -{ - uint8_t ctrl = 0x00; - - /* Configure the low level interface ---------------------------------------*/ - LIS302DL_LowLevel_Init(); - - /* Configure MEMS: data rate, power mode, full scale, self test and axes */ - ctrl = (uint8_t) (LIS302DL_InitStruct->Output_DataRate | LIS302DL_InitStruct->Power_Mode | \ - LIS302DL_InitStruct->Full_Scale | LIS302DL_InitStruct->Self_Test | \ - LIS302DL_InitStruct->Axes_Enable); - - /* Write value to MEMS CTRL_REG1 regsister */ - LIS302DL_Write(&ctrl, LIS302DL_CTRL_REG1_ADDR, 1); -} - -/** - * @brief Set LIS302DL Internal High Pass Filter configuration. - * @param LIS302DL_Filter_ConfigTypeDef: pointer to a LIS302DL_FilterConfig_TypeDef - * structure that contains the configuration setting for the LIS302DL Filter. - * @retval None - */ -void LIS302DL_FilterConfig(LIS302DL_FilterConfigTypeDef *LIS302DL_FilterConfigStruct) -{ - uint8_t ctrl = 0x00; - - /* Read CTRL_REG2 register */ - LIS302DL_Read(&ctrl, LIS302DL_CTRL_REG2_ADDR, 1); - - /* Clear high pass filter cut-off level, interrupt and data selection bits*/ - ctrl &= (uint8_t)~(LIS302DL_FILTEREDDATASELECTION_OUTPUTREGISTER | \ - LIS302DL_HIGHPASSFILTER_LEVEL_3 | \ - LIS302DL_HIGHPASSFILTERINTERRUPT_1_2); - /* Configure MEMS high pass filter cut-off level, interrupt and data selection bits */ - ctrl |= (uint8_t)(LIS302DL_FilterConfigStruct->HighPassFilter_Data_Selection | \ - LIS302DL_FilterConfigStruct->HighPassFilter_CutOff_Frequency | \ - LIS302DL_FilterConfigStruct->HighPassFilter_Interrupt); - - /* Write value to MEMS CTRL_REG2 register */ - LIS302DL_Write(&ctrl, LIS302DL_CTRL_REG2_ADDR, 1); -} - -/** - * @brief Set LIS302DL Interrupt configuration - * @param LIS302DL_InterruptConfig_TypeDef: pointer to a LIS302DL_InterruptConfig_TypeDef - * structure that contains the configuration setting for the LIS302DL Interrupt. - * @retval None - */ -void LIS302DL_InterruptConfig(LIS302DL_InterruptConfigTypeDef *LIS302DL_IntConfigStruct) -{ - uint8_t ctrl = 0x00; - - /* Read CLICK_CFG register */ - LIS302DL_Read(&ctrl, LIS302DL_CLICK_CFG_REG_ADDR, 1); - - /* Configure latch Interrupt request, click interrupts and double click interrupts */ - ctrl = (uint8_t)(LIS302DL_IntConfigStruct->Latch_Request| \ - LIS302DL_IntConfigStruct->SingleClick_Axes | \ - LIS302DL_IntConfigStruct->DoubleClick_Axes); - - /* Write value to MEMS CLICK_CFG register */ - LIS302DL_Write(&ctrl, LIS302DL_CLICK_CFG_REG_ADDR, 1); -} - -/** - * @brief Change the lowpower mode for LIS302DL - * @param LowPowerMode: new state for the lowpower mode. - * This parameter can be one of the following values: - * @arg LIS302DL_LOWPOWERMODE_POWERDOWN: Power down mode - * @arg LIS302DL_LOWPOWERMODE_ACTIVE: Active mode - * @retval None - */ -void LIS302DL_LowpowerCmd(uint8_t LowPowerMode) -{ - uint8_t tmpreg; - - /* Read CTRL_REG1 register */ - LIS302DL_Read(&tmpreg, LIS302DL_CTRL_REG1_ADDR, 1); - - /* Set new low power mode configuration */ - tmpreg &= (uint8_t)~LIS302DL_LOWPOWERMODE_ACTIVE; - tmpreg |= LowPowerMode; - - /* Write value to MEMS CTRL_REG1 regsister */ - LIS302DL_Write(&tmpreg, LIS302DL_CTRL_REG1_ADDR, 1); -} - -/** - * @brief Data Rate command - * @param DataRateValue: Data rate value - * This parameter can be one of the following values: - * @arg LIS302DL_DATARATE_100: 100 Hz output data rate - * @arg LIS302DL_DATARATE_400: 400 Hz output data rate - * @retval None - */ -void LIS302DL_DataRateCmd(uint8_t DataRateValue) -{ - uint8_t tmpreg; - - /* Read CTRL_REG1 register */ - LIS302DL_Read(&tmpreg, LIS302DL_CTRL_REG1_ADDR, 1); - - /* Set new Data rate configuration */ - tmpreg &= (uint8_t)~LIS302DL_DATARATE_400; - tmpreg |= DataRateValue; - - /* Write value to MEMS CTRL_REG1 regsister */ - LIS302DL_Write(&tmpreg, LIS302DL_CTRL_REG1_ADDR, 1); -} - -/** - * @brief Change the Full Scale of LIS302DL - * @param FS_value: new full scale value. - * This parameter can be one of the following values: - * @arg LIS302DL_FULLSCALE_2_3: +-2.3g - * @arg LIS302DL_FULLSCALE_9_2: +-9.2g - * @retval None - */ -void LIS302DL_FullScaleCmd(uint8_t FS_value) -{ - uint8_t tmpreg; - - /* Read CTRL_REG1 register */ - LIS302DL_Read(&tmpreg, LIS302DL_CTRL_REG1_ADDR, 1); - - /* Set new full scale configuration */ - tmpreg &= (uint8_t)~LIS302DL_FULLSCALE_9_2; - tmpreg |= FS_value; - - /* Write value to MEMS CTRL_REG1 regsister */ - LIS302DL_Write(&tmpreg, LIS302DL_CTRL_REG1_ADDR, 1); -} - -/** - * @brief Reboot memory content of LIS302DL - * @param None - * @retval None - */ -void LIS302DL_RebootCmd(void) -{ - uint8_t tmpreg; - /* Read CTRL_REG2 register */ - LIS302DL_Read(&tmpreg, LIS302DL_CTRL_REG2_ADDR, 1); - - /* Enable or Disable the reboot memory */ - tmpreg |= LIS302DL_BOOT_REBOOTMEMORY; - - /* Write value to MEMS CTRL_REG2 regsister */ - LIS302DL_Write(&tmpreg, LIS302DL_CTRL_REG2_ADDR, 1); -} - -/** - * @brief Writes one byte to the LIS302DL. - * @param pBuffer : pointer to the buffer containing the data to be written to the LIS302DL. - * @param WriteAddr : LIS302DL's internal address to write to. - * @param NumByteToWrite: Number of bytes to write. - * @retval None - */ -void LIS302DL_Write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite) -{ - /* Configure the MS bit: - - When 0, the address will remain unchanged in multiple read/write commands. - - When 1, the address will be auto incremented in multiple read/write commands. - */ - if(NumByteToWrite > 0x01) - { - WriteAddr |= (uint8_t)MULTIPLEBYTE_CMD; - } - /* Set chip select Low at the start of the transmission */ - LIS302DL_CS_LOW(); - - /* Send the Address of the indexed register */ - LIS302DL_SendByte(WriteAddr); - /* Send the data that will be written into the device (MSB First) */ - while(NumByteToWrite >= 0x01) - { - LIS302DL_SendByte(*pBuffer); - NumByteToWrite--; - pBuffer++; - } - - /* Set chip select High at the end of the transmission */ - LIS302DL_CS_HIGH(); -} - -/** - * @brief Reads a block of data from the LIS302DL. - * @param pBuffer : pointer to the buffer that receives the data read from the LIS302DL. - * @param ReadAddr : LIS302DL's internal address to read from. - * @param NumByteToRead : number of bytes to read from the LIS302DL. - * @retval None - */ -void LIS302DL_Read(uint8_t* pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead) -{ - if(NumByteToRead > 0x01) - { - ReadAddr |= (uint8_t)(READWRITE_CMD | MULTIPLEBYTE_CMD); - } - else - { - ReadAddr |= (uint8_t)READWRITE_CMD; - } - /* Set chip select Low at the start of the transmission */ - LIS302DL_CS_LOW(); - - /* Send the Address of the indexed register */ - LIS302DL_SendByte(ReadAddr); - - /* Receive the data that will be read from the device (MSB First) */ - while(NumByteToRead > 0x00) - { - /* Send dummy byte (0x00) to generate the SPI clock to LIS302DL (Slave device) */ - *pBuffer = LIS302DL_SendByte(DUMMY_BYTE); - NumByteToRead--; - pBuffer++; - } - - /* Set chip select High at the end of the transmission */ - LIS302DL_CS_HIGH(); -} - -/** - * @brief Read LIS302DL output register, and calculate the acceleration - * ACC[mg]=SENSITIVITY* (out_h*256+out_l)/16 (12 bit rappresentation) - * @param s16 buffer to store data - * @retval None - */ -void LIS302DL_ReadACC(int32_t* out) -{ - uint8_t buffer[6]; - uint8_t crtl, i = 0x00; - - LIS302DL_Read(&crtl, LIS302DL_CTRL_REG1_ADDR, 1); - LIS302DL_Read(buffer, LIS302DL_OUT_X_ADDR, 6); - - switch(crtl & 0x20) - { - /* FS bit = 0 ==> Sensitivity typical value = 18milligals/digit*/ - case 0x00: - for(i=0; i<0x03; i++) - { - *out =(int32_t)(LIS302DL_SENSITIVITY_2_3G * (int8_t)buffer[2*i]); - out++; - } - break; - /* FS bit = 1 ==> Sensitivity typical value = 72milligals/digit*/ - case 0x20: - for(i=0; i<0x03; i++) - { - *out =(int32_t)(LIS302DL_SENSITIVITY_9_2G * (int8_t)buffer[2*i]); - out++; - } - break; - default: - break; - } - } - -/** - * @brief Initializes the low level interface used to drive the LIS302DL - * @param None - * @retval None - */ -static void LIS302DL_LowLevel_Init(void) -{ - GPIO_InitTypeDef GPIO_InitStructure; - SPI_InitTypeDef SPI_InitStructure; - - /* Enable the SPI periph */ - RCC_APB2PeriphClockCmd(LIS302DL_SPI_CLK, ENABLE); - - /* Enable SCK, MOSI and MISO GPIO clocks */ - RCC_AHB1PeriphClockCmd(LIS302DL_SPI_SCK_GPIO_CLK | LIS302DL_SPI_MISO_GPIO_CLK | LIS302DL_SPI_MOSI_GPIO_CLK, ENABLE); - - /* Enable CS GPIO clock */ - RCC_AHB1PeriphClockCmd(LIS302DL_SPI_CS_GPIO_CLK, ENABLE); - - /* Enable INT1 GPIO clock */ - RCC_AHB1PeriphClockCmd(LIS302DL_SPI_INT1_GPIO_CLK, ENABLE); - - /* Enable INT2 GPIO clock */ - RCC_AHB1PeriphClockCmd(LIS302DL_SPI_INT2_GPIO_CLK, ENABLE); - - GPIO_PinAFConfig(LIS302DL_SPI_SCK_GPIO_PORT, LIS302DL_SPI_SCK_SOURCE, LIS302DL_SPI_SCK_AF); - GPIO_PinAFConfig(LIS302DL_SPI_MISO_GPIO_PORT, LIS302DL_SPI_MISO_SOURCE, LIS302DL_SPI_MISO_AF); - GPIO_PinAFConfig(LIS302DL_SPI_MOSI_GPIO_PORT, LIS302DL_SPI_MOSI_SOURCE, LIS302DL_SPI_MOSI_AF); - - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - - /* SPI SCK pin configuration */ - GPIO_InitStructure.GPIO_Pin = LIS302DL_SPI_SCK_PIN; - GPIO_Init(LIS302DL_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); - - /* SPI MOSI pin configuration */ - GPIO_InitStructure.GPIO_Pin = LIS302DL_SPI_MOSI_PIN; - GPIO_Init(LIS302DL_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); - - /* SPI MISO pin configuration */ - GPIO_InitStructure.GPIO_Pin = LIS302DL_SPI_MISO_PIN; - GPIO_Init(LIS302DL_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); - - /* SPI configuration -------------------------------------------------------*/ - SPI_I2S_DeInit(LIS302DL_SPI); - SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; - SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; - SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; - SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; - SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; - SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; - SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; - SPI_InitStructure.SPI_CRCPolynomial = 7; - SPI_InitStructure.SPI_Mode = SPI_Mode_Master; - SPI_Init(LIS302DL_SPI, &SPI_InitStructure); - - /* Enable SPI1 */ - SPI_Cmd(LIS302DL_SPI, ENABLE); - - /* Configure GPIO PIN for Lis Chip select */ - GPIO_InitStructure.GPIO_Pin = LIS302DL_SPI_CS_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(LIS302DL_SPI_CS_GPIO_PORT, &GPIO_InitStructure); - - /* Deselect : Chip Select high */ - GPIO_SetBits(LIS302DL_SPI_CS_GPIO_PORT, LIS302DL_SPI_CS_PIN); - - /* Configure GPIO PINs to detect Interrupts */ - GPIO_InitStructure.GPIO_Pin = LIS302DL_SPI_INT1_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(LIS302DL_SPI_INT1_GPIO_PORT, &GPIO_InitStructure); - - GPIO_InitStructure.GPIO_Pin = LIS302DL_SPI_INT2_PIN; - GPIO_Init(LIS302DL_SPI_INT2_GPIO_PORT, &GPIO_InitStructure); -} - -/** - * @brief Sends a Byte through the SPI interface and return the Byte received - * from the SPI bus. - * @param Byte : Byte send. - * @retval The received byte value - */ -static uint8_t LIS302DL_SendByte(uint8_t byte) -{ - /* Loop while DR register in not emplty */ - LIS302DLTimeout = LIS302DL_FLAG_TIMEOUT; - while (SPI_I2S_GetFlagStatus(LIS302DL_SPI, SPI_I2S_FLAG_TXE) == RESET) - { - if((LIS302DLTimeout--) == 0) return LIS302DL_TIMEOUT_UserCallback(); - } - - /* Send a Byte through the SPI peripheral */ - SPI_I2S_SendData(LIS302DL_SPI, byte); - - /* Wait to receive a Byte */ - LIS302DLTimeout = LIS302DL_FLAG_TIMEOUT; - while (SPI_I2S_GetFlagStatus(LIS302DL_SPI, SPI_I2S_FLAG_RXNE) == RESET) - { - if((LIS302DLTimeout--) == 0) return LIS302DL_TIMEOUT_UserCallback(); - } - - /* Return the Byte read from the SPI bus */ - return (uint8_t)SPI_I2S_ReceiveData(LIS302DL_SPI); -} - -#ifdef USE_DEFAULT_TIMEOUT_CALLBACK -/** - * @brief Basic management of the timeout situation. - * @param None. - * @retval None. - */ -uint32_t LIS302DL_TIMEOUT_UserCallback(void) -{ - /* Block communication and all processes */ - while (1) - { - } -} -#endif /* USE_DEFAULT_TIMEOUT_CALLBACK */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/blink2/stm32f4_discovery_lis302dl.h b/examples/STM32F4Discovery/blink2/stm32f4_discovery_lis302dl.h deleted file mode 100644 --- a/examples/STM32F4Discovery/blink2/stm32f4_discovery_lis302dl.h +++ /dev/null @@ -1,772 +0,0 @@ -/** - ****************************************************************************** - * @file stm32f4_discovery_lis302dl.h - * @author MCD Application Team - * @version V1.0.0 - * @date 19-September-2011 - * @brief This file contains all the functions prototypes for the stm32f4_discovery_lis302dl.c - * firmware driver. - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F4_DISCOVERY_LIS302DL_H -#define __STM32F4_DISCOVERY_LIS302DL_H - -#ifdef __cplusplus - extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ - #include "stm32f4xx.h" - -/** @addtogroup Utilities - * @{ - */ - -/** @addtogroup STM32F4_DISCOVERY - * @{ - */ - -/** @addtogroup STM32F4_DISCOVERY_LIS302DL - * @{ - */ - - -/** @defgroup STM32F4_DISCOVERY_LIS302DL_Exported_Types - * @{ - */ - -/* LIS302DL struct */ -typedef struct -{ - uint8_t Power_Mode; /* Power-down/Active Mode */ - uint8_t Output_DataRate; /* OUT data rate 100 Hz / 400 Hz */ - uint8_t Axes_Enable; /* Axes enable */ - uint8_t Full_Scale; /* Full scale */ - uint8_t Self_Test; /* Self test */ -}LIS302DL_InitTypeDef; - -/* LIS302DL High Pass Filter struct */ -typedef struct -{ - uint8_t HighPassFilter_Data_Selection; /* Internal filter bypassed or data from internal filter send to output register*/ - uint8_t HighPassFilter_CutOff_Frequency; /* High pass filter cut-off frequency */ - uint8_t HighPassFilter_Interrupt; /* High pass filter enabled for Freefall/WakeUp #1 or #2 */ -}LIS302DL_FilterConfigTypeDef; - -/* LIS302DL Interrupt struct */ -typedef struct -{ - uint8_t Latch_Request; /* Latch interrupt request into CLICK_SRC register*/ - uint8_t SingleClick_Axes; /* Single Click Axes Interrupts */ - uint8_t DoubleClick_Axes; /* Double Click Axes Interrupts */ -}LIS302DL_InterruptConfigTypeDef; - -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_LIS302DL_Exported_Constants - * @{ - */ - -/* Uncomment the following line to use the default LIS302DL_TIMEOUT_UserCallback() - function implemented in stm32f4_discovery_lis302dl.c file. - LIS302DL_TIMEOUT_UserCallback() function is called whenever a timeout condition - occure during communication (waiting transmit data register empty flag(TXE) - or waiting receive data register is not empty flag (RXNE)). */ -/* #define USE_DEFAULT_TIMEOUT_CALLBACK */ - -/* Maximum Timeout values for flags waiting loops. These timeouts are not based - on accurate values, they just guarantee that the application will not remain - stuck if the SPI communication is corrupted. - You may modify these timeout values depending on CPU frequency and application - conditions (interrupts routines ...). */ -#define LIS302DL_FLAG_TIMEOUT ((uint32_t)0x1000) - -/** - * @brief LIS302DL SPI Interface pins - */ -#define LIS302DL_SPI SPI1 -#define LIS302DL_SPI_CLK RCC_APB2Periph_SPI1 - -#define LIS302DL_SPI_SCK_PIN GPIO_Pin_5 /* PA.05 */ -#define LIS302DL_SPI_SCK_GPIO_PORT GPIOA /* GPIOA */ -#define LIS302DL_SPI_SCK_GPIO_CLK RCC_AHB1Periph_GPIOA -#define LIS302DL_SPI_SCK_SOURCE GPIO_PinSource5 -#define LIS302DL_SPI_SCK_AF GPIO_AF_SPI1 - -#define LIS302DL_SPI_MISO_PIN GPIO_Pin_6 /* PA.6 */ -#define LIS302DL_SPI_MISO_GPIO_PORT GPIOA /* GPIOA */ -#define LIS302DL_SPI_MISO_GPIO_CLK RCC_AHB1Periph_GPIOA -#define LIS302DL_SPI_MISO_SOURCE GPIO_PinSource6 -#define LIS302DL_SPI_MISO_AF GPIO_AF_SPI1 - -#define LIS302DL_SPI_MOSI_PIN GPIO_Pin_7 /* PA.7 */ -#define LIS302DL_SPI_MOSI_GPIO_PORT GPIOA /* GPIOA */ -#define LIS302DL_SPI_MOSI_GPIO_CLK RCC_AHB1Periph_GPIOA -#define LIS302DL_SPI_MOSI_SOURCE GPIO_PinSource7 -#define LIS302DL_SPI_MOSI_AF GPIO_AF_SPI1 - -#define LIS302DL_SPI_CS_PIN GPIO_Pin_3 /* PE.03 */ -#define LIS302DL_SPI_CS_GPIO_PORT GPIOE /* GPIOE */ -#define LIS302DL_SPI_CS_GPIO_CLK RCC_AHB1Periph_GPIOE - -#define LIS302DL_SPI_INT1_PIN GPIO_Pin_0 /* PE.00 */ -#define LIS302DL_SPI_INT1_GPIO_PORT GPIOE /* GPIOE */ -#define LIS302DL_SPI_INT1_GPIO_CLK RCC_AHB1Periph_GPIOE -#define LIS302DL_SPI_INT1_EXTI_LINE EXTI_Line0 -#define LIS302DL_SPI_INT1_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE -#define LIS302DL_SPI_INT1_EXTI_PIN_SOURCE EXTI_PinSource0 -#define LIS302DL_SPI_INT1_EXTI_IRQn EXTI0_IRQn - -#define LIS302DL_SPI_INT2_PIN GPIO_Pin_1 /* PE.01 */ -#define LIS302DL_SPI_INT2_GPIO_PORT GPIOE /* GPIOE */ -#define LIS302DL_SPI_INT2_GPIO_CLK RCC_AHB1Periph_GPIOE -#define LIS302DL_SPI_INT2_EXTI_LINE EXTI_Line1 -#define LIS302DL_SPI_INT2_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE -#define LIS302DL_SPI_INT2_EXTI_PIN_SOURCE EXTI_PinSource1 -#define LIS302DL_SPI_INT2_EXTI_IRQn EXTI1_IRQn - - -/******************************************************************************/ -/*************************** START REGISTER MAPPING **************************/ -/******************************************************************************/ - -/******************************************************************************* -* WHO_AM_I Register: Device Identification Register -* Read only register -* Default value: 0x3B -*******************************************************************************/ -#define LIS302DL_WHO_AM_I_ADDR 0x0F - -/******************************************************************************* -* CTRL_REG1 Register: Control Register 1 -* Read Write register -* Default value: 0x07 -* 7 DR: Data Rate selection. -* 0 - 100 Hz output data rate -* 1 - 400 Hz output data rate -* 6 PD: Power Down control. -* 0 - power down mode -* 1 - active mode -* 5 FS: Full Scale selection. -* 0 - Typical measurement range 2.3 -* 1 - Typical measurement range 9.2 -* 4:3 STP-STM Self Test Enable: -* STP | STM | mode -* ---------------------------- -* 0 | 0 | Normal mode -* 0 | 1 | Self Test M -* 1 | 0 | Self Test P -* 2 Zen: Z axis enable. -* 0 - Z axis disabled -* 1- Z axis enabled -* 1 Yen: Y axis enable. -* 0 - Y axis disabled -* 1- Y axis enabled -* 0 Xen: X axis enable. -* 0 - X axis disabled -* 1- X axis enabled -********************************************************************************/ -#define LIS302DL_CTRL_REG1_ADDR 0x20 - -/******************************************************************************* -* CTRL_REG2 Regsiter: Control Register 2 -* Read Write register -* Default value: 0x00 -* 7 SIM: SPI Serial Interface Mode Selection. -* 0 - 4 wire interface -* 1 - 3 wire interface -* 6 BOOT: Reboot memory content -* 0 - normal mode -* 1 - reboot memory content -* 5 Reserved -* 4 FDS: Filtered data selection. -* 0 - internal filter bypassed -* 1 - data from internal filter sent to output register -* 3 HP FF_WU2: High pass filter enabled for FreeFall/WakeUp#2. -* 0 - filter bypassed -* 1 - filter enabled -* 2 HP FF_WU1: High pass filter enabled for FreeFall/WakeUp#1. -* 0 - filter bypassed -* 1 - filter enabled -* 1:0 HP coeff2-HP coeff1 High pass filter cut-off frequency (ft) configuration. -* ft= ODR[hz]/6*HP coeff -* HP coeff2 | HP coeff1 | HP coeff -* ------------------------------------------- -* 0 | 0 | 8 -* 0 | 1 | 16 -* 1 | 0 | 32 -* 1 | 1 | 64 -* HP coeff | ft[hz] | ft[hz] | -* |ODR 100Hz | ODR 400Hz | -* -------------------------------------------- -* 00 | 2 | 8 | -* 01 | 1 | 4 | -* 10 | 0.5 | 2 | -* 11 | 0.25 | 1 | -*******************************************************************************/ -#define LIS302DL_CTRL_REG2_ADDR 0x21 - -/******************************************************************************* -* CTRL_REG3 Register: Interrupt Control Register -* Read Write register -* Default value: 0x00 -* 7 IHL active: Interrupt active high/low. -* 0 - active high -* 1 - active low -* 6 PP_OD: push-pull/open-drain. -* 0 - push-pull -* 1 - open-drain -* 5:3 I2_CFG2 - I2_CFG0 Data signal on INT2 pad control bits -* 2:0 I1_CFG2 - I1_CFG0 Data signal on INT1 pad control bits -* I1(2)_CFG2 | I1(2)_CFG1 | I1(2)_CFG0 | INT1(2) Pad -* ---------------------------------------------------------- -* 0 | 0 | 0 | GND -* 0 | 0 | 1 | FreeFall/WakeUp#1 -* 0 | 1 | 0 | FreeFall/WakeUp#2 -* 0 | 1 | 1 | FreeFall/WakeUp#1 or FreeFall/WakeUp#2 -* 1 | 0 | 0 | Data ready -* 1 | 1 | 1 | Click interrupt -*******************************************************************************/ -#define LIS302DL_CTRL_REG3_ADDR 0x22 - -/******************************************************************************* -* HP_FILTER_RESET Register: Dummy register. Reading at this address zeroes -* instantaneously the content of the internal high pass filter. If the high pass -* filter is enabled all three axes are instantaneously set to 0g. -* This allows to overcome the settling time of the high pass filter. -* Read only register -* Default value: Dummy -*******************************************************************************/ -#define LIS302DL_HP_FILTER_RESET_REG_ADDR 0x23 - -/******************************************************************************* -* STATUS_REG Register: Status Register -* Default value: 0x00 -* 7 ZYXOR: X, Y and Z axis data overrun. -* 0: no overrun has occurred -* 1: new data has overwritten the previous one before it was read -* 6 ZOR: Z axis data overrun. -* 0: no overrun has occurred -* 1: new data for Z-axis has overwritten the previous one before it was read -* 5 yOR: y axis data overrun. -* 0: no overrun has occurred -* 1: new data for y-axis has overwritten the previous one before it was read -* 4 XOR: X axis data overrun. -* 0: no overrun has occurred -* 1: new data for X-axis has overwritten the previous one before it was read -* 3 ZYXDA: X, Y and Z axis new data available -* 0: a new set of data is not yet available -* 1: a new set of data is available -* 2 ZDA: Z axis new data available. -* 0: a new set of data is not yet available -* 1: a new data for Z axis is available -* 1 YDA: Y axis new data available -* 0: a new set of data is not yet available -* 1: a new data for Y axis is available -* 0 XDA: X axis new data available -* 0: a new set of data is not yet available -* 1: a new data for X axis is available -*******************************************************************************/ -#define LIS302DL_STATUS_REG_ADDR 0x27 - -/******************************************************************************* -* OUT_X Register: X-axis output Data -* Read only register -* Default value: output -* 7:0 XD7-XD0: X-axis output Data -*******************************************************************************/ -#define LIS302DL_OUT_X_ADDR 0x29 - -/******************************************************************************* -* OUT_Y Register: Y-axis output Data -* Read only register -* Default value: output -* 7:0 YD7-YD0: Y-axis output Data -*******************************************************************************/ -#define LIS302DL_OUT_Y_ADDR 0x2B - -/******************************************************************************* -* OUT_Z Register: Z-axis output Data -* Read only register -* Default value: output -* 7:0 ZD7-ZD0: Z-axis output Data -*******************************************************************************/ -#define LIS302DL_OUT_Z_ADDR 0x2D - -/******************************************************************************* -* FF_WW_CFG_1 Register: Configuration register for Interrupt 1 source. -* Read write register -* Default value: 0x00 -* 7 AOI: AND/OR combination of Interrupt events. -* 0: OR combination of interrupt events -* 1: AND combination of interrupt events -* 6 LIR: Latch/not latch interrupt request -* 0: interrupt request not latched -* 1: interrupt request latched -* 5 ZHIE: Enable interrupt generation on Z high event. -* 0: disable interrupt request -* 1: enable interrupt request on measured accel. value higher than preset threshold -* 4 ZLIE: Enable interrupt generation on Z low event. -* 0: disable interrupt request -* 1: enable interrupt request on measured accel. value lower than preset threshold -* 3 YHIE: Enable interrupt generation on Y high event. -* 0: disable interrupt request -* 1: enable interrupt request on measured accel. value higher than preset threshold -* 2 YLIE: Enable interrupt generation on Y low event. -* 0: disable interrupt request -* 1: enable interrupt request on measured accel. value lower than preset threshold -* 1 XHIE: Enable interrupt generation on X high event. -* 0: disable interrupt request -* 1: enable interrupt request on measured accel. value higher than preset threshold -* 0 XLIE: Enable interrupt generation on X low event. -* 0: disable interrupt request -* 1: enable interrupt request on measured accel. value lower than preset threshold -*******************************************************************************/ -#define LIS302DL_FF_WU_CFG1_REG_ADDR 0x30 - -/******************************************************************************* -* FF_WU_SRC_1 Register: Interrupt 1 source register. -* Reading at this address clears FF_WU_SRC_1 register and the FF, WU 1 interrupt -* and allow the refreshment of data in the FF_WU_SRC_1 register if the latched option -* was chosen. -* Read only register -* Default value: 0x00 -* 7 Reserved -* 6 IA: Interrupt active. -* 0: no interrupt has been generated -* 1: one or more interrupts have been generated -* 5 ZH: Z high. -* 0: no interrupt -* 1: ZH event has occurred -* 4 ZL: Z low. -* 0: no interrupt -* 1: ZL event has occurred -* 3 YH: Y high. -* 0: no interrupt -* 1: YH event has occurred -* 2 YL: Y low. -* 0: no interrupt -* 1: YL event has occurred -* 1 YH: X high. -* 0: no interrupt -* 1: XH event has occurred -* 0 YL: X low. -* 0: no interrupt -* 1: XL event has occurred -*******************************************************************************/ -#define LIS302DL_FF_WU_SRC1_REG_ADDR 0x31 - -/******************************************************************************* -* FF_WU_THS_1 Register: Threshold register -* Read Write register -* Default value: 0x00 -* 7 DCRM: Reset mode selection. -* 0 - counter resetted -* 1 - counter decremented -* 6 THS6-THS0: Free-fall/wake-up threshold value. -*******************************************************************************/ -#define LIS302DL_FF_WU_THS1_REG_ADDR 0x32 - -/******************************************************************************* -* FF_WU_DURATION_1 Register: duration Register -* Read Write register -* Default value: 0x00 -* 7:0 D7-D0 Duration value. (Duration steps and maximum values depend on the ODR chosen) - ******************************************************************************/ -#define LIS302DL_FF_WU_DURATION1_REG_ADDR 0x33 - -/******************************************************************************* -* FF_WW_CFG_2 Register: Configuration register for Interrupt 2 source. -* Read write register -* Default value: 0x00 -* 7 AOI: AND/OR combination of Interrupt events. -* 0: OR combination of interrupt events -* 1: AND combination of interrupt events -* 6 LIR: Latch/not latch interrupt request -* 0: interrupt request not latched -* 1: interrupt request latched -* 5 ZHIE: Enable interrupt generation on Z high event. -* 0: disable interrupt request -* 1: enable interrupt request on measured accel. value higher than preset threshold -* 4 ZLIE: Enable interrupt generation on Z low event. -* 0: disable interrupt request -* 1: enable interrupt request on measured accel. value lower than preset threshold -* 3 YHIE: Enable interrupt generation on Y high event. -* 0: disable interrupt request -* 1: enable interrupt request on measured accel. value higher than preset threshold -* 2 YLIE: Enable interrupt generation on Y low event. -* 0: disable interrupt request -* 1: enable interrupt request on measured accel. value lower than preset threshold -* 1 XHIE: Enable interrupt generation on X high event. -* 0: disable interrupt request -* 1: enable interrupt request on measured accel. value higher than preset threshold -* 0 XLIE: Enable interrupt generation on X low event. -* 0: disable interrupt request -* 1: enable interrupt request on measured accel. value lower than preset threshold -*******************************************************************************/ -#define LIS302DL_FF_WU_CFG2_REG_ADDR 0x34 - -/******************************************************************************* -* FF_WU_SRC_2 Register: Interrupt 2 source register. -* Reading at this address clears FF_WU_SRC_2 register and the FF, WU 2 interrupt -* and allow the refreshment of data in the FF_WU_SRC_2 register if the latched option -* was chosen. -* Read only register -* Default value: 0x00 -* 7 Reserved -* 6 IA: Interrupt active. -* 0: no interrupt has been generated -* 1: one or more interrupts have been generated -* 5 ZH: Z high. -* 0: no interrupt -* 1: ZH event has occurred -* 4 ZL: Z low. -* 0: no interrupt -* 1: ZL event has occurred -* 3 YH: Y high. -* 0: no interrupt -* 1: YH event has occurred -* 2 YL: Y low. -* 0: no interrupt -* 1: YL event has occurred -* 1 YH: X high. -* 0: no interrupt -* 1: XH event has occurred -* 0 YL: X low. -* 0: no interrupt -* 1: XL event has occurred -*******************************************************************************/ -#define LIS302DL_FF_WU_SRC2_REG_ADDR 0x35 - -/******************************************************************************* -* FF_WU_THS_2 Register: Threshold register -* Read Write register -* Default value: 0x00 -* 7 DCRM: Reset mode selection. -* 0 - counter resetted -* 1 - counter decremented -* 6 THS6-THS0: Free-fall/wake-up threshold value. -*******************************************************************************/ -#define LIS302DL_FF_WU_THS2_REG_ADDR 0x36 - -/******************************************************************************* -* FF_WU_DURATION_2 Register: duration Register -* Read Write register -* Default value: 0x00 -* 7:0 D7-D0 Duration value. (Duration steps and maximum values depend on the ODR chosen) - ******************************************************************************/ -#define LIS302DL_FF_WU_DURATION2_REG_ADDR 0x37 - -/****************************************************************************** -* CLICK_CFG Register: click Register -* Read Write register -* Default value: 0x00 -* 7 Reserved -* 6 LIR: Latch Interrupt request. -* 0: interrupt request not latched -* 1: interrupt request latched -* 5 Double_Z: Enable interrupt generation on double click event on Z axis. -* 0: disable interrupt request -* 1: enable interrupt request -* 4 Single_Z: Enable interrupt generation on single click event on Z axis. -* 0: disable interrupt request -* 1: enable interrupt request -* 3 Double_Y: Enable interrupt generation on double click event on Y axis. -* 0: disable interrupt request -* 1: enable interrupt request -* 2 Single_Y: Enable interrupt generation on single click event on Y axis. -* 0: disable interrupt request -* 1: enable interrupt request -* 1 Double_X: Enable interrupt generation on double click event on X axis. -* 0: disable interrupt request -* 1: enable interrupt request -* 0 Single_y: Enable interrupt generation on single click event on X axis. -* 0: disable interrupt request -* 1: enable interrupt request - ******************************************************************************/ -#define LIS302DL_CLICK_CFG_REG_ADDR 0x38 - -/****************************************************************************** -* CLICK_SRC Register: click status Register -* Read only register -* Default value: 0x00 -* 7 Reserved -* 6 IA: Interrupt active. -* 0: no interrupt has been generated -* 1: one or more interrupts have been generated -* 5 Double_Z: Double click on Z axis event. -* 0: no interrupt -* 1: Double Z event has occurred -* 4 Single_Z: Z low. -* 0: no interrupt -* 1: Single Z event has occurred -* 3 Double_Y: Y high. -* 0: no interrupt -* 1: Double Y event has occurred -* 2 Single_Y: Y low. -* 0: no interrupt -* 1: Single Y event has occurred -* 1 Double_X: X high. -* 0: no interrupt -* 1: Double X event has occurred -* 0 Single_X: X low. -* 0: no interrupt -* 1: Single X event has occurred -*******************************************************************************/ -#define LIS302DL_CLICK_SRC_REG_ADDR 0x39 - -/******************************************************************************* -* CLICK_THSY_X Register: Click threshold Y and X register -* Read Write register -* Default value: 0x00 -* 7:4 THSy3-THSy0: Click threshold on Y axis, step 0.5g -* 3:0 THSx3-THSx0: Click threshold on X axis, step 0.5g -*******************************************************************************/ -#define LIS302DL_CLICK_THSY_X_REG_ADDR 0x3B - -/******************************************************************************* -* CLICK_THSZ Register: Click threshold Z register -* Read Write register -* Default value: 0x00 -* 7:4 Reserved -* 3:0 THSz3-THSz0: Click threshold on Z axis, step 0.5g -*******************************************************************************/ -#define LIS302DL_CLICK_THSZ_REG_ADDR 0x3C - -/******************************************************************************* -* CLICK_TimeLimit Register: Time Limit register -* Read Write register -* Default value: 0x00 -* 7:0 Dur7-Dur0: Time Limit value, step 0.5g -*******************************************************************************/ -#define LIS302DL_CLICK_TIMELIMIT_REG_ADDR 0x3D - -/******************************************************************************* -* CLICK_Latency Register: Latency register -* Read Write register -* Default value: 0x00 -* 7:0 Lat7-Lat0: Latency value, step 1msec -*******************************************************************************/ -#define LIS302DL_CLICK_LATENCY_REG_ADDR 0x3E - -/******************************************************************************* -* CLICK_Window Register: Window register -* Read Write register -* Default value: 0x00 -* 7:0 Win7-Win0: Window value, step 1msec -*******************************************************************************/ -#define LIS302DL_CLICK_WINDOW_REG_ADDR 0x3F - -/******************************************************************************/ -/**************************** END REGISTER MAPPING ***************************/ -/******************************************************************************/ - -#define LIS302DL_SENSITIVITY_2_3G 18 /* 18 mg/digit*/ -#define LIS302DL_SENSITIVITY_9_2G 72 /* 72 mg/digit*/ - -/** @defgroup Data_Rate_selection - * @{ - */ -#define LIS302DL_DATARATE_100 ((uint8_t)0x00) -#define LIS302DL_DATARATE_400 ((uint8_t)0x80) -/** - * @} - */ - -/** @defgroup Power_Mode_selection - * @{ - */ -#define LIS302DL_LOWPOWERMODE_POWERDOWN ((uint8_t)0x00) -#define LIS302DL_LOWPOWERMODE_ACTIVE ((uint8_t)0x40) -/** - * @} - */ - -/** @defgroup Full_Scale_selection - * @{ - */ -#define LIS302DL_FULLSCALE_2_3 ((uint8_t)0x00) -#define LIS302DL_FULLSCALE_9_2 ((uint8_t)0x20) -/** - * @} - */ - -/** @defgroup Self_Test_selection - * @{ - */ -#define LIS302DL_SELFTEST_NORMAL ((uint8_t)0x00) -#define LIS302DL_SELFTEST_P ((uint8_t)0x10) -#define LIS302DL_SELFTEST_M ((uint8_t)0x08) -/** - * @} - */ - -/** @defgroup Direction_XYZ_selection - * @{ - */ -#define LIS302DL_X_ENABLE ((uint8_t)0x01) -#define LIS302DL_Y_ENABLE ((uint8_t)0x02) -#define LIS302DL_Z_ENABLE ((uint8_t)0x04) -#define LIS302DL_XYZ_ENABLE ((uint8_t)0x07) -/** - * @} - */ - - /** @defgroup SPI_Serial_Interface_Mode_selection - * @{ - */ -#define LIS302DL_SERIALINTERFACE_4WIRE ((uint8_t)0x00) -#define LIS302DL_SERIALINTERFACE_3WIRE ((uint8_t)0x80) -/** - * @} - */ - - /** @defgroup Boot_Mode_selection - * @{ - */ -#define LIS302DL_BOOT_NORMALMODE ((uint8_t)0x00) -#define LIS302DL_BOOT_REBOOTMEMORY ((uint8_t)0x40) -/** - * @} - */ - - /** @defgroup Filtered_Data_Selection_Mode_selection - * @{ - */ -#define LIS302DL_FILTEREDDATASELECTION_BYPASSED ((uint8_t)0x00) -#define LIS302DL_FILTEREDDATASELECTION_OUTPUTREGISTER ((uint8_t)0x20) -/** - * @} - */ - - /** @defgroup High_Pass_Filter_Interrupt_selection - * @{ - */ -#define LIS302DL_HIGHPASSFILTERINTERRUPT_OFF ((uint8_t)0x00) -#define LIS302DL_HIGHPASSFILTERINTERRUPT_1 ((uint8_t)0x04) -#define LIS302DL_HIGHPASSFILTERINTERRUPT_2 ((uint8_t)0x08) -#define LIS302DL_HIGHPASSFILTERINTERRUPT_1_2 ((uint8_t)0x0C) -/** - * @} - */ - - /** @defgroup High_Pass_Filter_selection - * @{ - */ -#define LIS302DL_HIGHPASSFILTER_LEVEL_0 ((uint8_t)0x00) -#define LIS302DL_HIGHPASSFILTER_LEVEL_1 ((uint8_t)0x01) -#define LIS302DL_HIGHPASSFILTER_LEVEL_2 ((uint8_t)0x02) -#define LIS302DL_HIGHPASSFILTER_LEVEL_3 ((uint8_t)0x03) -/** - * @} - */ - - -/** @defgroup latch_Interrupt_Request_selection - * @{ - */ -#define LIS302DL_INTERRUPTREQUEST_NOTLATCHED ((uint8_t)0x00) -#define LIS302DL_INTERRUPTREQUEST_LATCHED ((uint8_t)0x40) -/** - * @} - */ - -/** @defgroup Click_Interrupt_XYZ_selection - * @{ - */ -#define LIS302DL_CLICKINTERRUPT_XYZ_DISABLE ((uint8_t)0x00) -#define LIS302DL_CLICKINTERRUPT_X_ENABLE ((uint8_t)0x01) -#define LIS302DL_CLICKINTERRUPT_Y_ENABLE ((uint8_t)0x04) -#define LIS302DL_CLICKINTERRUPT_Z_ENABLE ((uint8_t)0x10) -#define LIS302DL_CLICKINTERRUPT_XYZ_ENABLE ((uint8_t)0x15) -/** - * @} - */ - -/** @defgroup Double_Click_Interrupt_XYZ_selection - * @{ - */ -#define LIS302DL_DOUBLECLICKINTERRUPT_XYZ_DISABLE ((uint8_t)0x00) -#define LIS302DL_DOUBLECLICKINTERRUPT_X_ENABLE ((uint8_t)0x02) -#define LIS302DL_DOUBLECLICKINTERRUPT_Y_ENABLE ((uint8_t)0x08) -#define LIS302DL_DOUBLECLICKINTERRUPT_Z_ENABLE ((uint8_t)0x20) -#define LIS302DL_DOUBLECLICKINTERRUPT_XYZ_ENABLE ((uint8_t)0x2A) -/** - * @} - */ -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_LIS302DL_Exported_Macros - * @{ - */ -#define LIS302DL_CS_LOW() GPIO_ResetBits(LIS302DL_SPI_CS_GPIO_PORT, LIS302DL_SPI_CS_PIN) -#define LIS302DL_CS_HIGH() GPIO_SetBits(LIS302DL_SPI_CS_GPIO_PORT, LIS302DL_SPI_CS_PIN) -/** - * @} - */ - -/** @defgroup STM32F4_DISCOVERY_LIS302DL_Exported_Functions - * @{ - */ -void LIS302DL_Init(LIS302DL_InitTypeDef *LIS302DL_InitStruct); -void LIS302DL_InterruptConfig(LIS302DL_InterruptConfigTypeDef *LIS302DL_InterruptConfigStruct); -void LIS302DL_FilterConfig(LIS302DL_FilterConfigTypeDef *LIS302DL_FilterConfigStruct); -void LIS302DL_LowpowerCmd(uint8_t LowPowerMode); -void LIS302DL_FullScaleCmd(uint8_t FS_value); -void LIS302DL_DataRateCmd(uint8_t DataRateValue); -void LIS302DL_RebootCmd(void); -void LIS302DL_ReadACC(int32_t* out); -void LIS302DL_Write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite); -void LIS302DL_Read(uint8_t* pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead); - -/* USER Callbacks: This is function for which prototype only is declared in - MEMS accelerometre driver and that should be implemented into user applicaiton. */ -/* LIS302DL_TIMEOUT_UserCallback() function is called whenever a timeout condition - occure during communication (waiting transmit data register empty flag(TXE) - or waiting receive data register is not empty flag (RXNE)). - You can use the default timeout callback implementation by uncommenting the - define USE_DEFAULT_TIMEOUT_CALLBACK in stm32f4_discovery_lis302dl.h file. - Typically the user implementation of this callback should reset MEMS peripheral - and re-initialize communication or in worst case reset all the application. */ -uint32_t LIS302DL_TIMEOUT_UserCallback(void); - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32F4_DISCOVERY_LIS302DL_H */ -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/blink2/stm32f4xx_conf.h b/examples/STM32F4Discovery/blink2/stm32f4xx_conf.h deleted file mode 100644 --- a/examples/STM32F4Discovery/blink2/stm32f4xx_conf.h +++ /dev/null @@ -1,94 +0,0 @@ -/** - ****************************************************************************** - * @file stm32f4xx_conf.h - * @author MCD Application Team - * @version V1.0.0 - * @date 19-September-2011 - * @brief Library configuration file. - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F4xx_CONF_H -#define __STM32F4xx_CONF_H - -#if defined (HSE_VALUE) -/* Redefine the HSE value; it's equal to 8 MHz on the STM32F4-DISCOVERY Kit */ - #undef HSE_VALUE - #define HSE_VALUE ((uint32_t)8000000) -#endif /* HSE_VALUE */ - -/* Includes ------------------------------------------------------------------*/ -/* Uncomment the line below to enable peripheral header file inclusion */ -#include "stm32f4xx_adc.h" -#include "stm32f4xx_can.h" -#include "stm32f4xx_crc.h" -#include "stm32f4xx_cryp.h" -#include "stm32f4xx_dac.h" -#include "stm32f4xx_dbgmcu.h" -#include "stm32f4xx_dcmi.h" -#include "stm32f4xx_dma.h" -#include "stm32f4xx_exti.h" -#include "stm32f4xx_flash.h" -#include "stm32f4xx_fsmc.h" -#include "stm32f4xx_hash.h" -#include "stm32f4xx_gpio.h" -#include "stm32f4xx_i2c.h" -#include "stm32f4xx_iwdg.h" -#include "stm32f4xx_pwr.h" -#include "stm32f4xx_rcc.h" -#include "stm32f4xx_rng.h" -#include "stm32f4xx_rtc.h" -#include "stm32f4xx_sdio.h" -#include "stm32f4xx_spi.h" -#include "stm32f4xx_syscfg.h" -#include "stm32f4xx_tim.h" -#include "stm32f4xx_usart.h" -#include "stm32f4xx_wwdg.h" -#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ - -/* If an external clock source is used, then the value of the following define - should be set to the value of the external clock source, else, if no external - clock is used, keep this define commented */ -/*#define I2S_EXTERNAL_CLOCK_VAL 12288000 */ /* Value of the external clock in Hz */ - - -/* Uncomment the line below to expanse the "assert_param" macro in the - Standard Peripheral Library drivers code */ -/* #define USE_FULL_ASSERT 1 */ - -/* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT - -/** - * @brief The assert_param macro is used for function's parameters check. - * @param expr: If expr is false, it calls assert_failed function - * which reports the name of the source file and the source - * line number of the call that failed. - * If expr is true, it returns no value. - * @retval None - */ - #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) -/* Exported functions ------------------------------------------------------- */ - void assert_failed(uint8_t* file, uint32_t line); -#else - #define assert_param(expr) ((void)0) -#endif /* USE_FULL_ASSERT */ - -#endif /* __STM32F4xx_CONF_H */ - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/blink2/stm32f4xx_it.c b/examples/STM32F4Discovery/blink2/stm32f4xx_it.c deleted file mode 100644 --- a/examples/STM32F4Discovery/blink2/stm32f4xx_it.c +++ /dev/null @@ -1,179 +0,0 @@ -/** - ****************************************************************************** - * @file stm32f4xx_it.c - * @author MCD Application Team - * @version V1.0.0 - * @date 19-September-2011 - * @brief Main Interrupt Service Routines. - * This file provides all exceptions handler and peripherals interrupt - * service routine. - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx_it.h" - - - -/******************************************************************************/ -/* Cortex-M3 Processor Exceptions Handlers */ -/******************************************************************************/ - -/** - * @brief This function handles NMI exception. - * @param None - * @retval None - */ -void NMI_Handler(void) -{ -} - -/** - * @brief This function handles Hard Fault exception. - * @param None - * @retval None - */ -void HardFault_Handler(void) -{ - /* Go to infinite loop when Hard Fault exception occurs */ - while (1) - { - } -} - -/** - * @brief This function handles Memory Manage exception. - * @param None - * @retval None - */ -void MemManage_Handler(void) -{ - /* Go to infinite loop when Memory Manage exception occurs */ - while (1) - { - } -} - -/** - * @brief This function handles Bus Fault exception. - * @param None - * @retval None - */ -void BusFault_Handler(void) -{ - /* Go to infinite loop when Bus Fault exception occurs */ - while (1) - { - } -} - -/** - * @brief This function handles Usage Fault exception. - * @param None - * @retval None - */ -void UsageFault_Handler(void) -{ - /* Go to infinite loop when Usage Fault exception occurs */ - while (1) - { - } -} - -/** - * @brief This function handles SVCall exception. - * @param None - * @retval None - */ -void SVC_Handler(void) -{ -} - -/** - * @brief This function handles Debug Monitor exception. - * @param None - * @retval None - */ -void DebugMon_Handler(void) -{ -} - -/** - * @brief This function handles PendSVC exception. - * @param None - * @retval None - */ -void PendSV_Handler(void) -{ -} - -/** - * @brief This function handles SysTick Handler. - * @param None - * @retval None - */ -void SysTick_Handler(void) -{ -} - -/******************************************************************************/ -/* STM32Fxxx Peripherals Interrupt Handlers */ -/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ -/* available peripheral interrupt handler's name please refer to the startup */ -/* file (startup_stm32fxxx.s). */ -/******************************************************************************/ - -/** - * @brief This function handles PPP interrupt request. - * @param None - * @retval None - */ -/*void PPP_IRQHandler(void) -{ -}*/ - -/** - * @brief This function handles EXTI0_IRQ Handler. - * @param None - * @retval None - */ -void EXTI0_IRQHandler(void) -{ -} - -/** - * @brief This function handles EXTI15_10_IRQ Handler. - * @param None - * @retval None - */ -void OTG_FS_WKUP_IRQHandler(void) -{ -} - -/** - * @brief This function handles OTG_HS Handler. - * @param None - * @retval None - */ -void OTG_FS_IRQHandler(void) -{ -} - -/** -* @brief USBD_HID_GetPos -* @param None -* @retval Pointer to report -*/ - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/examples/STM32F4Discovery/blink2/syscalls.c b/examples/STM32F4Discovery/blink2/syscalls.c deleted file mode 100644 --- a/examples/STM32F4Discovery/blink2/syscalls.c +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#undef errno - - -#ifdef __cplusplus -extern "C" { -#endif -extern int errno; - -char *__env[1] = { 0 }; -char **environ = __env; - -int _exit() -{ - while(1); -} - -int _close(int file) { -return -1; -} - -int _write(int file, char *ptr, int len) { -int todo; -for (todo = 0; todo < len; todo++) { -//outbyte (*ptr++); -} -return len; -} - -int _execve(char *name, char **argv, char **env) { -errno = ENOMEM; -return -1; -} - - -int _fork(void) { -errno = EAGAIN; -return -1; -} - -int _fstat(int file, struct stat *st) { -st->st_mode = S_IFCHR; -return 0; -} - - -int _getpid(void) { -return 1; -} - - -int _isatty(int file) { -return 1; -} - - -int _kill(int pid, int sig) { -errno = EINVAL; -return -1; -} - - -int _link(char *old, char *new) { -errno = EMLINK; -return -1; -} - - -int _lseek(int file, int ptr, int dir) { -return 0; -} - -int _open(const char *name, int flags, int mode) { -return -1; -} - -int _read(int file, char *ptr, int len) { -return 0; -} - - - -caddr_t _sbrk(int incr) { -register char * stack_ptr __asm__ ("sp"); -extern char _end; /* Defined by the linker */ -static char *heap_end; -char *prev_heap_end; -if (heap_end == 0) { -heap_end = &_end; -} -prev_heap_end = heap_end; -if (heap_end + incr > stack_ptr) { -_write (1, "Heap and stack collision\n", 25); -abort (); -} -heap_end += incr; -return (caddr_t) prev_heap_end; -} - - - -int _stat(char *file, struct stat *st) { -st->st_mode = S_IFCHR; -return 0; -} - - -int _times(struct tms *buf) { -return -1; -} - - -int _unlink(char *name) { -errno = ENOENT; -return -1; -} - -int _wait(int *status) { -errno = ECHILD; -return -1; -} - - -#ifdef __cplusplus -} -#endif - - diff --git a/examples/STM32F4Discovery/blink2/system_stm32f4xx.c b/examples/STM32F4Discovery/blink2/system_stm32f4xx.c deleted file mode 100644 --- a/examples/STM32F4Discovery/blink2/system_stm32f4xx.c +++ /dev/null @@ -1,566 +0,0 @@ -/** - ****************************************************************************** - * @file system_stm32f4xx.c - * @author MCD Application Team - * @version V1.0.0 - * @date 19-September-2011 - * @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File. - * This file contains the system clock configuration for STM32F4xx devices, - * and is generated by the clock configuration tool - * stm32f4xx_Clock_Configuration_V1.0.0.xls - * - * 1. This file provides two functions and one global variable to be called from - * user application: - * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier - * and Divider factors, AHB/APBx prescalers and Flash settings), - * depending on the configuration made in the clock xls tool. - * This function is called at startup just after reset and - * before branch to main program. This call is made inside - * the "startup_stm32f4xx.s" file. - * - * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used - * by the user application to setup the SysTick - * timer or configure other parameters. - * - * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must - * be called whenever the core clock is changed - * during program execution. - * - * 2. After each device reset the HSI (16 MHz) is used as system clock source. - * Then SystemInit() function is called, in "startup_stm32f4xx.s" file, to - * configure the system clock before to branch to main program. - * - * 3. If the system clock source selected by user fails to startup, the SystemInit() - * function will do nothing and HSI still used as system clock source. User can - * add some code to deal with this issue inside the SetSysClock() function. - * - * 4. The default value of HSE crystal is set to 8 MHz, refer to "HSE_VALUE" define - * in "stm32f4xx.h" file. When HSE is used as system clock source, directly or - * through PLL, and you are using different crystal you have to adapt the HSE - * value to your own configuration. - * - * 5. This file configures the system clock as follows: - *============================================================================= - *============================================================================= - * Supported STM32F4xx device revision | Rev A - *----------------------------------------------------------------------------- - * System Clock source | PLL (HSE) - *----------------------------------------------------------------------------- - * SYSCLK(Hz) | 168000000 - *----------------------------------------------------------------------------- - * HCLK(Hz) | 168000000 - *----------------------------------------------------------------------------- - * AHB Prescaler | 1 - *----------------------------------------------------------------------------- - * APB1 Prescaler | 4 - *----------------------------------------------------------------------------- - * APB2 Prescaler | 2 - *----------------------------------------------------------------------------- - * HSE Frequency(Hz) | 8000000 - *----------------------------------------------------------------------------- - * PLL_M | 8 - *----------------------------------------------------------------------------- - * PLL_N | 336 - *----------------------------------------------------------------------------- - * PLL_P | 2 - *----------------------------------------------------------------------------- - * PLL_Q | 7 - *----------------------------------------------------------------------------- - * PLLI2S_N | 192 - *----------------------------------------------------------------------------- - * PLLI2S_R | 5 - *----------------------------------------------------------------------------- - * I2S input clock(Hz) | 38400000 - *----------------------------------------------------------------------------- - * VDD(V) | 3.3 - *----------------------------------------------------------------------------- - * High Performance mode | Enabled - *----------------------------------------------------------------------------- - * Flash Latency(WS) | 5 - *----------------------------------------------------------------------------- - * Prefetch Buffer | OFF - *----------------------------------------------------------------------------- - * Instruction cache | ON - *----------------------------------------------------------------------------- - * Data cache | ON - *----------------------------------------------------------------------------- - * Require 48MHz for USB OTG FS, | Enabled - * SDIO and RNG clock | - *----------------------------------------------------------------------------- - *============================================================================= - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - -/** @addtogroup CMSIS - * @{ - */ - -/** @addtogroup stm32f4xx_system - * @{ - */ - -/** @addtogroup STM32F4xx_System_Private_Includes - * @{ - */ - -#include "stm32f4xx.h" - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_TypesDefinitions - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Defines - * @{ - */ - -/*!< Uncomment the following line if you need to use external SRAM mounted - on STM324xG_EVAL board as data memory */ -/* #define DATA_IN_ExtSRAM */ - -/*!< Uncomment the following line if you need to relocate your vector Table in - Internal SRAM. */ -/* #define VECT_TAB_SRAM */ -#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. - This value must be a multiple of 0x200. */ - - -/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */ -#define PLL_M 8 -#define PLL_N 336 - -/* SYSCLK = PLL_VCO / PLL_P */ -#define PLL_P 2 - -/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */ -#define PLL_Q 7 - -/* PLLI2S_VCO = (HSE_VALUE Or HSI_VALUE / PLL_M) * PLLI2S_N - I2SCLK = PLLI2S_VCO / PLLI2S_R */ -#define PLLI2S_N 192 -#define PLLI2S_R 5 - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Macros - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Variables - * @{ - */ - - uint32_t SystemCoreClock = 168000000; - - __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_FunctionPrototypes - * @{ - */ - -static void SetSysClock(void); -#ifdef DATA_IN_ExtSRAM - static void SystemInit_ExtMemCtl(void); -#endif /* DATA_IN_ExtSRAM */ - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Functions - * @{ - */ - -/** - * @brief Setup the microcontroller system - * Initialize the Embedded Flash Interface, the PLL and update the - * SystemFrequency variable. - * @param None - * @retval None - */ -void SystemInit(void) -{ - /* Reset the RCC clock configuration to the default reset state ------------*/ - /* Set HSION bit */ - RCC->CR |= (uint32_t)0x00000001; - - /* Reset CFGR register */ - RCC->CFGR = 0x00000000; - - /* Reset HSEON, CSSON and PLLON bits */ - RCC->CR &= (uint32_t)0xFEF6FFFF; - - /* Reset PLLCFGR register */ - RCC->PLLCFGR = 0x24003010; - - /* Reset HSEBYP bit */ - RCC->CR &= (uint32_t)0xFFFBFFFF; - - /* Disable all interrupts */ - RCC->CIR = 0x00000000; - -#ifdef DATA_IN_ExtSRAM - SystemInit_ExtMemCtl(); -#endif /* DATA_IN_ExtSRAM */ - - /* Configure the System clock source, PLL Multiplier and Divider factors, - AHB/APBx prescalers and Flash settings ----------------------------------*/ - SetSysClock(); - - /* Configure the Vector Table location add offset address ------------------*/ -#ifdef VECT_TAB_SRAM - SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ -#else - SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ -#endif -} - -/** - * @brief Update SystemCoreClock variable according to Clock Register Values. - * The SystemCoreClock variable contains the core clock (HCLK), it can - * be used by the user application to setup the SysTick timer or configure - * other parameters. - * - * @note Each time the core clock (HCLK) changes, this function must be called - * to update SystemCoreClock variable value. Otherwise, any configuration - * based on this variable will be incorrect. - * - * @note - The system frequency computed by this function is not the real - * frequency in the chip. It is calculated based on the predefined - * constant and the selected clock source: - * - * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) - * - * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) - * - * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) - * or HSI_VALUE(*) multiplied/divided by the PLL factors. - * - * (*) HSI_VALUE is a constant defined in stm32f4xx.h file (default value - * 16 MHz) but the real value may vary depending on the variations - * in voltage and temperature. - * - * (**) HSE_VALUE is a constant defined in stm32f4xx.h file (default value - * 25 MHz), user has to ensure that HSE_VALUE is same as the real - * frequency of the crystal used. Otherwise, this function may - * have wrong result. - * - * - The result of this function could be not correct when using fractional - * value for HSE crystal. - * - * @param None - * @retval None - */ -void SystemCoreClockUpdate(void) -{ - uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2; - - /* Get SYSCLK source -------------------------------------------------------*/ - tmp = RCC->CFGR & RCC_CFGR_SWS; - - switch (tmp) - { - case 0x00: /* HSI used as system clock source */ - SystemCoreClock = HSI_VALUE; - break; - case 0x04: /* HSE used as system clock source */ - SystemCoreClock = HSE_VALUE; - break; - case 0x08: /* PLL used as system clock source */ - - /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N - SYSCLK = PLL_VCO / PLL_P - */ - pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22; - pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM; - - if (pllsource != 0) - { - /* HSE used as PLL clock source */ - pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6); - } - else - { - /* HSI used as PLL clock source */ - pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6); - } - - pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2; - SystemCoreClock = pllvco/pllp; - break; - default: - SystemCoreClock = HSI_VALUE; - break; - } - /* Compute HCLK frequency --------------------------------------------------*/ - /* Get HCLK prescaler */ - tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; - /* HCLK frequency */ - SystemCoreClock >>= tmp; -} - -/** - * @brief Configures the System clock source, PLL Multiplier and Divider factors, - * AHB/APBx prescalers and Flash settings - * @Note This function should be called only once the RCC clock configuration - * is reset to the default reset state (done in SystemInit() function). - * @param None - * @retval None - */ -static void SetSysClock(void) -{ -/******************************************************************************/ -/* PLL (clocked by HSE) used as System clock source */ -/******************************************************************************/ - __IO uint32_t StartUpCounter = 0, HSEStatus = 0; - - /* Enable HSE */ - RCC->CR |= ((uint32_t)RCC_CR_HSEON); - - /* Wait till HSE is ready and if Time out is reached exit */ - do - { - HSEStatus = RCC->CR & RCC_CR_HSERDY; - StartUpCounter++; - } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); - - if ((RCC->CR & RCC_CR_HSERDY) != RESET) - { - HSEStatus = (uint32_t)0x01; - } - else - { - HSEStatus = (uint32_t)0x00; - } - - if (HSEStatus == (uint32_t)0x01) - { - /* Enable high performance mode, System frequency up to 168 MHz */ - RCC->APB1ENR |= RCC_APB1ENR_PWREN; - PWR->CR |= PWR_CR_PMODE; - - /* HCLK = SYSCLK / 1*/ - RCC->CFGR |= RCC_CFGR_HPRE_DIV1; - - /* PCLK2 = HCLK / 2*/ - RCC->CFGR |= RCC_CFGR_PPRE2_DIV2; - - /* PCLK1 = HCLK / 4*/ - RCC->CFGR |= RCC_CFGR_PPRE1_DIV4; - - /* Configure the main PLL */ - RCC->PLLCFGR = PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) | - (RCC_PLLCFGR_PLLSRC_HSE) | (PLL_Q << 24); - - /* Enable the main PLL */ - RCC->CR |= RCC_CR_PLLON; - - /* Wait till the main PLL is ready */ - while((RCC->CR & RCC_CR_PLLRDY) == 0) - { - } - - /* Configure Flash prefetch, Instruction cache, Data cache and wait state */ - FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS; - - /* Select the main PLL as system clock source */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); - RCC->CFGR |= RCC_CFGR_SW_PLL; - - /* Wait till the main PLL is used as system clock source */ - while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL); - { - } - } - else - { /* If HSE fails to start-up, the application will have wrong clock - configuration. User can add here some code to deal with this error */ - } - -/******************************************************************************/ -/* I2S clock configuration */ -/******************************************************************************/ - /* PLLI2S clock used as I2S clock source */ - RCC->CFGR &= ~RCC_CFGR_I2SSRC; - - /* Configure PLLI2S */ - RCC->PLLI2SCFGR = (PLLI2S_N << 6) | (PLLI2S_R << 28); - - /* Enable PLLI2S */ - RCC->CR |= ((uint32_t)RCC_CR_PLLI2SON); - - /* Wait till PLLI2S is ready */ - while((RCC->CR & RCC_CR_PLLI2SRDY) == 0) - { - } -} - -/** - * @brief Setup the external memory controller. Called in startup_stm32f4xx.s - * before jump to __main - * @param None - * @retval None - */ -#ifdef DATA_IN_ExtSRAM -/** - * @brief Setup the external memory controller. - * Called in startup_stm32f4xx.s before jump to main. - * This function configures the external SRAM mounted on STM324xG_EVAL board - * This SRAM will be used as program data memory (including heap and stack). - * @param None - * @retval None - */ -void SystemInit_ExtMemCtl(void) -{ -/*-- GPIOs Configuration -----------------------------------------------------*/ -/* - +-------------------+--------------------+------------------+------------------+ - + SRAM pins assignment + - +-------------------+--------------------+------------------+------------------+ - | PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 | - | PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 | - | PD4 <-> FSMC_NOE | PE3 <-> FSMC_A19 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 | - | PD5 <-> FSMC_NWE | PE4 <-> FSMC_A20 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 | - | PD8 <-> FSMC_D13 | PE7 <-> FSMC_D4 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 | - | PD9 <-> FSMC_D14 | PE8 <-> FSMC_D5 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 | - | PD10 <-> FSMC_D15 | PE9 <-> FSMC_D6 | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 | - | PD11 <-> FSMC_A16 | PE10 <-> FSMC_D7 | PF13 <-> FSMC_A7 |------------------+ - | PD12 <-> FSMC_A17 | PE11 <-> FSMC_D8 | PF14 <-> FSMC_A8 | - | PD13 <-> FSMC_A18 | PE12 <-> FSMC_D9 | PF15 <-> FSMC_A9 | - | PD14 <-> FSMC_D0 | PE13 <-> FSMC_D10 |------------------+ - | PD15 <-> FSMC_D1 | PE14 <-> FSMC_D11 | - | | PE15 <-> FSMC_D12 | - +-------------------+--------------------+ -*/ - /* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */ - RCC->AHB1ENR = 0x00000078; - - /* Connect PDx pins to FSMC Alternate function */ - GPIOD->AFR[0] = 0x00cc00cc; - GPIOD->AFR[1] = 0xcc0ccccc; - /* Configure PDx pins in Alternate function mode */ - GPIOD->MODER = 0xaaaa0a0a; - /* Configure PDx pins speed to 100 MHz */ - GPIOD->OSPEEDR = 0xffff0f0f; - /* Configure PDx pins Output type to push-pull */ - GPIOD->OTYPER = 0x00000000; - /* No pull-up, pull-down for PDx pins */ - GPIOD->PUPDR = 0x00000000; - - /* Connect PEx pins to FSMC Alternate function */ - GPIOE->AFR[0] = 0xc00cc0cc; - GPIOE->AFR[1] = 0xcccccccc; - /* Configure PEx pins in Alternate function mode */ - GPIOE->MODER = 0xaaaa828a; - /* Configure PEx pins speed to 100 MHz */ - GPIOE->OSPEEDR = 0xffffc3cf; - /* Configure PEx pins Output type to push-pull */ - GPIOE->OTYPER = 0x00000000; - /* No pull-up, pull-down for PEx pins */ - GPIOE->PUPDR = 0x00000000; - - /* Connect PFx pins to FSMC Alternate function */ - GPIOF->AFR[0] = 0x00cccccc; - GPIOF->AFR[1] = 0xcccc0000; - /* Configure PFx pins in Alternate function mode */ - GPIOF->MODER = 0xaa000aaa; - /* Configure PFx pins speed to 100 MHz */ - GPIOF->OSPEEDR = 0xff000fff; - /* Configure PFx pins Output type to push-pull */ - GPIOF->OTYPER = 0x00000000; - /* No pull-up, pull-down for PFx pins */ - GPIOF->PUPDR = 0x00000000; - - /* Connect PGx pins to FSMC Alternate function */ - GPIOG->AFR[0] = 0x00cccccc; - GPIOG->AFR[1] = 0x000000c0; - /* Configure PGx pins in Alternate function mode */ - GPIOG->MODER = 0x00080aaa; - /* Configure PGx pins speed to 100 MHz */ - GPIOG->OSPEEDR = 0x000c0fff; - /* Configure PGx pins Output type to push-pull */ - GPIOG->OTYPER = 0x00000000; - /* No pull-up, pull-down for PGx pins */ - GPIOG->PUPDR = 0x00000000; - -/*-- FSMC Configuration ------------------------------------------------------*/ - /* Enable the FSMC interface clock */ - RCC->AHB3ENR = 0x00000001; - - /* Configure and enable Bank1_SRAM2 */ - FSMC_Bank1->BTCR[2] = 0x00001015; - FSMC_Bank1->BTCR[3] = 0x00010603;//0x00010400; - FSMC_Bank1E->BWTR[2] = 0x0fffffff; -/* - Bank1_SRAM2 is configured as follow: - - p.FSMC_AddressSetupTime = 3;//0; - p.FSMC_AddressHoldTime = 0; - p.FSMC_DataSetupTime = 6;//4; - p.FSMC_BusTurnAroundDuration = 1; - p.FSMC_CLKDivision = 0; - p.FSMC_DataLatency = 0; - p.FSMC_AccessMode = FSMC_AccessMode_A; - - FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; - FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; - FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; - FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; - FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; - FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; - FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; - FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; - FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; - FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; - FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; - FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; - FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; - FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; - FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; -*/ - -} -#endif /* DATA_IN_ExtSRAM */ - - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ - diff --git a/examples/STM32F4Discovery/sdcard/bin/stm32f4DiscoverySDCARD.elf b/examples/STM32F4Discovery/sdcard/bin/stm32f4DiscoverySDCARD.elf deleted file mode 100644 index eae27d948a590f7e185e3c9965179b1946f6b5d1..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 GIT binary patch literal 0 Hc$@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define delay for(volatile int i=0;i<1024*256;i++) -//streamdevice* stdo; - -int main() -{ - int seccnt = 1; - char test[512*seccnt]; - int i=0; - blkdevice dev; - dikpartition part; - ucdirent dirent; - FAT32fs fs; -// void sdcardmakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected) - //sdcardmakeblkdev(&dev); - mbropen(&dev,&part,1); - return 0; -} - - - - - - diff --git a/examples/STM32F4Discovery/sdcard/sdcard.pro b/examples/STM32F4Discovery/sdcard/sdcard.pro deleted file mode 100644 --- a/examples/STM32F4Discovery/sdcard/sdcard.pro +++ /dev/null @@ -1,14 +0,0 @@ -TEMPLATE = app -ARCH = stm32f4-arm-none-eabi-gcc -TARGET = stm32f4DiscoverySDCARD -BSP = STM32F4Discovery - -LIBS += ALLFS HEXVIEWER UART GPIO STREAMDEVICES UHANDLE UCSTRINGS CPU - -SOURCES += main.c - - - -HEADERS += - - diff --git a/examples/STM32F4IT/STM32F4IT.pro b/examples/STM32F4IT/STM32F4IT.pro deleted file mode 100644 --- a/examples/STM32F4IT/STM32F4IT.pro +++ /dev/null @@ -1,13 +0,0 @@ -!isEmpty( UCMODEL ) { - contains( UCMODEL, stm32f4 ){ - TEMPLATE = app - - BSP = STM32F4Discovery - - SOURCES += \ - main.c - } -} - - - diff --git a/examples/STM32F4IT/main.c b/examples/STM32F4IT/main.c deleted file mode 100644 --- a/examples/STM32F4IT/main.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - - -int libuc_main() -{ - printf("Hello world from project 'STM32F4IT'!\n"); - return 0; -} - diff --git a/examples/TEST_CMSIS_FFT/TEST_CMSIS_FFT.pro b/examples/TEST_CMSIS_FFT/TEST_CMSIS_FFT.pro deleted file mode 100644 --- a/examples/TEST_CMSIS_FFT/TEST_CMSIS_FFT.pro +++ /dev/null @@ -1,21 +0,0 @@ -!isEmpty( UCMODEL ) { - contains( UCMODEL, stm32f4 ){ - TEMPLATE = app - - DEFINES += CPUFREQ=160000000 - - #BSP = BEAGLESYNTH - #BSP = SOLAR_LFR_PSU - - BSP = STM32F4Eval - - SOURCES += \ - main.c - } -} - - - - - - diff --git a/examples/TEST_CMSIS_FFT/main.c b/examples/TEST_CMSIS_FFT/main.c deleted file mode 100644 --- a/examples/TEST_CMSIS_FFT/main.c +++ /dev/null @@ -1,106 +0,0 @@ -/* ---------------------------------------------------------------------- -* Copyright (C) 2010 ARM Limited. All rights reserved. -* -* $Date: 29. November 2010 -* $Revision: V1.0.3 -* -* Project: CMSIS DSP Library -* Title: arm_convolution_example_f32.c -* -* Description: Example code demonstrating Convolution of two input signals using fft. -* -* Target Processor: Cortex-M4/Cortex-M3 -* -* -* Version 1.0.3 2010/11/29 -* Re-organized the CMSIS folders and updated documentation. -* -* Version 1.0.1 2010/10/05 KK -* Production release and review comments incorporated. -* -* Version 1.0.0 2010/09/20 KK -* Production release and review comments incorporated. -* ------------------------------------------------------------------- */ - -#include -#include -#include -#include -#include -//#include "math_helper.h" -#include - -/* ---------------------------------------------------------------------- -* Defines each of the tests performed -* ------------------------------------------------------------------- */ -//#define MAX_BLOCKSIZE 1024 -#define MAX_BLOCKSIZE 16 - -/* ---------------------------------------------------------------------- -* Declare I/O buffers -* ------------------------------------------------------------------- */ -float32_t Ak[MAX_BLOCKSIZE*2]; /* Input A */ - -#define LCD_COLOR_WHITE 0xFFFF -#define LCD_COLOR_BLACK 0x0000 -#define LCD_COLOR_GREY 0xF7DE -#define LCD_COLOR_BLUE 0x001F -#define LCD_COLOR_BLUE2 0x051F -#define LCD_COLOR_RED 0xF800 -#define LCD_COLOR_MAGENTA 0xF81F -#define LCD_COLOR_GREEN 0x07E0 -#define LCD_COLOR_CYAN 0x7FFF -#define LCD_COLOR_YELLOW 0xFFE0 -extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; - - -int libuc_main() -{ - - arm_status status; /* Status of the example */ - arm_cfft_radix4_instance_f32 cfft_instance; /* CFFT Structure instance */ - - /* CFFT Structure instance pointer */ - arm_cfft_radix4_instance_f32 *cfft_instance_ptr = - (arm_cfft_radix4_instance_f32*) &cfft_instance; - - /* Initialise the fft input buffers with all zeros */ - arm_fill_f32(0.0, Ak, MAX_BLOCKSIZE); - for(int i =0;i<(MAX_BLOCKSIZE);i++) - { - Ak[2*i] = sin(4.0*PI*(float32_t)i/MAX_BLOCKSIZE); - printf("%f\n\r",Ak[i]); - } - - //gpioclr(LED1); - - /* Initialize the CFFT function to compute 64 point fft */ - status = arm_cfft_radix4_init_f32(cfft_instance_ptr, MAX_BLOCKSIZE, 0, 1); - - /* Transform input a[n] from time domain to frequency domain A[k] */ - arm_cfft_radix4_f32(cfft_instance_ptr, Ak); - - //gpioset(LED1); - - /* Initialize the CIFFT function to compute 64 point ifft */ - //status = arm_cfft_radix4_init_f32(cfft_instance_ptr, 16, 1, 1); - - /* Transform the multiplication output from frequency domain to time domain, - that gives the convolved output */ - //arm_cfft_radix4_f32(cfft_instance_ptr, AxB); - - /* SNR Calculation */ - //snr = arm_snr_f32((float32_t *)testRefOutput_f32, AxB, srcALen + srcBLen - 1); - - /* Compare the SNR with threshold to test whether the - computed output is matched with the reference output values. */ - printf("FFT Done!\n\r"); - for(int i =0;i<(MAX_BLOCKSIZE*2);i++) - { - printf("%f %f\n\r",Ak[2*i],Ak[(2*i)+1]); - } - - - while(1); /* main function does not return */ -} - diff --git a/examples/TEST_SIMULATOR/TEST_SIMULATOR.pro b/examples/TEST_SIMULATOR/TEST_SIMULATOR.pro deleted file mode 100644 --- a/examples/TEST_SIMULATOR/TEST_SIMULATOR.pro +++ /dev/null @@ -1,15 +0,0 @@ -!isEmpty( UCMODEL ) { - contains( UCMODEL, simulator ){ - TEMPLATE = app - BSP = SIMULATOR - - DEFINES += CPUFREQ=100000000 - - SOURCES += \ - main.c \ - test_lcd.c \ - test_SDCARD.c - } -} - - diff --git a/examples/TEST_SIMULATOR/main.c b/examples/TEST_SIMULATOR/main.c deleted file mode 100644 --- a/examples/TEST_SIMULATOR/main.c +++ /dev/null @@ -1,138 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern streamdevice* __opnfiles__[]; -extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); -extern void test_address(LCD_t* LCD); -extern void printRootClustersChain(FAT32fs* sdcard2FAT32part); -char buffer[512]; - - -//void streamdevicePrint(streamdevice* dev, const char* format,...) -//{ -// char str_buffer[512]=""; -// int i; -// va_list ap; -// va_start(ap,format); -// vasprintf(str_buffer,format,ap); -// va_end(ap); -// i=strlen(str_buffer); -// dev->ops->write(dev,(void*)str_buffer,1,i); -//} - -int _write(int file, char *ptr, int len) -{ - if(file<__MAX_OPENED_FILES__ && __opnfiles__[file]!=NULL) - { - if(__opnfiles__[file]->ops->write(__opnfiles__[file],ptr,1,len)) return len; - } - return len; -} - -int _write_r (struct _reent *r, int file, char * ptr, int len) -{ - return _write(file, ptr, len); -} - -//int printf(const char *format,...) -//{ -// char str_buffer[512]=""; -// for(int i =0;i<512;i++)str_buffer[i]='\0'; -// int i; -// va_list ap; -// va_start(ap,format); -// vasprintf(str_buffer,format,ap); -// va_end(ap); -// i=strlen(str_buffer); -// __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)str_buffer,1,i); -//} - -void lcd_print() -{ - lcd0.paintFilRect(&lcd0,10,10,100,100,0,0,0x0F0F); - // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)"hello",1,5); -} - - -void playFile(ucdirent* file,FAT32fs* part) -{ - extern volatile vs10XXDev audioCodec0; - char direntName[]=" \n"; - uint32_t fileLba,nextLba; - int i=0; - fat32getdirentname(file,direntName); - //gpioset(LCD_BACKL); - printf("%s\n",direntName); - nextLba=fat32getdirentlba(file); - //printf("Streaming File\n"); - //gpioclr(LCD_BACKL); -} - -void listFiles() -{ - extern FAT32fs sdcard2FAT32part1,sdcard2FAT32part2,sdcard2FAT32part3,sdcard2FAT32part4; - ucdirent root; - if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root)) - { - printf("Reading on SDCARD2 part1\n"); - if(DIRENT_noErr==fat32getrootfirstent(&root)) - { - do{ - playFile(&root,&sdcard2FAT32part1); - }while (DIRENT_noErr==fat32nextdirent(&root)); - } - } - gpioset(LED2); - if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root)) - { - printf("Reading on SDCARD2 part2\n"); - if(DIRENT_noErr==fat32getrootfirstent(&root)) - { - do{ - playFile(&root,&sdcard2FAT32part2); - }while (DIRENT_noErr==fat32nextdirent(&root)); - } - } -} - - -int libuc_main2() -{ - printRootClustersChain(&sdcard2FAT32part1); - -} - -int libuc_main() -{ - char in[255]; - //lcd_print(); - printf("hello world\n"); - delay_100us(10000); - // streamdevicePrint(__opnfiles__[1],"test Hello %d %f \n",1234567,8.96); - listFiles(); - // lcd0.paintText(&lcd0,"A",10,100,&ComicSansMS_18,0x0); - // while(1)test_address(&lcd0); -// while (scanf("%c",in)) -// { - sleep(5); -// } - -} - - - - - diff --git a/examples/TEST_SIMULATOR/test_SDCARD.c b/examples/TEST_SIMULATOR/test_SDCARD.c deleted file mode 100644 --- a/examples/TEST_SIMULATOR/test_SDCARD.c +++ /dev/null @@ -1,23 +0,0 @@ - -#include -#include -#include -#include -#include - - - -void printRootClustersChain(FAT32fs* sdcard2FAT32part) -{ - ucdirent root; - uint32_t sector_lba,res,tmp=sdcard2FAT32part->cluster_begin_lba; - sector_lba=tmp; - do - { - printf("Sector @0x%x\n",tmp); - //sector_lba=tmp+sdcard2FAT32part->BPB_SecPerClus-1; - sector_lba=tmp; - res=fat32nextsectorlba(sdcard2FAT32part,sector_lba,&tmp); - }while((res==DIRENT_noErr)&&(res!=DIRENT_LastSect)); - -} diff --git a/examples/TEST_SIMULATOR/test_lcd.c b/examples/TEST_SIMULATOR/test_lcd.c deleted file mode 100644 --- a/examples/TEST_SIMULATOR/test_lcd.c +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -uint16_t buff[50*50]; - -void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color) -{ -// LCD->paintFilRect(LCD,x,y,w,h,0,0,color); -} -int coef=1; - -void test_address(LCD_t* LCD) -{ - LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF); - uint16_t color[1]; - for(int y=0;yheight;y++) - { - for(int x=0;xwidth;x++) - { - color[0]=((x/10*y*x)/((y+x+1)))+coef; - coef = color[0]; - LCD->paint(LCD,color,x,y,1,1); - //delay_100us(100); - } - } - LCD->getPix(LCD,buff,50,50,50,50); - // delay_100us(5000); - LCD->paint(LCD,buff,50,50,50,50); - delay_100us(500); -} diff --git a/examples/examples.pro b/examples/examples.pro --- a/examples/examples.pro +++ b/examples/examples.pro @@ -5,22 +5,12 @@ CONFIG += ordered !isEmpty( UCMODEL ) { contains( UCMODEL, stm32f4 ){ SUBDIRS += \ - QtTest/test.pro \ - SOLAR_PSU_HELLO/hello.pro \ - SDCARD \ - STM32F4IT \ - M4StickV2 \ - lcdHello \ - BeagleSynthHello \ - lcdTerminal \ - BeagleSynthHelloSupMon \ - TEST_CMSIS_FFT \ - N25Q128_test \ - ssd2119Tests + helloWorld \ + DAC \ + PWM } contains( UCMODEL, simulator ){ SUBDIRS += \ - TEST_SIMULATOR \ helloWorld } } diff --git a/examples/helloWorld/helloWorld.pro b/examples/helloWorld/helloWorld.pro --- a/examples/helloWorld/helloWorld.pro +++ b/examples/helloWorld/helloWorld.pro @@ -1,9 +1,11 @@ - UCMODEL=simulator - TEMPLATE = app -BSP = SIMULATOR - +eval(UCMODEL = simulator) { + BSP = SIMULATOR +} +eval(UCMODEL = stm32f4) { + BSP = STM32F4Eval +} SOURCES += \ main.c @@ -14,3 +16,4 @@ SOURCES += \ + diff --git a/examples/helloWorld/main.c b/examples/helloWorld/main.c --- a/examples/helloWorld/main.c +++ b/examples/helloWorld/main.c @@ -24,6 +24,7 @@ * the project file. The value BSP contains the board name, and UCMODEL contain * the target architecture. */ +#include int libuc_main() { diff --git a/examples/lcdHello/lcdHello.pro b/examples/lcdHello/lcdHello.pro deleted file mode 100644 --- a/examples/lcdHello/lcdHello.pro +++ /dev/null @@ -1,18 +0,0 @@ -!isEmpty( UCMODEL ) { - contains( UCMODEL, stm32f4 ){ - TEMPLATE = app - - BSP = STM32F4Eval - - DEFINES += CPUFREQ=160000000 - - SOURCES += \ - main.c - - } -} - - - - - diff --git a/examples/lcdHello/main.c b/examples/lcdHello/main.c deleted file mode 100644 --- a/examples/lcdHello/main.c +++ /dev/null @@ -1,93 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern streamdevice* __opnfiles__[]; - -#define LCD_COLOR_WHITE 0xFFFF -#define LCD_COLOR_BLACK 0x0000 -#define LCD_COLOR_GREY 0xF7DE -#define LCD_COLOR_BLUE 0x001F -#define LCD_COLOR_BLUE2 0x051F -#define LCD_COLOR_RED 0xF800 -#define LCD_COLOR_MAGENTA 0xF81F -#define LCD_COLOR_GREEN 0x07E0 -#define LCD_COLOR_CYAN 0x7FFF -#define LCD_COLOR_YELLOW 0xFFE0 - - - - - -void monkDemo() -{ - //while(1) - { - lcd0.paintText(&lcd0," ",10,Monk_24.Height+10,&Monk_24,LCD_COLOR_BLACK); - lcd0.paintText(&lcd0," ",230-Monk_24.Width,310,&Monk_24,LCD_COLOR_BLUE); - //for(volatile int i=0;i<(1024*1024*16);i++); - //lcd0.paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_WHITE,1,LCD_COLOR_WHITE); - //for(volatile int i=0;i<(1024*1024*4);i++); - } -} - - -void randBoxesDemo() -{ - int16_t x,y,w,h,t,r; - x=rand()%240; - y=rand()%320; - w=rand()%(240-x); - if(x>y) - r=(rand()%(y))%(320-y); - else - r=(rand()%(x))%(240-x); - h=rand()%(320-y); - t=rand()%(10); - //ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); - ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); -} - -int libuc_main() -{ - uint16_t innerbuffer[16]; - uint16_t outterbuffer[16]; - for(int i=0;i<16;i++)innerbuffer[i]=LCD_COLOR_BLUE; - for(int i=0;i<16;i++)outterbuffer[i]=LCD_COLOR_RED; - ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_CYAN,5,LCD_COLOR_WHITE); - ili9328paintFilCirc(&lcd0,100,150,40,LCD_COLOR_RED,5,LCD_COLOR_BLUE); - ili9328paintFilCirc(&lcd0,120,160,120,LCD_COLOR_RED,1,LCD_COLOR_BLUE); - //ili9328paintFilCirc(&lcd0,150,240,80,LCD_COLOR_RED,2,LCD_COLOR_BLUE); - monkDemo(); - while(1) - { - delay_100us(5000); - gpioset(LED1); - gpioclr(LED2); - delay_100us(5000); - gpioclr(LED1); - gpioset(LED2); - } - printf("hello world\n\r"); - return 0; -} - - - - - - - - - diff --git a/examples/lcdTerminal/lcdTerminal.pro b/examples/lcdTerminal/lcdTerminal.pro deleted file mode 100644 --- a/examples/lcdTerminal/lcdTerminal.pro +++ /dev/null @@ -1,18 +0,0 @@ -!isEmpty( UCMODEL ) { - contains( UCMODEL, stm32f4 ){ - TEMPLATE = app - CONFIG += audio - - BSP = STM32F4Eval - - DEFINES += CPUFREQ=168000000 - - SOURCES += \ - main.c - - } -} - - - - diff --git a/examples/lcdTerminal/main.c b/examples/lcdTerminal/main.c deleted file mode 100644 --- a/examples/lcdTerminal/main.c +++ /dev/null @@ -1,127 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; - -#define LCD_COLOR_WHITE 0xFFFF -#define LCD_COLOR_BLACK 0x0000 -#define LCD_COLOR_GREY 0xF7DE -#define LCD_COLOR_BLUE 0x001F -#define LCD_COLOR_BLUE2 0x051F -#define LCD_COLOR_RED 0xF800 -#define LCD_COLOR_MAGENTA 0xF81F -#define LCD_COLOR_GREEN 0x07E0 -#define LCD_COLOR_CYAN 0x7FFF -#define LCD_COLOR_YELLOW 0xFFE0 - -void testAudioDAC() -{ - CS43L22_t dac; - cs43l22open(&dac,i2c1,0); - uint8_t ID= cs43l22getID(&dac); - printf("dac ID = %d\n\r",ID); -} - -void testIOEXPender() -{ - STMPE811_t ioexp1,ioexp2; - char data[2]={0,0}; - i2cwrite(i2c1,0x50,data,1); - - //i2cread(i2c1,0x88,data,2); -// stmpe811init(&ioexp1,i2c1,0); -// stmpe811init(&ioexp2,i2c1,1); -// printf("Scan for IOEXPANDER:\n\r ID1=%d\n\rID2=%d",stmpe811getID(&ioexp1),stmpe811getID(&ioexp2)); -} - -int _terminal_writenc(terminal_t* terminal,char* data, int n) -{ -#define CHARXPOS(terminal,charwidth) (((terminal)->column * charwidth) + (terminal)->Xpos) -#define CHARYPOS(terminal,charheight) ((terminal)->line * charheight + (terminal)->Ypos+charheight) - int charw=terminal->font->Width + terminal->horizontalSpace; - int charh=terminal->font->Height + terminal->verticalSpace; - int l=0; - char buffer[2]=" "; - while(lline= (terminal->line+1) % terminal->lineCount; - terminal->column = 0; -// if(terminal->line==0) -// terminal_clear(terminal); -// else -// terminal_clearCurentLine(terminal); - }else { - if(buffer[0]=='\t') - { - for(int i=0;i<1;i++)terminal_movecursor(terminal,1); - } -// else -// if(terminal->column==0)terminal_clearCurentLine(terminal); - if(buffer[0]!='\r'){ - // terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); - terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); - terminal_movecursor(terminal,1); - } - } - l++; - } - return n; -} - -int libuc_main() -{ - delay_100us(10000); - uint16_t innerbuffer[16]; - uint16_t outterbuffer[16]; - for(int i=0;i<16;i++)innerbuffer[i]=LCD_COLOR_BLUE; - for(int i=0;i<16;i++)outterbuffer[i]=LCD_COLOR_RED; - ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_CYAN,5,LCD_COLOR_BLACK); - - streamdevice* fd1=__opnfiles__[1]; - streamdevice fd2; - int i=0; - terminal_t terminal0,terminal1; - terminal_init(&terminal0,&lcd0,&ComicSansMS_18,fd1); - //terminal_init(&terminal1,&lcd0,&ComicSansMS_18,&fd2); - terminal_setgeometry(&terminal0,5,5,terminal0.LCD->width-10,(terminal0.LCD->height)-10); - //terminal_setbackgroundColor(&terminal1,0xFFFF); - //terminal_settextColor(&terminal1,0x0000); - //terminal_setgeometry(&terminal1,5,(terminal0.LCD->height/2)+5,terminal0.LCD->width-10,(terminal0.LCD->height/2)-10); - printf("Line cnt :\n \t%d\n",terminal0.lineCount); - printf("Column cnt :\n \t%d\n",terminal0.columnCount); - printf("CPU Freq :\n \t%dMHz\n",getCpuFreq()/1000000); - //testAudioDAC(); - for(int i=0;i<240;i++) - { - lcd0.paintFilRect(&lcd0,i,0,1,320,0,0,i); - } - lcd0.paintText(&lcd0,"A",100,100,&ComicSansMS_24,0); - while(1)_terminal_writenc(&terminal0,"test ",5); - return 0; -} - - - - - - - - - diff --git a/examples/ssd2119Tests/main.c b/examples/ssd2119Tests/main.c deleted file mode 100644 --- a/examples/ssd2119Tests/main.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include -#include -#include - -extern LCD_t lcd0; -extern void ssd2119paintFilCirc_old(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor); - -int libuc_main() -{ - printf("Hello World!\n\r"); - printf("SSD2119 Device Code = 0x%x\n\r",lcd0.interface->readreg(SSD2119_REGISTER_DEVICE_CODE_READ)); - printf("SSD2119 Entry mode = 0x%x\n\r",lcd0.interface->readreg(SSD2119_REGISTER_ENTRY_MODE)); - printf("SSD2119 Display Control = 0x%x\n\r",lcd0.interface->readreg(SSD2119_REGISTER_DISPLAY_CTRL)); - gpioset(LED2); - lcd0.paintFilRect(&lcd0,0,0,lcd0.width,lcd0.height,0xFFFF,0,0xFFFF); - lcd0.paintFilRect(&lcd0,10,10,100,100,0xFFFF,5,0); - lcd0.paintText(&lcd0,"Malik Ta gueule!",50,150,&ComicSansMS_24,0); - ssd2119paintFilCirc_old(&lcd0,160,120,50,0xF0F0,3,0x0F0F); - return 0; -} - diff --git a/examples/ssd2119Tests/ssd2119Tests.pro b/examples/ssd2119Tests/ssd2119Tests.pro deleted file mode 100644 --- a/examples/ssd2119Tests/ssd2119Tests.pro +++ /dev/null @@ -1,14 +0,0 @@ -!isEmpty( UCMODEL ) { - contains( UCMODEL, stm32f4 ){ - TEMPLATE = app - - DEFINES += CPUFREQ=120000000 - - BSP = STM32F4Discovery-EXT - - SOURCES += \ - main.c - } -} - - diff --git a/include/PERIPHERALS/dac.h b/include/PERIPHERALS/dac.h --- a/include/PERIPHERALS/dac.h +++ b/include/PERIPHERALS/dac.h @@ -15,17 +15,10 @@ #define DAC1 0 #define DAC2 1 -#define timer2 1 -#define timer3 2 -#define timer4 3 -#define timer5 4 -#define timer6 5 -#define timer7 6 -#define timer8 7 extern int dacopen(uint32_t pin); -extern int dacsetconfig(int timer, int buffer_size, int dac,uint32_t dac_type, uint32_t freq,uint32_t data); +extern int dacsetconfig(int timer, int buffer_size, int dac, uint32_t dac_type, uint32_t samplingFreq, void* data); diff --git a/include/PERIPHERALS/pwm.h b/include/PERIPHERALS/pwm.h --- a/include/PERIPHERALS/pwm.h +++ b/include/PERIPHERALS/pwm.h @@ -77,9 +77,6 @@ extern int pwmsetfrequency(int PWM,uint3 #endif #ifndef DOXYGEN_SHOULD_SKIP_THIS - #define UARTPARITYMASK 0x3 - #define UARTBITSMASK 0xC - #define UARTSTOPBITSMASK 0x70 typedef enum { diff --git a/include/PERIPHERALS/timer.h b/include/PERIPHERALS/timer.h new file mode 100644 --- /dev/null +++ b/include/PERIPHERALS/timer.h @@ -0,0 +1,65 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2014, Kaveh Mohamadabadi +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Kaveh Mohamadabadi +-- Mail : kaveh.mohamadabadi@gmail.com +-------------------------------------------------------------------------------*/ + /// \defgroup TIMER +/*! \file timer.h +\brief TIMER api. + + +\ingroup TIMER + +*/ +#ifndef TIMER_H +#define TIMER_H + +#include +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} +#endif + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + +#define timer1 0 +#define timer2 1 +#define timer3 2 +#define timer4 3 +#define timer5 4 +#define timer6 5 +#define timer7 6 +#define timer8 7 +#define timer9 8 +#define timer10 9 +#define timer11 10 +#define timer12 11 +#define timer13 12 +#define timer14 13 +#define timer15 14 +#define timer16 15 + + + +#endif +#endif // TIMER_H diff --git a/mkspecs/features/stm32f4/syscalls.c b/mkspecs/features/stm32f4/syscalls.c --- a/mkspecs/features/stm32f4/syscalls.c +++ b/mkspecs/features/stm32f4/syscalls.c @@ -11,6 +11,7 @@ #include #include #include +#include #undef errno diff --git a/src/stm32f4/DAC/dac.c b/src/stm32f4/DAC/dac.c --- a/src/stm32f4/DAC/dac.c +++ b/src/stm32f4/DAC/dac.c @@ -1,5 +1,5 @@ #include -//#include +#include #include #include #include @@ -8,38 +8,17 @@ #include #include #include +#include #define DAC_DHR12R2_ADDRESS 0x40007414 #define DAC_DHR8R1_ADDRESS 0x40007410 -#define DAC1_12bit_right_align 0x40007408 -#define DAC1_12bit_left_align 0x4000740C -#define DAC1_8bit_right_align 0x40007410 -#define DAC2_12bit_right_align 0x40007414 -#define DAC2_12bit_left_align 0x40007418 -#define DAC2_8bit_right_align 0x4000741C -#define DAC_Dual_12bit_right_align 0x40007420 -#define DAC_Dual_12bit_left_align 0x40007424 -#define DAC_Dual_8bit_right_align 0x40007428 -#define DAC_Dual_8bit_left_align 0x4000742C - - const TIM_TypeDef* _timer_dev_table[14]={TIM1,TIM2,TIM3,TIM4,TIM5,TIM6,TIM7, TIM8,TIM9,TIM10,TIM11,TIM12,TIM13,TIM14}; -#define DAC1 0 -#define DAC2 1 -#define timer2 1 -#define timer3 2 -#define timer4 3 -#define timer5 4 -#define timer6 5 -#define timer7 6 -#define timer8 7 -DAC_InitTypeDef DAC_InitStructure; int dacopen(uint32_t pin) { @@ -54,23 +33,35 @@ int dacopen(uint32_t pin) return 0; } -int dacsetconfig(int timer, int buffer_size, int dac,uint32_t dac_type, uint32_t freq,uint32_t data) +int dacsetconfig(int timer, int buffer_size, int dac, uint32_t dac_type, uint32_t samplingFreq, void *data) { - TIM_TypeDef* tim = _timer_dev_table[timer]; +#include + DAC_InitTypeDef DAC_InitStructure; + TIM_TypeDef* tim = (TIM_TypeDef*)_timer_dev_table[timer]; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; + DMA_InitTypeDef DMA_InitStructure; if(timer>=timer2 && timer <= timer7)RCC_APB1PeriphClockCmd((1<<(timer-1)), ENABLE); if(timer==timer8)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE); - uint32_t timfreq = (81300)*buffer_size/(freq); + uint32_t timfreq = getCpuFreq()/2; + uint32_t period = timfreq/samplingFreq - 1; + uint16_t PrescalerValue=0; + while (period>=0x0FFFF) + { + PrescalerValue++; + timfreq = getCpuFreq()/(2*(PrescalerValue+1)); + period = (timfreq/samplingFreq) - 1; + } + printf("period = %d \n\r prescaler = %d \n\r",period,PrescalerValue); TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); - TIM_TimeBaseStructure.TIM_Period = timfreq; + TIM_TimeBaseStructure.TIM_Period = 10; TIM_TimeBaseStructure.TIM_Prescaler = 0; - TIM_TimeBaseStructure.TIM_ClockDivision = 0; + TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure); TIM_SelectOutputTrigger(tim, TIM_TRGOSource_Update); + TIM_ARRPreloadConfig(tim, ENABLE); TIM_Cmd(tim, ENABLE); - DMA_InitTypeDef DMA_InitStructure; if (timer == timer2)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; if (timer == timer4)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T4_TRGO; if (timer == timer5)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T5_TRGO; diff --git a/src/stm32f4/PWM/pwm.c b/src/stm32f4/PWM/pwm.c --- a/src/stm32f4/PWM/pwm.c +++ b/src/stm32f4/PWM/pwm.c @@ -5,25 +5,11 @@ #include #include #include +#include + const TIM_TypeDef* _timer_dev_table[14]={TIM1,TIM2,TIM3,TIM4,TIM5,TIM6,TIM7, TIM8,TIM9,TIM10,TIM11,TIM12,TIM13,TIM14}; -#define timer1 0 -#define timer2 1 -#define timer3 2 -#define timer4 3 -#define timer5 4 -#define timer6 5 -#define timer7 6 -#define timer8 7 -#define timer9 8 -#define timer10 9 -#define timer11 10 -#define timer12 11 -#define timer13 12 -#define timer14 13 -#define timer15 14 -#define timer16 15 #define PWMGETTIMNUMBER(PWM) (((uint32_t)(PWM) & (uint32_t)0x0000FF00)>>(uint32_t)8) diff --git a/src/stm32f4/TIMER/timer.c b/src/stm32f4/TIMER/timer.c new file mode 100644 --- /dev/null +++ b/src/stm32f4/TIMER/timer.c @@ -0,0 +1,5 @@ +#include + + + + diff --git a/src/stm32f4/TIMER/timer.pro b/src/stm32f4/TIMER/timer.pro new file mode 100644 --- /dev/null +++ b/src/stm32f4/TIMER/timer.pro @@ -0,0 +1,13 @@ +TEMPLATE = lib +CONFIG += libuc2lib + +SOURCES += timer.c + + +UCMODEL=stm32f4 + +HEADERS += \ + ../../../include/PERIPHERALS/timer.h + + + diff --git a/src/stm32f4/stm32f4.pro b/src/stm32f4/stm32f4.pro --- a/src/stm32f4/stm32f4.pro +++ b/src/stm32f4/stm32f4.pro @@ -4,6 +4,7 @@ CONFIG += ordered SUBDIRS = CORE/core.pro \ CPU/cpu.pro \ GPIO/gpio.pro \ + TIMER/timer.pro \ UART/uart.pro \ SPI/spi.pro \ I2C/i2c.pro \