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

BTT-Octopus with STM32H723? #68

Open
thaala opened this issue Nov 3, 2024 · 31 comments
Open

BTT-Octopus with STM32H723? #68

thaala opened this issue Nov 3, 2024 · 31 comments

Comments

@thaala
Copy link

thaala commented Nov 3, 2024

Hello all,

i have two boards here from BTT. Octopus V1.1 with H723 processor and a Kraken V1.0 with same processor.
Because Kraken has fixed TMC5160 drivers missing - it may be a problem to use it with remora. Octopus lacks currently support for H723 processor only. Pins of Octopus are same as for M466 processor variant. Could you please give a roadmap to bring remora to the H723 - Version?

Is it maybe only the timing (clocking) setup? In case of success i will contribute the source to your project.
Is there a progress by adding TMC5160 driver code?

Thank you in advance.

@cakeslob
Copy link
Contributor

cakeslob commented Nov 3, 2024

Fantastic, always looking for help, lets start with the H7
With the nucleo H723, i have it working up until SPI by bypassing the bootloader and SD card
Roadmap :

  • Bootloader : not loading properly with the SKR3, personally i consider this lower priority
  • SD card SDIO driver : not sure where this was left off but there have been more updates by jojo to the driver that we need to implement and test , can be tested without it but it will need it in the long run
  • SPI DMA : biggest hurdle at the moment, because without it, theres nothing for no one . something with the SPI DMA MUX or something

spi issue is the biggest problem, and I am finding it very hard to debug the H7

@cakeslob
Copy link
Contributor

cakeslob commented Nov 3, 2024

RE TMC5160
user Sean has been working his way through the TMC SPI as well as working on the SKR3, I think he has the initial work done offline, but I dont know how physical testing has gone. He has also done some work on H7 but I dont know how far he has gotten
here is a link to his fork
https://github.com/seanmccully/Remora

@thaala
Copy link
Author

thaala commented Nov 3, 2024

Fine..
nice to be welcome with it.
Need some setup time - a week or so.... ;-)

thank you for this fast response...

BR
thilo

@thaala
Copy link
Author

thaala commented Nov 11, 2024

Hi,
in meanwhile i'm ready with env setup and have running some test progs with cubeMXide. Seems that spi dma is working with testprog.
Now i m trying to use mbed as work- and debug-space but i am unable to setup remora6 workspace in mbed by a selection of custom target skrv3 or octopus446.
This is a miracle to me. i need a kick in the ...
"How to": A first step to select TARGET_SKRV3 as build target?

Btw. is there a double of ROBIN_E3 in the custom_targets.json? it looks like a typo...
Could you please give little advice to set build target to SKRV3?

BR Thilo

@cakeslob
Copy link
Contributor

hmm cant find my writeup, its in the issues page somewhere but ill do a quick one

  1. download repo
  2. open mbed studio
  3. under "file" then "open workspace"
  4. go to the remora repo, and select the folder for workspace "/Firmware/FirmwareSource/Remora-OS6"
  5. once it opens the workspace under that folder, in the lower menu under "Libraries" select Fix all"
  6. after it downloads the mbed lib, you can then select the target, and compile

mbed1

@cakeslob
Copy link
Contributor

The Robin e3 and the robin 3 are 2 different boards

@thaala
Copy link
Author

thaala commented Nov 12, 2024

Thank you - it works.
regarding e3 board - i know that but for e3 you have two different sections...

sorry not custom_targets - it was mbed_app.json

    "ROBIN_E3": {
        "platform.stdio-baud-rate": 115200,
        "target.stdio_uart_tx": "PA_9",
        "target.stdio_uart_rx": "PA_10",
        "target.features_add": ["STORAGE"],
        "target.components_add" : ["SD"]
    },
         "ROBIN_E3": {
        "target.mbed_app_start": "0x08005000",
        "platform.stdio-baud-rate": 115200,
        "target.stdio_uart_tx": "PA_9",
        "target.stdio_uart_rx": "PA_10",
        "target.features_add": ["STORAGE"],
        "sd.SPI_MOSI": "PB_15",
        "sd.SPI_MISO": "PB_14",
        "sd.SPI_CLK":  "PB_13",
        "sd.SPI_CS":   "PA_15",
        "target.components_add" : ["SD"]
    },
    "SKR_MINI_E3": {
        "target.mbed_app_start": "0x08007000",

@thaala
Copy link
Author

thaala commented Nov 12, 2024

Hello,

after playing around with mbed studio i am really confused about selecting custom targets. None of the custom boards appears. After correct the mbed_app.json by deleting first robin_e3 entry i have a success now.

After reopen mbed studio all custom tragets appeared..

BR
Thilo

@cakeslob
Copy link
Contributor

good eye, although it doesnt seem to cause me any issues with custom targets, with or without both entries. something incorrect in custom_targets.json would describe what you are experiencing

@scottalford75
Copy link
Owner

I've dug out my old work on the SKR3 and have it working upto SPI comms. DMA appears to be working but I'm getting the request header coming back for some reason.

Currently in SMT32cubIDE but the thought is to move this into PlatformIO as Cakeslob suggested. I'd appreciate any feedback on the SPI issues...

https://github.com/scottalford75/Remora-STM32H7xx/tree/main

@thaala
Copy link
Author

thaala commented Nov 18, 2024

Hi Scott,

just a first hint:
hspi1.Init.DataSize = SPI_DATASIZE_4BIT;
i guess it should be 8 bits..
Is NSS really Soft instead of Hard at SKR3 HW? i havent knowledge about this HW.

BR
Thilo

@scottalford75
Copy link
Owner

scottalford75 commented Nov 18, 2024 via email

@thaala
Copy link
Author

thaala commented Nov 20, 2024

Hi Scott,

actually i have some success with my Octopus-H723 SPI.
I am using the SPI-Bridge of stlinkv3 to send cyclic data to the board and this works.

I have tried some time to put it into same reciepe as F4 - Boards but it seems H7 have integrated dma and my tries to port are unsuccessful..
Therefore i let do the Cube - code genererator what STCube wants to generate and use this generated handles.
I put the code here as attachment.

additional the windows msdev testprog for sending SPI - data over stlink bridge

BR
Thilo
ConsoleApplication1.zip
STM32-H723.ZIP

@thaala
Copy link
Author

thaala commented Nov 21, 2024

Hi,

regarding the debugger fault i found a mem align fault while hal procedure HAL_SPI_TransmitReceive_DMA() checks not initialzied handle of RXDMA. i solved this in that way..


    HAL_DMA_Init(&this->hdma_spi_rx);
    
    __HAL_LINKDMA(&this->spiHandle,hdmarx,this->hdma_spi_rx);
    __HAL_LINKDMA(&this->spiHandle, hdmatx, this->hdma_spi_tx);

i second thing are this updated lines in start procedure:


SCB_CleanDCache_by_Addr((uint32_t*)(((uint32_t)this->ptrTxData->txBuffer) & ~(uint32_t)0x1F), SPI_BUFF_SIZE+32);
SCB_InvalidateDCache_by_Addr((uint32_t*)(((uint32_t)this->spiRxBuffer.rxBuffer) & ~(uint32_t)0x1F), SPI_BUFF_SIZE+32);
HAL_SPI_TransmitReceive_DMA(&this->spiHandle, (uint8_t *)this->ptrTxData->txBuffer, (uint8_t *)this->spiRxBuffer.rxBuffer, SPI_BUFF_SIZE);

....related to that link from ST:

and a last thing please:
because i have only a RPI5 here i need little advice about combined send/receive of spi host communication.
Should i send out 128 Bytes to shift out the rxbuffer/txbuffer to the host or split into recieve / transmit procedures? I can use only my stlink bridge SPI to emulate a Host here....

thank you in advance!

BR
Thilo

P.S. should we use scotts alternative github Remora-STM32H7xx for further discussions?

@scottalford75
Copy link
Owner

Hi Thilo,

I'm going to follow you lead and start a project from scratch in STM32CubeIDE rather than hacking around my 2 year old project. I found some posts on line saying there was some .ioc errors in older STM32H7xx projects.

Remora component is now available for the RPI5 as well. The data packet is 64 bytes.

BR
Scott

@thaala
Copy link
Author

thaala commented Nov 22, 2024

Hello cakeslob,

because having sd-card and spi now running with the cubeIDE on my octopus H723 here i want to try to port this to mbed.
I am facing two problems.

  1. mbed filesystem couldn't handle extfat like cubeIDE does. I fail to create an card which could be read by mbed filesystem. Is there a special (old) formatter? I am unable to create a sdcard havin 512 Bytes blocksize as mbed fs it want.

  2. debug environment for mbed. Whats your way to debug that custom board(s) with mbed (i have an stlinkv3 here....)! I found old posts for setup VSCode but this seems very complicated to me. it seems mbed was a dead horse before official eol announced.. if you`re use VSCode you may help me with some json-config files for VSCode debug setup?

thank you in advance

BR
Thilo

P.S.
I found scotts and your posts in Linuxcnc forum. I followed your advice and have burned an image to RPI 5. Whats the way to enable SPI for my Board? How to compile and load?

@scottalford75
Copy link
Owner

scottalford75 commented Nov 22, 2024 via email

@scottalford75
Copy link
Owner

Ok, some success. Started from scratch and built up each step to find where I made the errors. H743 SPI with DMA is running in circular mode and LinuxCNC comes out of estop.

Latest has been pushed to the repo

https://github.com/scottalford75/Remora-STM32H7xx

Next step is to get the process packet interrupt to work. The method used for the F4 killed the SPI totally.

@thaala
Copy link
Author

thaala commented Nov 23, 2024

Ohh - i am too late..

however. Nice to hear.
After visiting your code i could identify the main problem inside my code. (have had success only with complete - callback functions and let GPIO4 untouched...)

The GPIO4 interrupt pin needs to be initialized before all other stuff.
My code runs also after changing only that..

About the alignments:
good against hard faults but whats about local member in Remoracomms

rxData_t spiRxBuffer;

it should be aligned too...

pls. give ma a hint about mbed debugging - whats your mbed debbuging way?
BR
Thilo

@scottalford75
Copy link
Owner

scottalford75 commented Nov 23, 2024 via email

@scottalford75
Copy link
Owner

Threads are running but getting strange communication errors. LinuxCNC is happy, just the SKR3 side... Maybe cache cleaning not working correct.

The rxData_t is 32 byte aligned in the remora.h so all instances should be aligned to 32 byte boundaries.

@cakeslob
Copy link
Contributor

Hey thilo, i dont think you can debug the stm32H7 with debug inside mbed. you need to use something like you said with vscode, or something with visualGDB(?). the pyOCD used in mbed doesnt work with H7. if you can figure out how to replace the pyocd in mbed with a working one, it might work.

For the SDcard... i dont use anything special, just default windows stuff or whatever is on the RPi

@thaala
Copy link
Author

thaala commented Nov 24, 2024

Thank you both for your efforts.

@cakeslob I try to mount SD-Card/FATFilesystem stuff in mbed env. and getting return error code tells sector size beyond 512 Bytes are not supported - which is nowadays unusual. Searching internet tells also that exFAT is supported in FATFilesystem but not in mbed. However you say that FAT16 formatted cards (using blocksize of min 2048 bytes ) are working (on i. e. octopus 446) - I have to dig deeper in my adpoted configuration. Maybe it will be better using SKR3 - Software which scott are actually preparing.

Regarding Platfom IO: - This is frustrating me - Riding along the dead horse mbed ? Trying using Platform IO - but with custom BTT board ? My learning curve tear down dramatical if i have no examples to adopt like the configuration files in mbed. After deep digging into scotts code i understand what remora trys to do - i have also good knowledge about electronics - but my understanding of the mighty HAL is in a beginner state.

However - from the look of STM32 processors it seems the best using CubeIDE because lot of well functioning code can be generated and then adopted.
Whats about multitasking OS framework in Platform IO? I think creating custom boards and adopting OS maybe the open questions using Platform IO?

@scottalford75 - i want to help with H7 boards if in can - but i need little advice to setup a test scenario with my RPI 5 here. My stlinkv3 SPI-Bridge doesn't support combined Read/Write SPI operations. RPI 5 image is running with the "ready to start LinuxCNC" provided by cakeslob in Forum. Do you think the problem you have is SW or HW related?
For setup a test environment i need to know how to build/load linux Remora-SPI extension to that installation. Unfortunately i haven't RPI4 here an i dont want to buy one for this...
Btw. i am wondering about the endianess of the SPI-Headers. Preparing the SPI - Bridge buffer write command i need to send "tirw" istead of "writ" - is that intention or maybe H7 related?

BR
Thilo

@cakeslob
Copy link
Contributor

cakeslob commented Nov 24, 2024

Ive never done anything special, checking one of my sd cards, its running FAT(default) under windows, and formatted under FAT(default)

the library for the STM32 in platformIO is from cubeIDE, you can also import generated code. since most boards are pretty much the same, theres really only a few things that need be changed to support most boards. If the initial infrastructure is laid out before hand (like drew did with the w5500 remora PIO branch), even someone like me can add boards with relative ease, either using MX or just copying other firmware.

Hmm not sure how old that forum post would be, but heres a new quickstart guide just for you

  1. download one of these rpi5 images ( https://github.com/Expatria-Technologies/Flexi-Pi/releases ) or ( https://forum.linuxcnc.org/9-installing-linuxcnc/50653-comparison-between-raspian-12-bookworm-on-raspberry-pi-4-and-raspberry-pi-5?start=40#303752 ) right now im using elovalvos image, but will soon migrate to the flexi one and include it in the docs
  2. download this repo to the RPi5 ( https://github.com/scottalford75/Remora/tree/main )
  3. Open folder Remora/LinuxCNC/Components/ in terminal
  4. install the remora comp using this command sudo halcompile --install ./Remora-spi/remora-spi.c

@thaala
Copy link
Author

thaala commented Nov 25, 2024

Hello cakeslob,

i have followed your advice and as last step i have copied the Configsample octopus_xyz.
After correcting file remora_xyz.hal the line loadrt statement to:

loadrt remora-spi chip_type=STM=SPI_clk_div=32 i got this crash:

Debug file information:
Note: Using POSIX realtime
Unknown parameter `chip_type=STM'
./remora-xyz.hal:9: waitpid failed /usr/bin/rtapi_app remora-spi
./remora-xyz.hal:9: /usr/bin/rtapi_app exited without becoming ready
./remora-xyz.hal:9: insmod for remora-spi failed, returned -1 4118

after removing chip_type parameter LinuxCNC starts but i got two error message popups:

  1. RPi peripheral baseaddress: 0x00000010 size:0x7c000000
  2. Raspberry Pi 5, using RP1 driver

but i have no luck receivin SPI-Master data....
is it possibly because this is simulation only?

any farther advice?

BR
Thilo

@scottalford75
Copy link
Owner

Hi Thilo,

This post has the command line options for the RPi 5. Those messages are "normal" and show that the component has correctly configured itself for the RPi 5 and using the RP1 driver.

If you are using the standard SPI0 setup with default frequency then you just need

loadrt remora-spi

@scottalford75
Copy link
Owner

I should also mention that SPI mater transmission only occurs when bringing LinuxCNC out of estop.

@thaala
Copy link
Author

thaala commented Nov 25, 2024

OK
estop is set but it is nailed. Pushing it has no react. Machine on is greyed out..
Status tell: estop active - No tool

Whats about raspi gpio 25 state - How to handle it on octopus side?

BR
Thilo
P.S. what is your plan for updated code for SKR3? Do you get SD working?
I have seen that seanmccully have adopted SDMMC-Blockdriver from Arduino-Project - i wonder why...

@scottalford75
Copy link
Owner

I'd launch LinuxCNC from the command line and look for error messages in the terminal. Bad SPI comms will be reported.

Are you using your H723 firmware?

SKR3 code is progressing well. SD card is working along with the threads. The SD card driver needed the cache management enabled. I pushed my latest work to the H743 repo.

Currently working on getting the comms reliable. I've done a local fork to add the double buffers for DMA reception. It looks to have solved the corrupt headers I was seeing. Just need to get the buffer swapping logic sorted and robust.

To use the reset pin the Reset module is used.
{
"Thread": "Servo",
"Type": "Reset Pin",
"Comment": "Reset pin",
"Pin": "PC_4"
},

@thaala
Copy link
Author

thaala commented Nov 25, 2024

Hi Scott,

i haven't used mbed code - because of the SD card problem - i have stopped my work on it because if SKR3 is ready to use - my task will be much easier. A porting and testing to octopus 723 will be more uncomplicated if SKR3 is ready to use.
I thouht i try to fiddle out a SPI lifesign from Rasberry together with the CubeIDE test program but no success about estop.

You have "bad spi comms" reported is this maybe related to this conf in sample file?

(i found this in the sample hal-file - octopus_xyz.hal)

/# estop loopback, SPI comms enable and feedback
net user-enable-out <= iocontrol.0.user-enable-out => remora.SPI-enable
net user-request-enable <= iocontrol.0.user-request-enable => remora.SPI-reset
net remora-status <= remora.SPI-status => iocontrol.0.emc-enable-in
... but i couldn't identify some code in mbed software...

But your tip about cache maybe do the trick for SDIO....
I'll give it a try

BR
Thilo

@scottalford75
Copy link
Owner

scottalford75 commented Nov 26, 2024 via email

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

3 participants