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
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
dfe8980a
Commit
dfe8980a
authored
7 years ago
by
Peter D. Gray
Committed by
Damien George
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
stm32/spi: If MICROPY_HW_SPIn_MISO undefined, do not claim pin on init.
This permits output-only SPI use.
parent
b25f9216
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ports/stm32/spi.c
+17
-3
17 additions, 3 deletions
ports/stm32/spi.c
with
17 additions
and
3 deletions
ports/stm32/spi.c
+
17
−
3
View file @
dfe8980a
...
...
@@ -243,8 +243,7 @@ STATIC void spi_set_params(SPI_HandleTypeDef *spi, uint32_t prescale, int32_t ba
// TODO allow to take a list of pins to use
void
spi_init
(
SPI_HandleTypeDef
*
spi
,
bool
enable_nss_pin
)
{
const
pyb_spi_obj_t
*
self
;
const
pin_obj_t
*
pins
[
4
];
pins
[
0
]
=
NULL
;
const
pin_obj_t
*
pins
[
4
]
=
{
NULL
,
NULL
,
NULL
,
NULL
};
if
(
0
)
{
#if defined(MICROPY_HW_SPI1_SCK)
...
...
@@ -254,7 +253,9 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
pins
[
0
]
=
&
MICROPY_HW_SPI1_NSS
;
#endif
pins
[
1
]
=
&
MICROPY_HW_SPI1_SCK
;
#if defined(MICROPY_HW_SPI1_MISO)
pins
[
2
]
=
&
MICROPY_HW_SPI1_MISO
;
#endif
pins
[
3
]
=
&
MICROPY_HW_SPI1_MOSI
;
// enable the SPI clock
__SPI1_CLK_ENABLE
();
...
...
@@ -266,7 +267,9 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
pins
[
0
]
=
&
MICROPY_HW_SPI2_NSS
;
#endif
pins
[
1
]
=
&
MICROPY_HW_SPI2_SCK
;
#if defined(MICROPY_HW_SPI2_MISO)
pins
[
2
]
=
&
MICROPY_HW_SPI2_MISO
;
#endif
pins
[
3
]
=
&
MICROPY_HW_SPI2_MOSI
;
// enable the SPI clock
__SPI2_CLK_ENABLE
();
...
...
@@ -278,7 +281,9 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
pins
[
0
]
=
&
MICROPY_HW_SPI3_NSS
;
#endif
pins
[
1
]
=
&
MICROPY_HW_SPI3_SCK
;
#if defined(MICROPY_HW_SPI3_MISO)
pins
[
2
]
=
&
MICROPY_HW_SPI3_MISO
;
#endif
pins
[
3
]
=
&
MICROPY_HW_SPI3_MOSI
;
// enable the SPI clock
__SPI3_CLK_ENABLE
();
...
...
@@ -290,7 +295,9 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
pins
[
0
]
=
&
MICROPY_HW_SPI4_NSS
;
#endif
pins
[
1
]
=
&
MICROPY_HW_SPI4_SCK
;
#if defined(MICROPY_HW_SPI4_MISO)
pins
[
2
]
=
&
MICROPY_HW_SPI4_MISO
;
#endif
pins
[
3
]
=
&
MICROPY_HW_SPI4_MOSI
;
// enable the SPI clock
__SPI4_CLK_ENABLE
();
...
...
@@ -302,7 +309,9 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
pins
[
0
]
=
&
MICROPY_HW_SPI5_NSS
;
#endif
pins
[
1
]
=
&
MICROPY_HW_SPI5_SCK
;
#if defined(MICROPY_HW_SPI5_MISO)
pins
[
2
]
=
&
MICROPY_HW_SPI5_MISO
;
#endif
pins
[
3
]
=
&
MICROPY_HW_SPI5_MOSI
;
// enable the SPI clock
__SPI5_CLK_ENABLE
();
...
...
@@ -314,7 +323,9 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
pins
[
0
]
=
&
MICROPY_HW_SPI6_NSS
;
#endif
pins
[
1
]
=
&
MICROPY_HW_SPI6_SCK
;
#if defined(MICROPY_HW_SPI6_MISO)
pins
[
2
]
=
&
MICROPY_HW_SPI6_MISO
;
#endif
pins
[
3
]
=
&
MICROPY_HW_SPI6_MOSI
;
// enable the SPI clock
__SPI6_CLK_ENABLE
();
...
...
@@ -327,7 +338,10 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
// init the GPIO lines
uint32_t
mode
=
MP_HAL_PIN_MODE_ALT
;
uint32_t
pull
=
spi
->
Init
.
CLKPolarity
==
SPI_POLARITY_LOW
?
MP_HAL_PIN_PULL_DOWN
:
MP_HAL_PIN_PULL_UP
;
for
(
uint
i
=
(
enable_nss_pin
&&
pins
[
0
]
?
0
:
1
);
i
<
4
;
i
++
)
{
for
(
uint
i
=
(
enable_nss_pin
?
0
:
1
);
i
<
4
;
i
++
)
{
if
(
pins
[
i
]
==
NULL
)
{
continue
;
}
mp_hal_pin_config_alt
(
pins
[
i
],
mode
,
pull
,
AF_FN_SPI
,
(
self
-
&
pyb_spi_obj
[
0
])
+
1
);
}
...
...
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