Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
5af6184e
Commit
5af6184e
authored
Aug 23, 2016
by
Matt Brejza
Committed by
Damien George
Aug 25, 2016
Browse files
Options
Downloads
Patches
Plain Diff
stmhal: Make ADC channel 16 available on L4 MCUs.
parent
c4283675
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
stmhal/adc.c
+20
-5
20 additions, 5 deletions
stmhal/adc.c
stmhal/boards/make-pins.py
+5
-1
5 additions, 1 deletion
stmhal/boards/make-pins.py
with
25 additions
and
6 deletions
stmhal/adc.c
+
20
−
5
View file @
5af6184e
...
@@ -54,7 +54,16 @@
...
@@ -54,7 +54,16 @@
#define ADCx (ADC1)
#define ADCx (ADC1)
#define ADCx_CLK_ENABLE __ADC1_CLK_ENABLE
#define ADCx_CLK_ENABLE __ADC1_CLK_ENABLE
#define ADC_NUM_CHANNELS (19)
#define ADC_NUM_CHANNELS (19)
#define ADC_NUM_GPIO_CHANNELS (16)
#if defined(MCU_SERIES_F4) || defined(MCU_SERIES_F7)
#define ADC_FIRST_GPIO_CHANNEL (0)
#define ADC_LAST_GPIO_CHANNEL (15)
#elif defined(MCU_SERIES_L4)
#define ADC_FIRST_GPIO_CHANNEL (1)
#define ADC_LAST_GPIO_CHANNEL (16)
#else
#error Unsupported processor
#endif
#if defined(STM32F405xx) || defined(STM32F415xx) || \
#if defined(STM32F405xx) || defined(STM32F415xx) || \
defined(STM32F407xx) || defined(STM32F417xx) || \
defined(STM32F407xx) || defined(STM32F417xx) || \
...
@@ -124,7 +133,7 @@ STATIC void adc_init_single(pyb_obj_adc_t *adc_obj) {
...
@@ -124,7 +133,7 @@ STATIC void adc_init_single(pyb_obj_adc_t *adc_obj) {
return
;
return
;
}
}
if
(
adc_obj
->
channel
<
ADC_
NUM
_GPIO_CHANNEL
S
)
{
if
(
ADC_FIRST_GPIO_CHANNEL
<=
adc_obj
->
channel
&&
adc_obj
->
channel
<
=
ADC_
LAST
_GPIO_CHANNEL
)
{
// Channels 0-16 correspond to real pins. Configure the GPIO pin in
// Channels 0-16 correspond to real pins. Configure the GPIO pin in
// ADC mode.
// ADC mode.
const
pin_obj_t
*
pin
=
pin_adc1
[
adc_obj
->
channel
];
const
pin_obj_t
*
pin
=
pin_adc1
[
adc_obj
->
channel
];
...
@@ -253,8 +262,14 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uin
...
@@ -253,8 +262,14 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uin
if
(
!
is_adcx_channel
(
channel
))
{
if
(
!
is_adcx_channel
(
channel
))
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_ValueError
,
"not a valid ADC Channel: %d"
,
channel
));
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_ValueError
,
"not a valid ADC Channel: %d"
,
channel
));
}
}
if
(
ADC_FIRST_GPIO_CHANNEL
<=
channel
&&
channel
<=
ADC_LAST_GPIO_CHANNEL
)
{
// these channels correspond to physical GPIO ports so make sure they exist
if
(
pin_adc1
[
channel
]
==
NULL
)
{
if
(
pin_adc1
[
channel
]
==
NULL
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_ValueError
,
"channel %d not available on this board"
,
channel
));
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_ValueError
,
"channel %d not available on this board"
,
channel
));
}
}
}
pyb_obj_adc_t
*
o
=
m_new_obj
(
pyb_obj_adc_t
);
pyb_obj_adc_t
*
o
=
m_new_obj
(
pyb_obj_adc_t
);
...
@@ -423,7 +438,7 @@ void adc_init_all(pyb_adc_all_obj_t *adc_all, uint32_t resolution) {
...
@@ -423,7 +438,7 @@ void adc_init_all(pyb_adc_all_obj_t *adc_all, uint32_t resolution) {
"resolution %d not supported"
,
resolution
));
"resolution %d not supported"
,
resolution
));
}
}
for
(
uint32_t
channel
=
0
;
channel
<
ADC_
NUM
_GPIO_CHANNEL
S
;
channel
++
)
{
for
(
uint32_t
channel
=
ADC_FIRST_GPIO_CHANNEL
;
channel
<
=
ADC_
LAST
_GPIO_CHANNEL
;
++
channel
)
{
// Channels 0-16 correspond to real pins. Configure the GPIO pin in
// Channels 0-16 correspond to real pins. Configure the GPIO pin in
// ADC mode.
// ADC mode.
const
pin_obj_t
*
pin
=
pin_adc1
[
channel
];
const
pin_obj_t
*
pin
=
pin_adc1
[
channel
];
...
...
This diff is collapsed.
Click to expand it.
stmhal/boards/make-pins.py
+
5
−
1
View file @
5af6184e
...
@@ -303,7 +303,9 @@ class Pins(object):
...
@@ -303,7 +303,9 @@ class Pins(object):
def
print_adc
(
self
,
adc_num
):
def
print_adc
(
self
,
adc_num
):
print
(
''
);
print
(
''
);
print
(
'
const pin_obj_t * const pin_adc{:d}[] = {{
'
.
format
(
adc_num
))
print
(
'
const pin_obj_t * const pin_adc{:d}[] = {{
'
.
format
(
adc_num
))
for
channel
in
range
(
16
):
for
channel
in
range
(
17
):
if
channel
==
16
:
print
(
'
#if defined(MCU_SERIES_L4)
'
)
adc_found
=
False
adc_found
=
False
for
named_pin
in
self
.
cpu_pins
:
for
named_pin
in
self
.
cpu_pins
:
pin
=
named_pin
.
pin
()
pin
=
named_pin
.
pin
()
...
@@ -314,6 +316,8 @@ class Pins(object):
...
@@ -314,6 +316,8 @@ class Pins(object):
break
break
if
not
adc_found
:
if
not
adc_found
:
print
(
'
NULL, // {:d}
'
.
format
(
channel
))
print
(
'
NULL, // {:d}
'
.
format
(
channel
))
if
channel
==
16
:
print
(
'
#endif
'
)
print
(
'
};
'
)
print
(
'
};
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment