Skip to content

Commit 4bc09e3

Browse files
committed
rpc: port to new architecture
1 parent 2418f41 commit 4bc09e3

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

src/rpc.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@
2424
#include "arduino_openamp.h"
2525
#include "stm32h7xx_hal.h"
2626
#include "ringbuffer.h"
27+
#include "stm32h7xx_ll_rcc.h"
28+
#include "debug.h"
2729

2830
/**************************************************************************************
2931
* TYPEDEF
3032
**************************************************************************************/
3133

3234
enum endpoints_t {
3335
ENDPOINT_RAW = 0,
34-
ENDPOINT_RESPONSE
36+
ENDPOINT_RPC
3537
};
3638

3739
/**************************************************************************************
@@ -48,50 +50,49 @@ extern ring_buffer_t virtual_uart_ring_buffer;
4850
int rpmsg_recv_raw_callback(struct rpmsg_endpoint *ept, void *data,
4951
size_t len, uint32_t src, void *priv)
5052
{
51-
/*
52-
printf("raw: received %d bytes from M4, content:", len);
53-
for (int i = 0; i<len; i++) {
54-
printf("%x ", ((uint8_t*)data)[i]);
55-
}
56-
printf("\n");
57-
*/
5853
ring_buffer_queue_arr(&virtual_uart_ring_buffer, (const char *)data, len);
5954

6055
return 0;
6156
}
6257

6358
void new_service_cb(struct rpmsg_device *rdev, const char *name, uint32_t dest)
6459
{
65-
if (strcmp(name, "raw") == 0) {
66-
OPENAMP_create_endpoint(&rp_endpoints[ENDPOINT_RAW], name, dest, rpmsg_recv_raw_callback, NULL);
67-
}
60+
uint8_t buffer[1] = {0};
61+
struct rpmsg_endpoint *ept = NULL;
62+
6863
if (strcmp(name, "rpc") == 0) {
69-
OPENAMP_create_endpoint(&rp_endpoints[ENDPOINT_RESPONSE], name, dest, rpmsg_recv_raw_callback, NULL);
64+
ept = &rp_endpoints[ENDPOINT_RPC];
65+
} else if (strcmp(name, "raw") == 0) {
66+
ept = &rp_endpoints[ENDPOINT_RAW];
67+
}
68+
69+
if (ept) {
70+
OPENAMP_create_endpoint(ept, name, dest, rpmsg_recv_raw_callback, NULL);
71+
OPENAMP_send(ept, buffer, sizeof(buffer));
7072
}
7173
}
7274

7375
int serial_rpc_begin() {
7476

7577
/* Initialize OpenAmp and libmetal libraries */
76-
if (MX_OPENAMP_Init(RPMSG_MASTER, new_service_cb) != HAL_OK) {
78+
if (MX_OPENAMP_Init(RPMSG_HOST, new_service_cb) != HAL_OK) {
7779
return 0;
7880
}
7981

8082
/* Initialize the rpmsg endpoint to set default addresses to RPMSG_ADDR_ANY */
81-
rpmsg_init_ept(&rp_endpoints[0], "raw", RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, NULL, NULL);
82-
rpmsg_init_ept(&rp_endpoints[1], "rpc", RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, NULL, NULL);
83+
memset(rp_endpoints, 0, sizeof(rp_endpoints));
8384

8485
/*
8586
* The rpmsg service is initiate by the remote processor, on H7 new_service_cb
8687
* callback is received on service creation. Wait for the callback
8788
*/
88-
OPENAMP_Wait_EndPointready(&rp_endpoints[0], HAL_GetTick() + 500);
89-
OPENAMP_Wait_EndPointready(&rp_endpoints[1], HAL_GetTick() + 500);
90-
91-
// Send first dummy message to enable the channel
92-
int message = 0x00;
93-
OPENAMP_send(&rp_endpoints[0], &message, sizeof(message));
94-
OPENAMP_send(&rp_endpoints[1], &message, sizeof(message));
89+
uint32_t millis_start = HAL_GetTick();
90+
while (rp_endpoints[0].rdev == NULL || rp_endpoints[1].rdev == NULL) {
91+
if ((HAL_GetTick() - millis_start) >= 1000) {
92+
dbg_printf("M4 RPC timeout\n");
93+
return 0;
94+
}
95+
}
9596

9697
return 1;
9798
}
@@ -102,7 +103,7 @@ void serial_rpc_available() {
102103

103104
void serial_rpc_write(uint8_t const * buf, size_t len) {
104105
// we'll only get rpc requests from "upstairs"
105-
OPENAMP_send(&rp_endpoints[1], buf, len);
106+
OPENAMP_send(&rp_endpoints[ENDPOINT_RPC], buf, len);
106107
}
107108

108109
void HSEM1_IRQHandler(void)

src/system.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,12 @@ static void MPU_Config(void)
162162
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
163163
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
164164
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
165-
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
165+
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
166166
MPU_InitStruct.Number = MPU_REGION_NUMBER3;
167-
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
167+
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
168168
MPU_InitStruct.SubRegionDisable = 0x00;
169169
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
170+
170171
HAL_MPU_ConfigRegion(&MPU_InitStruct);
171172

172173
/* Enable MPU */

0 commit comments

Comments
 (0)