-
Notifications
You must be signed in to change notification settings - Fork 5
/
my_note.txt
194 lines (169 loc) · 6.79 KB
/
my_note.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Launch OpenOCD
#cd ~/Downloads/ChibiStudio_Linux_Preview2/ChibiStudio/tools/openocd/scripts
#~/opt/xPacks/@gnu-mcu-eclipse/openocd/0.10.0-12.1/.content/bin/openocd -f board/stm32f3discovery.cfg
~/opt/xPacks/@gnu-mcu-eclipse/openocd/0.10.0-12.1/.content/bin/openocd -f ~/Downloads/ChibiStudio_Linux_Preview2/ChibiStudio/tools/openocd/scripts/board/stm32f3discovery.cfg
# Launch ChibiStudio
#cd ~/Downloads/ChibiStudio_Linux_Preview2/ChibiStudio
#./ChibiStudio-GCC7.3.1 &
~/Downloads/ChibiStudio_Linux_Preview2/ChibiStudio/ChibiStudio-GCC7.3.1 &
#Launch STM32CubeMX
#cd /usr/local/STMicroelectronics/STM32Cube/STM32CubeMX
#./STM32CubeMX &
/usr/local/STMicroelectronics/STM32Cube/STM32CubeMX/STM32CubeMX &
# How to use ChibiSTudio
https://www.playembedded.org/blog/debugging-stm32-chibistudio/
cp hal_adc_lld.c.fixed ./ChibiOS/os/hal/ports/STM32/LLD/ADCv3/hal_adc_lld.c
#Merge with upstream
#git remote add upstream <URL>
git fetch upstream
git merge upstream/master
-> git stash and merge, resolve conflicts before commit.
ADC:
pin PA6 is ADC2_IN3
pin PA7 is ADC2_IN4
Special ADC channels
- Temperature sensor connected to ADC1 channel 16
- V BAT/2 connected to ADC1 channel 17
- Voltage reference V REFINT connected to the 4 ADCs channel 18
- VOPAMP1 connected to ADC1 channel 15
- VOPAMP2 connected to ADC2 channel 17
- VREFOPAMP3 connected to ADC3 channel 17
- VREFOPAMP4 connected to ADC4 channel 17
ADC Analog Watchdog reference:
http://www.chibios.com/forum/viewtopic.php?t=3959
~/Downloads/ChibiOS_18.2.2/testhal/STM32/STM32F3xx/ADC
STM32BubeMX:
cd /usr/local/STMicroelectronics/STM32Cube/STM32CubeMX$
./STM32CubeMX &
ADC: copied from ChibiOS/os/hal/ports/STM32/LLD/ADCv3/hal_adc_lld.h for reference
ChibiOS/os/common/ext/CMSIS/ST/STM32F3xx/stm32f302xc.h
/**
* @brief Conversion group configuration structure.
* @details This implementation-dependent structure describes a conversion
* operation.
* @note The use of this configuration structure requires knowledge of
* STM32 ADC cell registers interface, please refer to the STM32
* reference manual for details.
*/
// ADCConversionGroup
typedef struct {
/**
* @brief Enables the circular buffer mode for the group.
*/
bool circular;
/**
* @brief Number of the analog channels belonging to the conversion group.
*/
adc_channels_num_t num_channels;
/**
* @brief Callback function associated to the group or @p NULL.
*/
adccallback_t end_cb;
/**
* @brief Error callback or @p NULL.
*/
adcerrorcallback_t error_cb;
/* End of the mandatory fields.*/
/**
* @brief ADC CFGR register initialization data.
* @note The bits DMAEN and DMACFG are enforced internally
* to the driver, keep them to zero.
* @note The bits @p ADC_CFGR_CONT or @p ADC_CFGR_DISCEN must be
* specified in continuous mode or if the buffer depth is
* greater than one.
*/
uint32_t cfgr;
/**
* @brief ADC TR1 register initialization data.
*/
uint32_t tr1;
/**
* @brief ADC SMPRx registers initialization data.
*/
uint32_t smpr[2];
/**
* @brief ADC SQRx register initialization data.
*/
uint32_t sqr[4];
} ADCConversionGroup;
/**
* @name CFGR register configuration helpers
* @{
*/
#define ADC_CFGR_DMACFG_MASK (1 << 1)
#define ADC_CFGR_DMACFG_ONESHOT (0 << 1)
#define ADC_CFGR_DMACFG_CIRCULAR (1 << 1)
#define ADC_CFGR_RES_MASK (3 << 3)
#define ADC_CFGR_RES_12BITS (0 << 3)
#define ADC_CFGR_RES_10BITS (1 << 3)
#define ADC_CFGR_RES_8BITS (2 << 3)
#define ADC_CFGR_RES_6BITS (3 << 3)
#define ADC_CFGR_ALIGN_MASK (1 << 5)
#define ADC_CFGR_ALIGN_RIGHT (0 << 5)
#define ADC_CFGR_ALIGN_LEFT (1 << 5)
#define ADC_CFGR_EXTSEL_MASK (15 << 6)
#define ADC_CFGR_EXTSEL_SRC(n) ((n) << 6)
#define ADC_CFGR_EXTEN_MASK (3 << 10)
#define ADC_CFGR_EXTEN_DISABLED (0 << 10)
#define ADC_CFGR_EXTEN_RISING (1 << 10)
#define ADC_CFGR_EXTEN_FALLING (2 << 10)
#define ADC_CFGR_EXTEN_BOTH (3 << 10)
#define ADC_CFGR_DISCEN_MASK (1 << 16)
#define ADC_CFGR_DISCEN_DISABLED (0 << 16)
#define ADC_CFGR_DISCEN_ENABLED (1 << 16)
#define ADC_CFGR_DISCNUM_MASK (7 << 17)
#define ADC_CFGR_DISCNUM_VAL(n) ((n) << 17)
#define ADC_CFGR_AWD1_DISABLED 0
#define ADC_CFGR_AWD1_ALL (1 << 23)
#define ADC_CFGR_AWD1_SINGLE(n) (((n) << 26) | (1 << 23) | (1 << 22))
/** @} */
/**
* @name CCR register configuration helpers
* @{
*/
#define ADC_CCR_DUAL_MASK (31 << 0)
#define ADC_CCR_DUAL_FIELD(n) ((n) << 0)
#define ADC_CCR_DELAY_MASK (15 << 8)
#define ADC_CCR_DELAY_FIELD(n) ((n) << 8)
#define ADC_CCR_DMACFG_MASK (1 << 13)
#define ADC_CCR_DMACFG_ONESHOT (0 << 13)
#define ADC_CCR_DMACFG_CIRCULAR (1 << 13)
#define ADC_CCR_MDMA_MASK (3 << 14)
#define ADC_CCR_MDMA_DISABLED (0 << 14)
#define ADC_CCR_MDMA_WORD (2 << 14)
#define ADC_CCR_MDMA_HWORD (3 << 14)
#define ADC_CCR_CKMODE_MASK (3 << 16)
#define ADC_CCR_CKMODE_ADCCK (0 << 16)
#define ADC_CCR_CKMODE_AHB_DIV1 (1 << 16)
#define ADC_CCR_CKMODE_AHB_DIV2 (2 << 16)
#define ADC_CCR_CKMODE_AHB_DIV4 (3 << 16)
USART/Serial/SD1:
https://www.playembedded.org/blog/stm32-usart-chibios-serial/
https://www.playembedded.org/blog/vcp-stm32-chibios/
Bluetooth connection in Ubuntu
HC-05 MAC: 98:D3:32:21:B5:AE
Reference: https://askubuntu.com/questions/248817/how-to-i-connect-a-raw-serial-terminal-to-a-bluetooth-connection
sudo apt-get install bluez bluez-tools
sudo bluetoothctl
#scan on
#pair <MAC address>
#pair 98:D3:32:21:B5:AE
# connect 98:D3:32:21:B5:AE
#ctrl-D
sudo rfcomm connect /dev/rfcomm0 <MAC address> 1 &
sudo rfcomm connect /dev/rfcomm0 98:D3:32:21:B5:AE 1 &
or sudo rfcomm connect /dev/rfcomm0 98:D3:32:21:B5:AE 1
and use Ctrl-C to hangup
sudo screen /dev/rfcomm0
or
sudo minicom -D /dev/rfcomm0
or
Python download this script https://sourceforge.net/p/pyserial/code/HEAD/tree/trunk/pyserial/serial/tools/miniterm.py
chmod +x miniterm.py
sudo ./miniterm.py /dev/rfcomm0
If necessary, do "reset" after entering shell
Use PyBlueZ to connect to Bluetooth
https://pybluez.github.io/ https://github.com/pybluez/pybluez https://pypi.org/project/PyBluez-win10/
https://stackoverflow.com/questions/37465157/pairing-bluetooth-devices-with-passkey-password-in-python-rfcomm-linux
Use Bluetooth Serial Terminal for Windows 10 for Bluetooth (HC-05)
Use AirTerminal or BLE Terminal app for iOS for BLE (HC-08 or JDY-32)