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
370a8116
Commit
370a8116
authored
5 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
stm32/mphalport: Add support for having MAC in OTP region.
parent
10e173aa
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ports/stm32/mphalport.c
+32
-0
32 additions, 0 deletions
ports/stm32/mphalport.c
ports/stm32/mphalport.h
+1
-0
1 addition, 0 deletions
ports/stm32/mphalport.h
with
33 additions
and
0 deletions
ports/stm32/mphalport.c
+
32
−
0
View file @
370a8116
...
...
@@ -151,7 +151,30 @@ void mp_hal_pin_config_speed(mp_hal_pin_obj_t pin_obj, uint32_t speed) {
gpio
->
OSPEEDR
=
(
gpio
->
OSPEEDR
&
~
(
3
<<
(
2
*
pin
)))
|
(
speed
<<
(
2
*
pin
));
}
/*******************************************************************************/
// MAC address
typedef
struct
_pyb_otp_t
{
uint16_t
series
;
uint16_t
rev
;
uint8_t
mac
[
6
];
}
pyb_otp_t
;
#if defined(STM32F722xx) || defined(STM32F723xx) || defined(STM32F732xx) || defined(STM32F733xx)
#define OTP_ADDR (0x1ff079e0)
#else
#define OTP_ADDR (0x1ff0f3c0)
#endif
#define OTP ((pyb_otp_t*)OTP_ADDR)
MP_WEAK
void
mp_hal_get_mac
(
int
idx
,
uint8_t
buf
[
6
])
{
// Check if OTP region has a valid MAC address, and use it if it does
if
(
OTP
->
series
==
0x00d1
&&
OTP
->
mac
[
0
]
==
'H'
&&
OTP
->
mac
[
1
]
==
'J'
&&
OTP
->
mac
[
2
]
==
'0'
)
{
memcpy
(
buf
,
OTP
->
mac
,
6
);
buf
[
5
]
+=
idx
;
return
;
}
// Generate a random locally administered MAC address (LAA)
uint8_t
*
id
=
(
uint8_t
*
)
MP_HAL_UNIQUE_ID_ADDRESS
;
buf
[
0
]
=
0x02
;
// LAA range
...
...
@@ -161,3 +184,12 @@ MP_WEAK void mp_hal_get_mac(int idx, uint8_t buf[6]) {
buf
[
4
]
=
id
[
2
];
buf
[
5
]
=
(
id
[
0
]
<<
2
)
|
idx
;
}
void
mp_hal_get_mac_ascii
(
int
idx
,
size_t
chr_off
,
size_t
chr_len
,
char
*
dest
)
{
static
const
char
hexchr
[
16
]
=
"0123456789ABCDEF"
;
uint8_t
mac
[
6
];
mp_hal_get_mac
(
idx
,
mac
);
for
(;
chr_len
;
++
chr_off
,
--
chr_len
)
{
*
dest
++
=
hexchr
[
mac
[
chr_off
>>
1
]
>>
(
4
*
(
1
-
(
chr_off
&
1
)))
&
0xf
];
}
}
This diff is collapsed.
Click to expand it.
ports/stm32/mphalport.h
+
1
−
0
View file @
370a8116
...
...
@@ -88,3 +88,4 @@ enum {
};
void
mp_hal_get_mac
(
int
idx
,
uint8_t
buf
[
6
]);
void
mp_hal_get_mac_ascii
(
int
idx
,
size_t
chr_off
,
size_t
chr_len
,
char
*
dest
);
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