Skip to content

Commit 88b9416

Browse files
committed
wip: c33
1 parent d2c73c4 commit 88b9416

File tree

18 files changed

+2929
-2863
lines changed

18 files changed

+2929
-2863
lines changed

boards.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ portentac33.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/
484484
portentac33.menu.mode.llext=llext
485485
portentac33.menu.mode.linked=linked
486486

487-
portentac33.menu.mode.linked.build.extra_extra_ldflags=-lc -lm -lgcc -L{build.variant.path}
487+
portentac33.menu.mode.linked.build.extra_extra_ldflags=-lc -lm -lgcc -L{build.variant.path} -Wl,--wrap=random -Wl,--wrap=calloc -Wl,--wrap=free -Wl,--wrap=malloc -Wl,--wrap=realloc
488488
portentac33.menu.mode.linked.build.llext_link_flags=
489489
portentac33.menu.mode.linked.build.suffix=_linked
490490
portentac33.menu.mode.linked.build.ldscript={runtime.platform.path}/variants/linked/linker_script.ld

cores/arduino/main.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include "Arduino.h"
8+
#include "zephyr/kernel.h"
89
#include <cstdint>
910
#ifdef CONFIG_LLEXT
1011
#include <zephyr/llext/symbol.h>
@@ -59,7 +60,7 @@ static void __libc_init_array (void)
5960
__init_array_start[i] ();
6061
}
6162

62-
extern "C" __attribute__((section(".entry_point"), used)) void entry_point(k_thread_stack_t* stack, size_t stack_size) {
63+
extern "C" __attribute__((section(".entry_point"), used)) void entry_point(struct k_heap* stack, size_t stack_size) {
6364
// copy .data in the right place
6465
// .bss should already be in the right place
6566
// call constructors
@@ -68,7 +69,15 @@ extern "C" __attribute__((section(".entry_point"), used)) void entry_point(k_thr
6869
extern uintptr_t _edata;
6970
extern uintptr_t _sbss;
7071
extern uintptr_t _ebss;
72+
extern uintptr_t __heap_start;
73+
extern uintptr_t __heap_end;
7174
//__asm volatile ("cpsie i");
75+
76+
const size_t alignment = 4096;
77+
printk("Heap end: %p\n", &__heap_end);
78+
printk("Heap start: %p\n", &__heap_start);
79+
// __heap_start = (__heap_start + (alignment - 1)) & ~(alignment - 1);
80+
7281
memcpy(&_sdata, &_sidata, &_edata - &_sdata);
7382
memset(&_sbss, 0, &_ebss - &_sbss);
7483
__libc_init_array();

cores/arduino/new.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,4 @@ void operator delete(void* ptr, void* place) noexcept {
132132
void operator delete[](void* ptr, void* place) noexcept {
133133
(void)ptr; (void)place; // unused
134134
// Nothing to do
135-
}
135+
}

extra/build.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,16 @@ fi
3333
# Generate the provides.ld file for linked builds
3434
echo "Exporting provides.ld"
3535
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep FUNC | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' > variants/$variant/provides.ld
36-
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep llext_stack | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' >> variants/$variant/provides.ld
37-
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep llext_stack | awk -F' ' '{print "PROVIDE(llext_stack_size = "$3");"}' >> variants/$variant/provides.ld
36+
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep kheap_llext_heap | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' >> variants/$variant/provides.ld
37+
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep kheap_llext_heap | awk -F' ' '{print "PROVIDE(kheap_llext_heap_size = "$3");"}' >> variants/$variant/provides.ld
38+
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep kheap__system_heap | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' >> variants/$variant/provides.ld
39+
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep kheap__system_heap | awk -F' ' '{print "PROVIDE(kheap__system_heap_size = "$3");"}' >> variants/$variant/provides.ld
3840
cat build/zephyr/zephyr.map | grep __device_dts_ord | grep -v rodata | grep -v llext_const_symbol | awk -F' ' '{print "PROVIDE("$2" = "$1");"}' >> variants/$variant/provides.ld
3941
TEXT_START=`cat loader/boards/$variant.overlay | grep user_sketch: | cut -f2 -d"@" | cut -f1 -d"{"`
4042
echo "PROVIDE(_sketch_start = 0x$TEXT_START);" >> variants/$variant/provides.ld
43+
44+
sed -i 's/PROVIDE(malloc =/PROVIDE(__wrap_malloc =/g' variants/$variant/provides.ld
45+
sed -i 's/PROVIDE(free =/PROVIDE(__wrap_free =/g' variants/$variant/provides.ld
46+
sed -i 's/PROVIDE(realloc =/PROVIDE(__wrap_realloc =/g' variants/$variant/provides.ld
47+
sed -i 's/PROVIDE(calloc =/PROVIDE(__wrap_calloc =/g' variants/$variant/provides.ld
48+
sed -i 's/PROVIDE(random =/PROVIDE(__wrap_random =/g' variants/$variant/provides.ld

libraries/SocketWrapper/SocketHelpers.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class NetworkInterface {
135135
return (ret == 0);
136136
}
137137

138+
bool disconnect() {
139+
return (net_if_down(net_if_get_by_index(iface_index)) == 0);
140+
}
141+
138142
// TODO: manual functions for setting IP address, subnet mask, gateway, etc.
139143
// net_if_ipv4_set_netmask_by_addr(iface, &addr4, &nm);
140144
// net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
@@ -148,6 +152,14 @@ class NetworkInterface {
148152
}
149153
}
150154

155+
bool begin(uint8_t* mac_address, int _timeout, int _response_timeout) {
156+
return begin();
157+
}
158+
159+
bool begin(uint8_t* mac_address, IPAddress _ip, IPAddress _dns, IPAddress _gateway, IPAddress _netmask, int _timeout, int _response_timeout) {
160+
return begin();
161+
}
162+
151163
EthernetHardwareStatus hardwareStatus() {
152164
const struct device *const dev = DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(ethernet_phy));
153165
if (device_is_ready(dev)) {

libraries/SocketWrapper/SocketWrapper.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ class ZephyrSocketWrapper {
117117
if (ca_certificate_pem != nullptr) {
118118
ret = tls_credential_add(CA_CERTIFICATE_TAG, TLS_CREDENTIAL_CA_CERTIFICATE,
119119
ca_certificate_pem, strlen(ca_certificate_pem) + 1);
120-
Serial.println(ret);
121120
}
122121

123122
sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TLS_1_2);

libraries/SocketWrapper/ZephyrClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma once
2+
13
#include "SocketWrapper.h"
24
#include "api/Client.h"
35
#include "unistd.h"

libraries/SocketWrapper/ZephyrSSLClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma once
2+
13
#include "SocketWrapper.h"
24
#include "api/Client.h"
35
#include "unistd.h"

loader/boards/arduino_portenta_c33.conf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ CONFIG_INIT_STACKS=y
4444

4545
CONFIG_NET_SOCKETS=y
4646
CONFIG_NET_SOCKETS_NET_MGMT=y
47-
#CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
47+
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
4848
CONFIG_NET_MGMT=y
4949
CONFIG_NET_MGMT_EVENT=y
5050
CONFIG_NET_L2_ETHERNET=y
@@ -58,11 +58,11 @@ CONFIG_NET_TCP=y
5858
CONFIG_NET_SOCKETS=y
5959
CONFIG_POSIX_API=y
6060

61-
#CONFIG_MBEDTLS=y
62-
#CONFIG_MBEDTLS_BUILTIN=y
63-
#CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT=y
64-
#CONFIG_MBEDTLS_ENABLE_HEAP=y
65-
#CONFIG_MBEDTLS_HEAP_SIZE=60000
66-
#CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=7168
67-
#CONFIG_MBEDTLS_HASH_ALL_ENABLED=y
68-
#CONFIG_MBEDTLS_CMAC=y
61+
CONFIG_MBEDTLS=y
62+
CONFIG_MBEDTLS_BUILTIN=y
63+
CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT=y
64+
CONFIG_MBEDTLS_ENABLE_HEAP=y
65+
CONFIG_MBEDTLS_HEAP_SIZE=60000
66+
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=7168
67+
CONFIG_MBEDTLS_HASH_ALL_ENABLED=y
68+
CONFIG_MBEDTLS_CMAC=y

loader/boards/arduino_portenta_c33.overlay

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272

7373
pwm-pin-gpios = <&ioport6 0 0>;
7474

75-
serials = <&cdc_acm_uart0>,<&uart9>;
76-
cdc-acm = <&cdc_acm_uart0>;
75+
serials = /*<&cdc_acm_uart0>,*/ <&uart9>;
76+
/* cdc-acm = <&cdc_acm_uart0>; */
7777
i2cs = <&iic1>;
7878
spis = <&spi1>;
7979
pwms = <&pwm6 1 PWM_HZ(25000000) PWM_POLARITY_NORMAL>;

0 commit comments

Comments
 (0)