STM32H745 - Dual Core, ThreadX and Queues

Jason Gauthier 0 Reputation points
2023-04-03T13:03:31.6+00:00

First, I will say what I am trying to accomplish then my approach and finally my issue.

The STM32H745 MCPU is a dual core device. It has a Cortex-M7 and a Cortex-M4. I would like to use both cores for my project and I would like to be able to share data between them. It's important to note that the STM32H745 has 64KB of memory that can be accessed by both cores (This starts at address 0x38000000).

So, I thought using AzureRTOS' threadX queue implementaion may be a great way to send data between processors if I have the queue in shared memory. My initial attempt did not work and through debugging/reading the code I discovered that there is a linked list for "suspended threads" on a queue and that was pointed to a local (local to the processor) memory space.

So, I created a struct that resides in the shared memory space that has all the user-generated threads and queues in it.

This kind of works. However, I am having some very strange issues and I don't want to document them all here because I don't want to detract from the challenge.

So, I will now discuss one issue I am seeing and if I can solve it then I think the other issues may be solved as well.

Quick design overview. The user-code on the CM7 core generates 2 threads and 2 queues. The threads are a "main" thread that I am experimenting with queus the CM4 and the other thread is listening on a TCP port and handling network things for now. 2 queues are currently creates. One queue for the CM7 to "send" to the CM4 and one queue for the CM4 to "send" to the CM7.

The CM4 and CM7 boot at the same time and create their threads. The CM4 then "waits" on the queue for the CM7 to boot. When the CM7 has done it's booting it puts a single item in the queue. the CM4 picks up item and continues to it's main loop.

Then, in the main processing the CM4 will send a constant stream of data to the CM7 using a queue.

This works: kinda. Here's the issue.

As soon as I call the tx_queue_receive() function on the CM4 the CM4's timer/timer interrupt (something) goes completely out of wack.

Example: If I use the function with an infinite wait:

tx_queue_receive(cm7_to_cm4, &digit, TX_WAIT_FOREVER)

Any subsequent calls to tx_thread_sleep() hang indefinitely.

If I use the function without a wait:

while (tx_queue_receive(cm7_to_cm4, &digit, TX_NO_WAIT) != TX_SUCCESS);

And subsequent calls to tx_thread_sleep() return immediately.

I feel like I am incredibly close to accomplishing this, but something is not quite right. I'm hoping someone with some experience with the way this code works will be able to give me some insight into what could be happening.

Thank you!

Azure RTOS
Azure RTOS
An Azure embedded development suite including a small but powerful operating system for resource-constrained devices.
331 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Xiuwen Cai 366 Reputation points Microsoft Employee
    2023-04-10T08:16:21.2133333+00:00

    Hi @Jason Gauthier , it seems you are running two ThreadX instances on these two processors. But ThreadX queue is not designed to work between two ThreadX instances. My suggestion is to implement your own queues for sending messages between these two cores. For example, CM4 creates a semaphore and a thread, the thread waits on the semaphore and CM7 sends message by using shared memory and notify CM4 by interrupt. In the interrupt handler of the CM4, it releases the semaphore so that the thread can get the message.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.