##// END OF EJS Templates
Some cleaning plus DAC library started
Jeandet Alexis -
r100:e8e36f727532 dev_alexis
parent child
Show More
@@ -0,0 +1,22
1 TEMPLATE = app
2
3 DEFINES += CPUFREQ=40000000
4
5 LIBS += -ldac
6
7 eval(UCMODEL = simulator) {
8 BSP = SIMULATOR
9 }
10 eval(UCMODEL = stm32f4) {
11 BSP = STM32F4Eval
12 }
13
14 SOURCES += \
15 main.c
16
17
18
19
20
21
22
@@ -0,0 +1,56
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2013, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /** @author Alexis Jeandet alexis.jeandet@member.fsf.org
20 -------------------------------------------------------------------------------*/
21 /**
22 * This file is a simple example for the DAC library.
23 *
24 */
25
26 #include <stdio.h>
27 #include <uhandle.h>
28 #include <dac.h>
29 #include <timer.h>
30 #include <gpio.h>
31 #include <math.h>
32 int16_t __attribute__ ((aligned (4))) data[512];
33 int libuc_main()
34 {
35 /**
36 Depending on the board the printf can be directed on one uart or LCD screen or
37 any other stream device.
38 */
39 printf("DAC example\n\r");
40 for(int i=0;i<512;i++)
41 {
42 data[i]=(int16_t)(2000.0*cos(i/10.0))+2000.0;
43 }
44 dacopen(PA4);
45 dacsetconfig(timer8, 512, DAC1,DAC1_12bit_right_align , 100000,(void*)data);
46 return 0;
47 }
48
49
50
51
52
53
54
55
56
@@ -0,0 +1,18
1 TEMPLATE = app
2
3 eval(UCMODEL = simulator) {
4 BSP = SIMULATOR
5 }
6 eval(UCMODEL = stm32f4) {
7 BSP = STM32F4Eval
8 }
9
10 SOURCES += \
11 main.c
12
13
14
15
16
17
18
@@ -0,0 +1,45
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2013, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /** @author Alexis Jeandet alexis.jeandet@member.fsf.org
20 -------------------------------------------------------------------------------*/
21 /**
22 * This file is a simple hello world example it should run on any supported
23 * board/architecture couple. To change target board and architecture modify
24 * the project file. The value BSP contains the board name, and UCMODEL contain
25 * the target architecture.
26 */
27
28 int libuc_main()
29 {
30 /**
31 Depending on the board the printf can be directed on one uart or LCD screen or
32 any other stream device.
33 */
34 printf("hello world\n\r");
35 return 0;
36 }
37
38
39
40
41
42
43
44
45
@@ -0,0 +1,65
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2014, Kaveh Mohamadabadi
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Kaveh Mohamadabadi
20 -- Mail : kaveh.mohamadabadi@gmail.com
21 -------------------------------------------------------------------------------*/
22 /// \defgroup TIMER
23 /*! \file timer.h
24 \brief TIMER api.
25
26
27 \ingroup TIMER
28
29 */
30 #ifndef TIMER_H
31 #define TIMER_H
32
33 #include <stdint.h>
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38
39 #ifdef __cplusplus
40 }
41 #endif
42
43 #ifndef DOXYGEN_SHOULD_SKIP_THIS
44
45 #define timer1 0
46 #define timer2 1
47 #define timer3 2
48 #define timer4 3
49 #define timer5 4
50 #define timer6 5
51 #define timer7 6
52 #define timer8 7
53 #define timer9 8
54 #define timer10 9
55 #define timer11 10
56 #define timer12 11
57 #define timer13 12
58 #define timer14 13
59 #define timer15 14
60 #define timer16 15
61
62
63
64 #endif
65 #endif // TIMER_H
@@ -0,0 +1,5
1 #include <timer.h>
2
3
4
5
@@ -0,0 +1,13
1 TEMPLATE = lib
2 CONFIG += libuc2lib
3
4 SOURCES += timer.c
5
6
7 UCMODEL=stm32f4
8
9 HEADERS += \
10 ../../../include/PERIPHERALS/timer.h
11
12
13
@@ -5,22 +5,12 CONFIG += ordered
5 !isEmpty( UCMODEL ) {
5 !isEmpty( UCMODEL ) {
6 contains( UCMODEL, stm32f4 ){
6 contains( UCMODEL, stm32f4 ){
7 SUBDIRS += \
7 SUBDIRS += \
8 QtTest/test.pro \
8 helloWorld \
9 SOLAR_PSU_HELLO/hello.pro \
9 DAC \
10 SDCARD \
10 PWM
11 STM32F4IT \
12 M4StickV2 \
13 lcdHello \
14 BeagleSynthHello \
15 lcdTerminal \
16 BeagleSynthHelloSupMon \
17 TEST_CMSIS_FFT \
18 N25Q128_test \
19 ssd2119Tests
20 }
11 }
21 contains( UCMODEL, simulator ){
12 contains( UCMODEL, simulator ){
22 SUBDIRS += \
13 SUBDIRS += \
23 TEST_SIMULATOR \
24 helloWorld
14 helloWorld
25 }
15 }
26 }
16 }
@@ -1,9 +1,11
1 UCMODEL=simulator
2
3 TEMPLATE = app
1 TEMPLATE = app
4
2
5 BSP = SIMULATOR
3 eval(UCMODEL = simulator) {
6
4 BSP = SIMULATOR
5 }
6 eval(UCMODEL = stm32f4) {
7 BSP = STM32F4Eval
8 }
7
9
8 SOURCES += \
10 SOURCES += \
9 main.c
11 main.c
@@ -14,3 +16,4 SOURCES += \
14
16
15
17
16
18
19
@@ -24,6 +24,7
24 * the project file. The value BSP contains the board name, and UCMODEL contain
24 * the project file. The value BSP contains the board name, and UCMODEL contain
25 * the target architecture.
25 * the target architecture.
26 */
26 */
27 #include <stdio.h>
27
28
28 int libuc_main()
29 int libuc_main()
29 {
30 {
@@ -15,17 +15,10
15 #define DAC1 0
15 #define DAC1 0
16 #define DAC2 1
16 #define DAC2 1
17
17
18 #define timer2 1
19 #define timer3 2
20 #define timer4 3
21 #define timer5 4
22 #define timer6 5
23 #define timer7 6
24 #define timer8 7
25
18
26
19
27 extern int dacopen(uint32_t pin);
20 extern int dacopen(uint32_t pin);
28 extern int dacsetconfig(int timer, int buffer_size, int dac,uint32_t dac_type, uint32_t freq,uint32_t data);
21 extern int dacsetconfig(int timer, int buffer_size, int dac, uint32_t dac_type, uint32_t samplingFreq, void* data);
29
22
30
23
31
24
@@ -77,9 +77,6 extern int pwmsetfrequency(int PWM,uint3
77 #endif
77 #endif
78
78
79 #ifndef DOXYGEN_SHOULD_SKIP_THIS
79 #ifndef DOXYGEN_SHOULD_SKIP_THIS
80 #define UARTPARITYMASK 0x3
81 #define UARTBITSMASK 0xC
82 #define UARTSTOPBITSMASK 0x70
83
80
84 typedef enum
81 typedef enum
85 {
82 {
@@ -11,6 +11,7
11 #include <uart.h>
11 #include <uart.h>
12 #include <stdint.h>
12 #include <stdint.h>
13 #include <bsp.h>
13 #include <bsp.h>
14 #include <core.h>
14
15
15 #undef errno
16 #undef errno
16
17
@@ -1,5 +1,5
1 #include <stdio.h>
1 #include <stdio.h>
2 //#include <bsp.h>
2 #include <timer.h>
3 #include <stm32f4xx_rcc.h>
3 #include <stm32f4xx_rcc.h>
4 #include <stm32f4xx_tim.h>
4 #include <stm32f4xx_tim.h>
5 #include <stm32f4xx_dac.h>
5 #include <stm32f4xx_dac.h>
@@ -8,38 +8,17
8 #include <stm32f4xx.h>
8 #include <stm32f4xx.h>
9 #include <gpio.h>
9 #include <gpio.h>
10 #include <stm32f4xx.h>
10 #include <stm32f4xx.h>
11 #include <dac.h>
11
12
12
13
13 #define DAC_DHR12R2_ADDRESS 0x40007414
14 #define DAC_DHR12R2_ADDRESS 0x40007414
14 #define DAC_DHR8R1_ADDRESS 0x40007410
15 #define DAC_DHR8R1_ADDRESS 0x40007410
15
16
16 #define DAC1_12bit_right_align 0x40007408
17 #define DAC1_12bit_left_align 0x4000740C
18 #define DAC1_8bit_right_align 0x40007410
19 #define DAC2_12bit_right_align 0x40007414
20 #define DAC2_12bit_left_align 0x40007418
21 #define DAC2_8bit_right_align 0x4000741C
22 #define DAC_Dual_12bit_right_align 0x40007420
23 #define DAC_Dual_12bit_left_align 0x40007424
24 #define DAC_Dual_8bit_right_align 0x40007428
25 #define DAC_Dual_8bit_left_align 0x4000742C
26
27
28
17
29 const TIM_TypeDef* _timer_dev_table[14]={TIM1,TIM2,TIM3,TIM4,TIM5,TIM6,TIM7,
18 const TIM_TypeDef* _timer_dev_table[14]={TIM1,TIM2,TIM3,TIM4,TIM5,TIM6,TIM7,
30 TIM8,TIM9,TIM10,TIM11,TIM12,TIM13,TIM14};
19 TIM8,TIM9,TIM10,TIM11,TIM12,TIM13,TIM14};
31 #define DAC1 0
32 #define DAC2 1
33
20
34 #define timer2 1
35 #define timer3 2
36 #define timer4 3
37 #define timer5 4
38 #define timer6 5
39 #define timer7 6
40 #define timer8 7
41
21
42 DAC_InitTypeDef DAC_InitStructure;
43
22
44 int dacopen(uint32_t pin)
23 int dacopen(uint32_t pin)
45 {
24 {
@@ -54,23 +33,35 int dacopen(uint32_t pin)
54 return 0;
33 return 0;
55 }
34 }
56
35
57 int dacsetconfig(int timer, int buffer_size, int dac,uint32_t dac_type, uint32_t freq,uint32_t data)
36 int dacsetconfig(int timer, int buffer_size, int dac, uint32_t dac_type, uint32_t samplingFreq, void *data)
58 {
37 {
59 TIM_TypeDef* tim = _timer_dev_table[timer];
38 #include <core.h>
39 DAC_InitTypeDef DAC_InitStructure;
40 TIM_TypeDef* tim = (TIM_TypeDef*)_timer_dev_table[timer];
60 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
41 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
42 DMA_InitTypeDef DMA_InitStructure;
61 if(timer>=timer2 && timer <= timer7)RCC_APB1PeriphClockCmd((1<<(timer-1)), ENABLE);
43 if(timer>=timer2 && timer <= timer7)RCC_APB1PeriphClockCmd((1<<(timer-1)), ENABLE);
62 if(timer==timer8)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);
44 if(timer==timer8)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);
63 uint32_t timfreq = (81300)*buffer_size/(freq);
45 uint32_t timfreq = getCpuFreq()/2;
46 uint32_t period = timfreq/samplingFreq - 1;
47 uint16_t PrescalerValue=0;
48 while (period>=0x0FFFF)
49 {
50 PrescalerValue++;
51 timfreq = getCpuFreq()/(2*(PrescalerValue+1));
52 period = (timfreq/samplingFreq) - 1;
53 }
54 printf("period = %d \n\r prescaler = %d \n\r",period,PrescalerValue);
64 TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
55 TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
65 TIM_TimeBaseStructure.TIM_Period = timfreq;
56 TIM_TimeBaseStructure.TIM_Period = 10;
66 TIM_TimeBaseStructure.TIM_Prescaler = 0;
57 TIM_TimeBaseStructure.TIM_Prescaler = 0;
67 TIM_TimeBaseStructure.TIM_ClockDivision = 0;
58 TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
68 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
59 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
69 TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure);
60 TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure);
70 TIM_SelectOutputTrigger(tim, TIM_TRGOSource_Update);
61 TIM_SelectOutputTrigger(tim, TIM_TRGOSource_Update);
62 TIM_ARRPreloadConfig(tim, ENABLE);
71 TIM_Cmd(tim, ENABLE);
63 TIM_Cmd(tim, ENABLE);
72
64
73 DMA_InitTypeDef DMA_InitStructure;
74 if (timer == timer2)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
65 if (timer == timer2)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
75 if (timer == timer4)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T4_TRGO;
66 if (timer == timer4)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T4_TRGO;
76 if (timer == timer5)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T5_TRGO;
67 if (timer == timer5)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T5_TRGO;
@@ -5,25 +5,11
5 #include <stm32f4xx_tim.h>
5 #include <stm32f4xx_tim.h>
6 #include <core.h>
6 #include <core.h>
7 #include <gpio.h>
7 #include <gpio.h>
8 #include <timer.h>
9
8 const TIM_TypeDef* _timer_dev_table[14]={TIM1,TIM2,TIM3,TIM4,TIM5,TIM6,TIM7,
10 const TIM_TypeDef* _timer_dev_table[14]={TIM1,TIM2,TIM3,TIM4,TIM5,TIM6,TIM7,
9 TIM8,TIM9,TIM10,TIM11,TIM12,TIM13,TIM14};
11 TIM8,TIM9,TIM10,TIM11,TIM12,TIM13,TIM14};
10
12
11 #define timer1 0
12 #define timer2 1
13 #define timer3 2
14 #define timer4 3
15 #define timer5 4
16 #define timer6 5
17 #define timer7 6
18 #define timer8 7
19 #define timer9 8
20 #define timer10 9
21 #define timer11 10
22 #define timer12 11
23 #define timer13 12
24 #define timer14 13
25 #define timer15 14
26 #define timer16 15
27
13
28 #define PWMGETTIMNUMBER(PWM) (((uint32_t)(PWM) & (uint32_t)0x0000FF00)>>(uint32_t)8)
14 #define PWMGETTIMNUMBER(PWM) (((uint32_t)(PWM) & (uint32_t)0x0000FF00)>>(uint32_t)8)
29
15
@@ -4,6 +4,7 CONFIG += ordered
4 SUBDIRS = CORE/core.pro \
4 SUBDIRS = CORE/core.pro \
5 CPU/cpu.pro \
5 CPU/cpu.pro \
6 GPIO/gpio.pro \
6 GPIO/gpio.pro \
7 TIMER/timer.pro \
7 UART/uart.pro \
8 UART/uart.pro \
8 SPI/spi.pro \
9 SPI/spi.pro \
9 I2C/i2c.pro \
10 I2C/i2c.pro \
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (509 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (566 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (808 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (509 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (1651 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (504 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (772 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (566 lines changed) Show them Hide them
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now