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

Add port for Analog Devices MAX32 MCUs #2708

Merged
merged 31 commits into from
Aug 19, 2024
Merged

Conversation

BrentK-ADI
Copy link
Contributor

Describe the PR
Add support for the Analog Devices MCUs MAX32650/1/2, MAX32665/6, MAX32690 and MAX78002.

Additional context
The USB IP for these devices is identical amongst the part families and uses a variation of the Mentor IP core. dcd_musb.c was used as the baseline implementation, modified for the part specific FIFO, register access and PHY control.

Supported Boards:

  • MAX32650EVKIT
  • MAX32650FTHR
  • MAX32651EVKIT
  • MAX32666EVKIT
  • MAX32666FTHR
  • MAX32690EVKIT
  • AD-APARD32690-SL
  • MAX78002EVKIT

Initial commit for the port of TUSB to MAX32xxx parts, staring with MAX32690
 - Added dcd_max32.c (based on dcd_musb.c) for interfacing with the peripheral
 - Added MAX32690 part family support
 - Added max32690evkit board support
 - Updated examples for unique EP number requirement
 - Updated get_deps.py to fetch the MSDK

Known Issues / Additional Testing Required
 - msc_dual_lun only shown 1 volume on Windows
 - USBTMC does not have a valid Windowsdriver
 - DFU does not have a valid Windows driver
 - WebUSB is "Device not Recognized"
 - Need to test build scripts with IAR and Clang
 - Added BSP for AD-APARD32690-SL board (apard32690)
 - Ran clang-formatting on previously committed code
 - Removed LOG messages from dcd_max32.c
 -Added support for MAX78002, MAX78002EVKIT
 -Added provisions for remaining MAX32 USB parts
Updated MAX32690 and MAX78002 linker and cmake scripts to work with CMake + Ninja build system.  Verified all example projects build with the tools/build.py script for both board, and both make and cmake build systems.
Added support for the MAX32666, Boards MAX32666EvKit and MAX32666FTHR.
Added support for the MAX32650/1/2 series parts
 - MAX32650FTHR, MAX32650EvKit, MAX32651EvKit
 - Added special flash rule for MAX32651 due to signing required
 - Added depencies to flash-msdk rules for executable
 - Added MSDK flash rules for CMake
 - Removed partial IAR support. Uniform GCC support across MAX32 parts
 - Updated build scripts for correctly signing the MAX32651
 - Added README files for the BSPs to describe flashing and limitiations
Correct a case-sensitive file extension issue in the MAX32690 build scripts.  Did not present itself as an issue under MinGW or MSYS, just Linux.
Resolve codespell and EOF errors found in the pre-commit CI task.
@hathach
Copy link
Owner

hathach commented Jul 12, 2024

thank you for your PR, I think we should update the dcd_musb.c to support max32 instead of duplicating an new driver. Since that make maintanence easier in the future. I can help with that, give me a bit of time, I will try to find an dev board to test this out.

PS: digikey backorder is 09/20, this probably take a while.

@BrentK-ADI
Copy link
Contributor Author

Thanks @hathach. As part of that potential merging of the existing dcd_msub.c with my updates, should probably also look at the sunxi version as well. The scope of modifications for that were similar to mine.

Unfortunate about the back order. Once you get hardware reach out if you have any questions or issues getting up and running.

@hathach
Copy link
Owner

hathach commented Jul 12, 2024

Thanks @hathach. As part of that potential merging of the existing dcd_msub.c with my updates, should probably also look at the sunxi version as well. The scope of modifications for that were similar to mine.

Unfortunate about the back order. Once you get hardware reach out if you have any questions or issues getting up and running.

yeah, sunxi uses the same mentor usb, but it is more complicated since it is actually arm9 processor. I want to do that also but couldn't mannage the time.

For dev board, this one look reasonable https://www.digikey.com/en/products/detail/analog-devices-inc-maxim-integrated/MAX32666FTHR/12727215 (lead time is 09/02), will let you know once I got the hardware.

@BrentK-ADI
Copy link
Contributor Author

For dev board, this one look reasonable https://www.digikey.com/en/products/detail/analog-devices-inc-maxim-integrated/MAX32666FTHR/12727215 (lead time is 09/02), will let you know once I got the hardware.

Yes, that board will work out well for testing. The MAX32650FTHR is also a good choice for a small form factor board, but same 9/20 lead time at Digikey.

@hathach
Copy link
Owner

hathach commented Jul 12, 2024

Feather 666 is a bigger chip with dual core but cost less than 650 and also available earlier so it is better choice I guess.

@hathach
Copy link
Owner

hathach commented Jul 20, 2024

Updated: requested by @tannewt, I did a bit more search and found mouser having these in stocks, just ordered max32650,666,690 boards (sponsored by Adafruit). It will probaly take a week or so for it to get delivery. Meanwhile @BrentK-ADI If possible, you can try to merge the dcd_max32 to dcd_musb, probably create an header musb_max32.h and abstract/put max32 specific function there. you could check out dwc2 for reference. We will try to get this merge as soon as I could.

@BrentK-ADI
Copy link
Contributor Author

@hathach , I'll start digging into that merge. Hopefully can get something together by the end of the week.

Combined the new MAX32 MUSB implementation with the existing (TI) implementation to provide generic code base for working the MUSB DCD peripheral.
 - Added abstraction calls for FIFO setup, EP registers, Ctrl registers and interrupt setup.
 - Combined TM4C and MSP432E into a single header file.
 - Created musb_max32.h, and removed the MAX32 specific C implementation.
 - Updated MAX32 build system to use dcd_musb.c.
 - Added MAX32 conditions for cdc_dual_ports example descriptors missed during first testing.
@BrentK-ADI
Copy link
Contributor Author

@hathach, I took a shot at combining the existing DCD MUSB with the new MAX32. Things were a little trickier than the dwc2 example, for a couple reasons:

  • The EP registers are the same packing/data types, but accessed differently between TI and MAX32. TI has a contiguous memory map where each EP register set follows the previous. MAX32 uses a shared memory space and an index to determine which EP is being accessed
  • The FIFOs on the TI parts need to be configured, where as the MAX32 has dedicated memory for each EP.

With that said, as well as a couple other hooks for interrupt handling, I think the implementation is fairly clean and easy to follow, and retained all of the original dcd_musb.c logic and register handling. Let me know your thoughts.

I happened to have a EK-TM4C123GXL board hanging around so was able to at least re-run the example projects on that board to verify functionality was consistent with the updates.

@hathach
Copy link
Owner

hathach commented Jul 25, 2024

@BrentK-ADI perfect thank you, my order from Mouser already shipped, it will probably delivery in a few days. Let hope we could get this merged as soon as we could.

@BrentK-ADI
Copy link
Contributor Author

For some reason my codespell didn't catch that error when I ran pre-commit. I'll hold off fixing it if there are other updates needed for this merge to avoid a frivolous entry in the commit log.

@hathach
Copy link
Owner

hathach commented Aug 4, 2024

For some reason my codespell didn't catch that error when I ran pre-commit. I'll hold off fixing it if there are other updates needed for this merge to avoid a frivolous entry in the commit log.

no problems, my order is in custom clearance, it should be delivered in a couple of days.

@hathach
Copy link
Owner

hathach commented Aug 9, 2024

I got the feather dev boards, will start to test/review and make changes if needed to merge this PR asap. If you have an pending update, please push it if possible to prevent conflict/merge thanks.

@hathach hathach added Porting Adding new mcu/board/os support Prio Urgent labels Aug 14, 2024
@hathach
Copy link
Owner

hathach commented Aug 14, 2024

I have bring this PR updated to master, add max32 to ci build and fixes some warning when compiling with cmsis header v3 (in the mcu/max32). Will do more extensive test with actual hw tomorrow.

@hathach
Copy link
Owner

hathach commented Aug 15, 2024

Tested with feather maax32866, it works as a charm, passed my local hil test with both TI tm4c and max32666, I am doing a bit of more refactor, but probably wont change the driver behavior. We probably merge this real soon (hopefully). Note: since I have both max32650 and 666, I will add one to the hil pool as well to get it tested with the ci.

@BrentK-ADI
Copy link
Contributor Author

Glad things worked smoothly. Thanks for putting the time into this!

Comment on lines +88 to +92
// CXD56 USB driver has fixed endpoint type (bulk/interrupt/iso) and direction (IN/OUT) by its number
// 0 control (IN/OUT), 1 Bulk (IN), 2 Bulk (OUT), 3 In (IN), 4 Bulk (IN), 5 Bulk (OUT), 6 In (IN)
// #define EPNUM_AUDIO_IN 0x01
// #define EPNUM_AUDIO_OUT 0x02
// #define EPNUM_AUDIO_INT 0x03

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
@hathach
Copy link
Owner

hathach commented Aug 17, 2024

@BrentK-ADI Everything went smoothly, I push more refactor to generalize register interfacee. I also tried to include max32650 to my hardware-in-the-loop pool #2194 which is running on a Raspberry Pi 5 (flashing hardware and run test script to verify usb function). Therefore I tried to compile openocd (analog fork) https://github.com/analogdevicesinc/openocd but got following error on my Linux x86.

/usr/bin/ld: src/.libs/libopenocd.a(adi_v6_jtag.o):/home/hathach/code/openocd_analog/src/target/adi_v6_jtag.c:181: multiple definition of dap_cmd_pool'; src/.libs/libopenocd.a(adi_v5_jtag.o):/home/hathach/code/openocd_analog/src/target/adi_v5_jtag.c:151: first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:3111: src/openocd] Error 1
make[2]: Leaving directory '/home/hathach/code/openocd_analog'
make[1]: *** [Makefile:4468: all-recursive] Error 1
make[1]: Leaving directory '/home/hathach/code/openocd_analog'
make: *** [Makefile:2100: all] Error 2

here is my configure (mostly default)

./configure --disable-werro
OpenOCD configuration summary
--------------------------------------------------
MPSSE mode of FTDI based devices        yes (auto)
ST-Link Programmer                      yes (auto)
Analog Devices ICE-1000                 yes (auto)
Analog Devices ICE-2000                 yes (auto)
Analog Devices Debug Agent              yes (auto)
TI ICDI JTAG Programmer                 yes (auto)
Keil ULINK JTAG Programmer              yes (auto)
Altera USB-Blaster II Compatible        yes (auto)
Bitbang mode of FT232R based devices    yes (auto)
Versaloon-Link JTAG Programmer          yes (auto)
TI XDS110 Debug Probe                   yes (auto)
OSBDM (JTAG only) Programmer            yes (auto)
eStick/opendous JTAG Programmer         yes (auto)
Andes JTAG Programmer                   yes (auto)
USBProg JTAG Programmer                 no
Raisonance RLink JTAG Programmer        no
Olimex ARM-JTAG-EW Programmer           no
CMSIS-DAP Compliant Debugger            yes (auto)
Cypress KitProg Programmer              yes (auto)
Altera USB-Blaster Compatible           no
ASIX Presto Adapter                     no
OpenJTAG Adapter                        no
Linux GPIO bitbang through libgpiod     no
SEGGER J-Link Programmer                yes (auto)

Maybe I miss something, would you mind poiting me to instruction to compile ADI's openocd for to run on a RPI 5. Thank you.

@BrentK-ADI
Copy link
Contributor Author

@hathach As far as I know that is the right repo. I believe it should be the release branch vs adi-main or master. I was able to build that branch with the normal OpenOCD instructions:

To build OpenOCD, use the following sequence of commands:

  ./bootstrap (when building from the git repository)
  ./configure [options]
  make
  sudo make install

If that's still causing you problems, I'll ping the group that maintains the tools for these MCUs on Monday and get more guidance.

@hathach
Copy link
Owner

hathach commented Aug 18, 2024

@BrentK-ADI thank you, I change the branch to release and it compiles perfectly. I was on the default adi-main previousls. Shouldd have tried that first, not too familliar with Analog tool (have been using jlink so far for developing) :)

add feather max32666 to the hil pool
…pture example with iso kind of work but not smoothly. audio example does not seems to work as expected
@hathach
Copy link
Owner

hathach commented Aug 19, 2024

I am able to add feather max32666 to the hil pool. Somehow, someway, I fried my feather max32650 while trying to flash with openocd, no 3v3 measured,power with lipo battery does not work as well (it has been doing just fine with jlink). Luckily I still have an extra max32690 ekit (though it is a bit trunky).

Copy link
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you very much for your awesome work. PR works out the box with max32650/666/690 at first try. I have done quite a bit of refactoring mostly with dcd musb (hcd isn't touched yet) with

  • declare general musb register
  • add musb configuraation option MUSB_CFG_SHARED_FIFO/MUSB_CFG_DYNAMIC_FIFO which is the main difference between adi and ti implementation
  • indexed tx/rx register to make the code look cleaner
  • implement dcd_edpt_iso_alloc()/activate() for TI port, which makes it simpler without fifo size allocation management.
  • enable double buffer for ISO

most bulkd/interrupt examples work well. ISO though isn't working too well audio_test does not work as expected, video_capture (with CFG_TUD_VIDEO_STREAMING_BULK=0 for using ISO) only work as proof of concept (kind of laggy), which shouldn't be the caase with max32 with huge fifo depth. But it is probably our bug. We will fix this later with following up PR since this is already large enough.

@hathach hathach merged commit ca3925a into hathach:master Aug 19, 2024
82 checks passed
@BrentK-ADI
Copy link
Contributor Author

Thanks so much for pushing this through so fast!

@hathach
Copy link
Owner

hathach commented Aug 19, 2024

No problem, I am the one to say thank. Thanks again for your contribution on the PR. There is still work for ISO endpoint, but we can do that later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Porting Adding new mcu/board/os support Prio Urgent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants