Skip to content

Commit d8f717b

Browse files
author
franco.polo
committed
ADC section done.-
1 parent 835fc71 commit d8f717b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+10899
-0
lines changed

Cpp/65_adc/App/main.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "uart.h"
2+
#include "stdio.h"
3+
#include "adc.h"
4+
5+
6+
std::uint32_t sensorVal;
7+
8+
int main(void){
9+
/*Init USART6*/
10+
uart6_init();
11+
/*ADC1 Init*/
12+
adc1_init();
13+
14+
/*Superloop*/
15+
while(true){
16+
/*Read ADC*/
17+
sensorVal = adc1_get();
18+
}
19+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// File: STM32F405_415_407_417_427_437_429_439.dbgconf
2+
// Version: 1.0.0
3+
// Note: refer to STM32F405/415 STM32F407/417 STM32F427/437 STM32F429/439 reference manual (RM0090)
4+
// refer to STM32F40x STM32F41x datasheets
5+
// refer to STM32F42x STM32F43x datasheets
6+
7+
// <<< Use Configuration Wizard in Context Menu >>>
8+
9+
// <h> Debug MCU configuration register (DBGMCU_CR)
10+
// <o.2> DBG_STANDBY <i> Debug Standby Mode
11+
// <o.1> DBG_STOP <i> Debug Stop Mode
12+
// <o.0> DBG_SLEEP <i> Debug Sleep Mode
13+
// </h>
14+
DbgMCU_CR = 0x00000007;
15+
16+
// <h> Debug MCU APB1 freeze register (DBGMCU_APB1_FZ)
17+
// <i> Reserved bits must be kept at reset value
18+
// <o.26> DBG_CAN2_STOP <i> CAN2 stopped when core is halted
19+
// <o.25> DBG_CAN1_STOP <i> CAN2 stopped when core is halted
20+
// <o.23> DBG_I2C3_SMBUS_TIMEOUT <i> I2C3 SMBUS timeout mode stopped when core is halted
21+
// <o.22> DBG_I2C2_SMBUS_TIMEOUT <i> I2C2 SMBUS timeout mode stopped when core is halted
22+
// <o.21> DBG_I2C1_SMBUS_TIMEOUT <i> I2C1 SMBUS timeout mode stopped when core is halted
23+
// <o.12> DBG_IWDG_STOP <i> Independent watchdog stopped when core is halted
24+
// <o.11> DBG_WWDG_STOP <i> Window watchdog stopped when core is halted
25+
// <o.10> DBG_RTC_STOP <i> RTC stopped when core is halted
26+
// <o.8> DBG_TIM14_STOP <i> TIM14 counter stopped when core is halted
27+
// <o.7> DBG_TIM13_STOP <i> TIM13 counter stopped when core is halted
28+
// <o.6> DBG_TIM12_STOP <i> TIM12 counter stopped when core is halted
29+
// <o.5> DBG_TIM7_STOP <i> TIM7 counter stopped when core is halted
30+
// <o.4> DBG_TIM6_STOP <i> TIM6 counter stopped when core is halted
31+
// <o.3> DBG_TIM5_STOP <i> TIM5 counter stopped when core is halted
32+
// <o.2> DBG_TIM4_STOP <i> TIM4 counter stopped when core is halted
33+
// <o.1> DBG_TIM3_STOP <i> TIM3 counter stopped when core is halted
34+
// <o.0> DBG_TIM2_STOP <i> TIM2 counter stopped when core is halted
35+
// </h>
36+
DbgMCU_APB1_Fz = 0x00000000;
37+
38+
// <h> Debug MCU APB2 freeze register (DBGMCU_APB2_FZ)
39+
// <i> Reserved bits must be kept at reset value
40+
// <o.18> DBG_TIM11_STOP <i> TIM11 counter stopped when core is halted
41+
// <o.17> DBG_TIM10_STOP <i> TIM10 counter stopped when core is halted
42+
// <o.16> DBG_TIM9_STOP <i> TIM9 counter stopped when core is halted
43+
// <o.1> DBG_TIM8_STOP <i> TIM8 counter stopped when core is halted
44+
// <o.0> DBG_TIM1_STOP <i> TIM1 counter stopped when core is halted
45+
// </h>
46+
DbgMCU_APB2_Fz = 0x00000000;
47+
48+
// <<< end of configuration section >>>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// File: STM32F405_415_407_417_427_437_429_439.dbgconf
2+
// Version: 1.0.0
3+
// Note: refer to STM32F405/415 STM32F407/417 STM32F427/437 STM32F429/439 reference manual (RM0090)
4+
// refer to STM32F40x STM32F41x datasheets
5+
// refer to STM32F42x STM32F43x datasheets
6+
7+
// <<< Use Configuration Wizard in Context Menu >>>
8+
9+
// <h> Debug MCU configuration register (DBGMCU_CR)
10+
// <o.2> DBG_STANDBY <i> Debug Standby Mode
11+
// <o.1> DBG_STOP <i> Debug Stop Mode
12+
// <o.0> DBG_SLEEP <i> Debug Sleep Mode
13+
// </h>
14+
DbgMCU_CR = 0x00000007;
15+
16+
// <h> Debug MCU APB1 freeze register (DBGMCU_APB1_FZ)
17+
// <i> Reserved bits must be kept at reset value
18+
// <o.26> DBG_CAN2_STOP <i> CAN2 stopped when core is halted
19+
// <o.25> DBG_CAN1_STOP <i> CAN2 stopped when core is halted
20+
// <o.23> DBG_I2C3_SMBUS_TIMEOUT <i> I2C3 SMBUS timeout mode stopped when core is halted
21+
// <o.22> DBG_I2C2_SMBUS_TIMEOUT <i> I2C2 SMBUS timeout mode stopped when core is halted
22+
// <o.21> DBG_I2C1_SMBUS_TIMEOUT <i> I2C1 SMBUS timeout mode stopped when core is halted
23+
// <o.12> DBG_IWDG_STOP <i> Independent watchdog stopped when core is halted
24+
// <o.11> DBG_WWDG_STOP <i> Window watchdog stopped when core is halted
25+
// <o.10> DBG_RTC_STOP <i> RTC stopped when core is halted
26+
// <o.8> DBG_TIM14_STOP <i> TIM14 counter stopped when core is halted
27+
// <o.7> DBG_TIM13_STOP <i> TIM13 counter stopped when core is halted
28+
// <o.6> DBG_TIM12_STOP <i> TIM12 counter stopped when core is halted
29+
// <o.5> DBG_TIM7_STOP <i> TIM7 counter stopped when core is halted
30+
// <o.4> DBG_TIM6_STOP <i> TIM6 counter stopped when core is halted
31+
// <o.3> DBG_TIM5_STOP <i> TIM5 counter stopped when core is halted
32+
// <o.2> DBG_TIM4_STOP <i> TIM4 counter stopped when core is halted
33+
// <o.1> DBG_TIM3_STOP <i> TIM3 counter stopped when core is halted
34+
// <o.0> DBG_TIM2_STOP <i> TIM2 counter stopped when core is halted
35+
// </h>
36+
DbgMCU_APB1_Fz = 0x00000000;
37+
38+
// <h> Debug MCU APB2 freeze register (DBGMCU_APB2_FZ)
39+
// <i> Reserved bits must be kept at reset value
40+
// <o.18> DBG_TIM11_STOP <i> TIM11 counter stopped when core is halted
41+
// <o.17> DBG_TIM10_STOP <i> TIM10 counter stopped when core is halted
42+
// <o.16> DBG_TIM9_STOP <i> TIM9 counter stopped when core is halted
43+
// <o.1> DBG_TIM8_STOP <i> TIM8 counter stopped when core is halted
44+
// <o.0> DBG_TIM1_STOP <i> TIM1 counter stopped when core is halted
45+
// </h>
46+
DbgMCU_APB2_Fz = 0x00000000;
47+
48+
// <<< end of configuration section >>>

Cpp/65_adc/Drivers/adc.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include "adc.h"
2+
3+
#define ADC1((mcal::reg::ADC_TypeDef*)mcal::reg::adc1_base)
4+
5+
void adc1_init(void){
6+
7+
/*Enable clock access to PA1*/
8+
mcal::reg::reg_access<
9+
std::uint32_t,
10+
std::uint32_t,
11+
mcal::reg::ahb1enr,
12+
(1U<<0)
13+
>::reg_or();
14+
15+
/*Configure PA1 as analog*/
16+
mcal::reg::reg_access<
17+
std::uint32_t,
18+
std::uint32_t,
19+
mcal::reg::gpioa_moder,
20+
(1U<<2)
21+
>::reg_or();
22+
mcal::reg::reg_access<
23+
std::uint32_t,
24+
std::uint32_t,
25+
mcal::reg::gpioa_moder,
26+
(1U<<3)
27+
>::reg_or();
28+
//mcal::reg::reg_access<
29+
//std::uint32_t,
30+
//std::uint32_t,
31+
//mcal::reg::ahb1enr,
32+
//(0x0C)
33+
// >::reg_or();
34+
35+
/*Enable clock access to adc1*/
36+
mcal::reg::reg_access<
37+
std::uint32_t,
38+
std::uint32_t,
39+
mcal::reg::apb2enr,
40+
(1U<<8)
41+
>::reg_or();
42+
43+
/*SW trigger*/
44+
mcal::reg::reg_access<
45+
std::uint32_t,
46+
std::uint32_t,
47+
mcal::reg::adc1_cr2,
48+
(0x00)
49+
>::reg_set();
50+
51+
/*Conversion sequence starts at channel1*/
52+
mcal::reg::reg_access<
53+
std::uint32_t,
54+
std::uint32_t,
55+
mcal::reg::adc1_sqr3,
56+
(1U<<0)
57+
>::reg_set();
58+
59+
60+
/*Conversion sequence length*/
61+
mcal::reg::reg_access<
62+
std::uint32_t,
63+
std::uint32_t,
64+
mcal::reg::adc1_sqr1,
65+
(0x00)
66+
>::reg_set();
67+
68+
/*Enable ADC*/
69+
mcal::reg::reg_access<
70+
std::uint32_t,
71+
std::uint32_t,
72+
mcal::reg::adc1_cr2,
73+
(1U<<0)
74+
>::reg_or();
75+
76+
}
77+
78+
/*adc1_get*/
79+
std::uint32_t adc1_get(void){
80+
/*Start conversion*/
81+
mcal::reg::reg_access<
82+
std::uint32_t,
83+
std::uint32_t,
84+
mcal::reg::adc1_cr2,
85+
(1U<<30)
86+
>::reg_or();
87+
88+
/*Wait for conversion*/
89+
while(!(ADC1->SR) & (0x02)){}
90+
91+
/*Read value from data register*/
92+
return mcal::reg::reg_access<
93+
std::uint32_t,
94+
std::uint32_t,
95+
mcal::reg::adc1_dr,
96+
(1U<<30)
97+
>::reg_get();
98+
99+
100+
}

Cpp/65_adc/Drivers/adc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef __ADC_H
2+
#define __ADC_H
3+
4+
#include "mcal_reg.h"
5+
6+
7+
void adc1_init(void);
8+
std::uint32_t adc1_get(void);
9+
10+
#endif // __ADC_H

0 commit comments

Comments
 (0)