Skip to content

Commit 7e9ccee

Browse files
committed
ports/stm32: Add libmetal port.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent fb4fc43 commit 7e9ccee

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

ports/stm32/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,10 @@ endif
493493

494494
endif # MICROPY_PY_BLUETOOTH
495495

496+
ifeq ($(MICROPY_PY_OPENAMP),1)
497+
SRC_C += metal/metal_port.c
498+
endif
499+
496500
# SRC_O should be placed first to work around this LTO bug with binutils <2.35:
497501
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83967
498502
OBJ += $(addprefix $(BUILD)/, $(SRC_O))

ports/stm32/metal/metal_config.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2023 Arduino SA
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
* libmetal stm32 port.
27+
*/
28+
#ifndef MICROPY_INCLUDED_STM32_METAL_CONFIG_H
29+
#define MICROPY_INCLUDED_STM32_METAL_CONFIG_H
30+
31+
#include <stdlib.h>
32+
#include "py/mphal.h"
33+
34+
#define METAL_PROCESSOR_CPU_H "metal/processor/arm/cpu.h"
35+
#define METAL_PROCESSOR_ATOMIC_H "metal/processor/arm/atomic.h"
36+
37+
#define HAVE_STDATOMIC_H 0
38+
#define HAVE_FUTEX_H 0
39+
#define MAX_IRQS 8
40+
#define METAL_MAX_DEVICE_REGIONS 2
41+
42+
#define metal_cpu_yield()
43+
#define metal_sys_assert(cond) assert(cond)
44+
#define metal_generic_default_poll() MICROPY_EVENT_POLL_HOOK
45+
#define __metal_sleep_usec(usec) mp_hal_delay_us(usec);
46+
47+
#endif // MICROPY_INCLUDED_STM32_METAL_CONFIG_H

ports/stm32/metal/metal_port.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2023 Arduino SA
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
* libmetal stm32 port.
27+
*/
28+
#include "metal/sys.h"
29+
#include "metal/utilities.h"
30+
#include "metal/device.h"
31+
32+
struct metal_state _metal;
33+
34+
int metal_sys_init(const struct metal_init_params *params) {
35+
metal_unused(params);
36+
metal_bus_register(&metal_generic_bus);
37+
return 0;
38+
}
39+
40+
void metal_sys_finish(void) {
41+
metal_bus_unregister(&metal_generic_bus);
42+
}
43+
44+
unsigned int sys_irq_save_disable(void) {
45+
return disable_irq();
46+
}
47+
48+
void sys_irq_restore_enable(unsigned int state) {
49+
enable_irq(state);
50+
}
51+
52+
void sys_irq_enable(unsigned int vector) {
53+
metal_unused(vector);
54+
}
55+
56+
void sys_irq_disable(unsigned int vector) {
57+
metal_unused(vector);
58+
}
59+
60+
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
61+
size_t size, unsigned int flags) {
62+
metal_unused(pa);
63+
metal_unused(size);
64+
metal_unused(flags);
65+
return va;
66+
}
67+
68+
void metal_machine_cache_flush(void *addr, unsigned int len) {
69+
SCB_CleanDCache_by_Addr((uint32_t *)addr, len);
70+
}
71+
72+
void metal_machine_cache_invalidate(void *addr, unsigned int len) {
73+
SCB_CleanInvalidateDCache_by_Addr((uint32_t *)addr, len);
74+
}

0 commit comments

Comments
 (0)