Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32F4 SPI + ESP32_S3 FG communication issue #522

Open
3 tasks done
czagaadam opened this issue Oct 25, 2024 · 7 comments
Open
3 tasks done

STM32F4 SPI + ESP32_S3 FG communication issue #522

czagaadam opened this issue Oct 25, 2024 · 7 comments

Comments

@czagaadam
Copy link

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate.
  • Provided a clear description of your suggestion.
  • Included any relevant context or examples.

Issue or Suggestion Description

Can someone help how to proceed with STM32F4 SPI + ESP32_S3 FG firmware implementation?

Where I stuck:

I generated a normal STM32F4 (STM32F407VGTX) project with CubeIDE which includes:
SPI1, UART5, FREERTOS(CMSIS_V1), + CS, RESET, HANDSHAKE, DATA READY pins.

I followed the guide and put everything together in cube IDE.
I can compile the firmware but I think I missed something or do not understand something well.

So my main.c contains this:
image
I removed freertos.c file and I'm using the MX_FREERTOS_Init implementation from app_main.c

Running the application and putting a break point in MX_FREERTOS_Init in from app_main.c:
For me the value of transport_driver_event_handler looks strange:
image

Storing the event handler in transport_init in spi_drv.c
image

Continue running the application:
I'm getting an ESP-Hosted for ESP32-C2/C3/C6/S2/S3 message in CoolTerm, but error from ESP
E (144959) SPI_DRIVER: rx_pkt len+offset[131070]>max[1600], dropping it
and threads seems to be blocked
image

Modification:
I made a small modification in spi_drv.c I had to comment out these lines because application thinks STM32 is connected to a ESP32 instead of ESP32_S3:
image

If I uncomment them in CoolTerm I'm getting:
ESP-Hosted for ESP32 message instead of ESP-Hosted for ESP32-C2/C3/C6/S2/S3
and no error message from ESP, but I'm using ESP32_S3

Do I have to run any default task in MX_FREERTOS_Init in from app_main.c: ?
Why application thinks it is an ESP instead of ESP32_S3?
Why I'm getting this error: E (144959) SPI_DRIVER: rx_pkt len+offset[131070]>max[1600], dropping it

Thank you!

@mantriyogesh
Copy link
Collaborator

Did you use master code base or feature/esp_as_mcu_host branch?

@czagaadam
Copy link
Author

czagaadam commented Oct 25, 2024

Did you use master code base or feature/esp_as_mcu_host branch?

Do you mean in this esp-hosted repository ?
I'm using all of these files under esp_hosted_fg:
image
and calling MX_FREERTOS_Init from app_main.c in my main.c generated by CubeIDE

They are linked in my CubeIDE project:
image

For ESP I just pulled the esp-idf and did the export.ps1 stuffs...

@mantriyogesh
Copy link
Collaborator

can you hold up till 15 nov?

We are porting the https://github.com/espressif/esp-hosted/tree/feature/esp_as_mcu_host which is dedicated for mcu, by 15 nov.
this would be better experience and better integration for mcu like stm32 (we are trying to get specific stm32h7 ported for host, which could be referred for your stm mcu host)

to answer your original question, you shouldn't need to replace the file on your own. ideally the https://github.com/espressif/esp-hosted/blob/master/esp_hosted_fg/host/stm32/proj/prepare_project.bat should have done. but check the https://github.com/espressif/esp-hosted/blob/master/esp_hosted_fg/docs/MCU_based_host/Getting_started.md for all the details, how it should be used..

@czagaadam
Copy link
Author

hi,
that project seems impressive I'll take a look of that on 15th of nov but until that I don't want to give up.

I've used that bat file and I followed the guide, all the symbols,path and build variables are set.
If I call directly control_path_init(control_path_event_handler); it is listing the proper configuration.

image

I think the issue is somewhere with SPI communication:
E (25743) SPI_DRIVER: rx_pkt len+offset[131070]>max[1600], dropping it
It's like ESP throwing the SPI message because it's tool long or not compatible.
In STM side the SPI buffer size is set
#define MAX_SPI_BUFFER_SIZE 1600

Can you help what this error message is referring to exactly ?

@mantriyogesh
Copy link
Collaborator

Spi buffer size is expected to be 1600 bytes only, both the sides.

The log shows that the spi communication is not correct. Basically you can lower the frequency for spi and cross check if you have same spi mode in use.

If you are using jumper wires, ensure you use good, equal lengthed (<cm) wires.

The bytes interpreted are shifted bytes.

@czagaadam
Copy link
Author

Thanks for your support!
Sorry for late answering, a few days ago I was managed to make it work:
I regenerated the whole CubeIDE project and did again the whole ESP source compilation stuff and also the SPI frequnecy was lowered. It was working but it was very unstable because of the jumper cables and it was running on the lowest SPI clock.
image

So finally I soldered the necessary pins with good quality wires, with this the SPI speed can be increased.
esp_stm

My question now, how can I extend the STM firmware with my code ?
Should I use the following function:
stm_ret_t send_to_slave(uint8_t iface_type, uint8_t iface_num, uint8_t * wbuffer, uint16_t wlen) ?
It seems it's adding a interface_buffer_handle_t message to the to_slave_queue queue.
And should I call the send_to_slave in a new thread?

@mantriyogesh
Copy link
Collaborator

Hello @czagaadam , it looks like you are using master branch right now.

We are going to a friendly port, which we also plan to test on sample stm32 (h7), over MCU only branch, at https://github.com/espressif/esp-hosted/tree/feature/esp_as_mcu_host. Most probably by Mid November.

This change would have offer the easier port layer, with easy sample network stack integration.
Would it be worth for waiting in my opinion, but if you wish to still continue on master (which we plan to deprecated once the above port is available on above dedicated MCU branch), please let us know.

Finally, please I would like to add, all the efforts by now you have put are not totally waste. In fact, the changes and verification method would in fact would be helpful, suppliment and also comparable at some places. Please let us know what you think ahead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants