micropython icon indicating copy to clipboard operation
micropython copied to clipboard

ports/stm32/boards: Add WEACT_STM32H743 board.

Open mattytrentini opened this issue 1 year ago • 8 comments

Adds a board definition for the WeAct Studio STM32H743 board.

mattytrentini avatar Sep 28 '23 06:09 mattytrentini

Note: Currently only the 8M QSPI flash is available. There is an additional 8M SPI flash that is currently unused by this board definition. I'm not sure how best to add both...

mattytrentini avatar Sep 28 '23 06:09 mattytrentini

Hi @mattytrentini, good to see this being added. I've been using this board and was not sure if it was derirable to submit it.

I've added some comments in your code. Additionally, you can look at my config below and files in the zip.

[WEACT_H743.zip](https://github.com/micropython/micropython/files/12796449/WEACT_H743.zip)

#define MICROPY_HW_BOARD_NAME       "WEACT_H743"
#define MICROPY_HW_MCU_NAME         "STM32H743"

... see zip for full file ...

// Servos
#define PYB_SERVO_NUM (4)

// Use external SPI flash for storage
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0)
#define MICROPY_HW_SPIFLASH_ENABLE_CACHE         (1)

// SPI Flash 64MBits
#define MICROPY_HW_SPIFLASH_SIZE_BITS (64 * 1024 * 1024)
#define MICROPY_HW_SPIFLASH_CS      (pin_D6)
#define MICROPY_HW_SPIFLASH_SCK     (pin_B3)
#define MICROPY_HW_SPIFLASH_MISO    (pin_B4)
#define MICROPY_HW_SPIFLASH_MOSI    (pin_D7)

// QSPI Flash 64MBits
#define MICROPY_HW_QSPIFLASH_SIZE_BITS   (64 * 1024 * 1024)
#define MICROPY_HW_QSPIFLASH_SIZE_BITS_LOG2 (26)
#define MICROPY_HW_QSPIFLASH_CS         (pin_B6)
#define MICROPY_HW_QSPIFLASH_SCK        (pin_B2)
#define MICROPY_HW_QSPIFLASH_IO0        (pin_D11)
#define MICROPY_HW_QSPIFLASH_IO1        (pin_D12)
#define MICROPY_HW_QSPIFLASH_IO2        (pin_E2)
#define MICROPY_HW_QSPIFLASH_IO3        (pin_D13)

#define MICROPY_HW_QSPI_PRESCALER       2

// block device config for SPI flash
extern const struct _mp_spiflash_config_t spiflash_config;
extern struct _spi_bdev_t spi_bdev;
#define MICROPY_HW_BDEV_IOCTL(op, arg) ( \
    (op) == BDEV_IOCTL_NUM_BLOCKS ? (MICROPY_HW_SPIFLASH_SIZE_BITS / 8 / FLASH_BLOCK_SIZE) : \
    (op) == BDEV_IOCTL_INIT ? spi_bdev_ioctl(&spi_bdev, (op), (uint32_t)&spiflash_config) : \
    spi_bdev_ioctl(&spi_bdev, (op), (arg)) \
)
#define MICROPY_HW_BDEV_READBLOCKS(dest, bl, n) spi_bdev_readblocks(&spi_bdev, (dest), (bl), (n))
#define MICROPY_HW_BDEV_WRITEBLOCKS(src, bl, n) spi_bdev_writeblocks(&spi_bdev, (src), (bl), (n))

extern const struct _mp_spiflash_config_t spiflash2_config;
extern struct _spi_bdev_t spi_bdev2;

#define MICROPY_BOARD_EARLY_INIT    board_early_init
void board_early_init(void);

JohnieBraaf avatar Oct 03 '23 19:10 JohnieBraaf

Thanks @JohnieBraaf! These additions look great, I just need to get my head around some of them and test them out. The CAN registers in particular are not familiar to me - and I'm not yet sure of the best clock domain configuration either. I'll try to find some time to spend with the reference manual this weekend!

mattytrentini avatar Oct 07 '23 00:10 mattytrentini

Good, yes I've spent some time in the datasheet as well figuring out those pins. Be sure to check the zip. You could test with that. Haven't build in couple months though, so it might need updates

JohnieBraaf avatar Oct 07 '23 06:10 JohnieBraaf

btw, here is the manufacturers version: https://github.com/WeActStudio/MiniSTM32H7xx/tree/master/SDK/openmv/Ports/micropython/boards/WeActStudioSTM32H7xx

JohnieBraaf avatar Jan 02 '24 23:01 JohnieBraaf

@mattytrentini Hi Mat. Thank you for the PR. I tried it today with a WEACT STM32H750 board, and it works. But, the PR needs a maintenance, since it does not compile any more. Two topics:

  • The oscillator values in strm32H7xx_hal_conf.h are not needed any more.
  • The defines for SDCARD_MMC have a conflict with the defines in mpconfigport_common.h

P.S.: I wonder why you included the networking support but did not define e.g. Ethernet pins, like these:

// Ethernet via RMII
#define MICROPY_HW_ETH_MDC          (pin_C1)
#define MICROPY_HW_ETH_MDIO         (pin_A2)
#define MICROPY_HW_ETH_RMII_REF_CLK (pin_A1)
#define MICROPY_HW_ETH_RMII_CRS_DV  (pin_A7)
#define MICROPY_HW_ETH_RMII_RXD0    (pin_C4)
#define MICROPY_HW_ETH_RMII_RXD1    (pin_C5)
#define MICROPY_HW_ETH_RMII_TX_EN   (pin_B11)
#define MICROPY_HW_ETH_RMII_TXD0    (pin_B12)
#define MICROPY_HW_ETH_RMII_TXD1    (pin_B13)

robert-hh avatar Feb 15 '24 10:02 robert-hh

@mattytrentini Hi Mat. Thank you for the PR. I tried it today with a WEACT STM32H750 board, and it works. But, the PR needs a maintenance, since it does not compile any more. Two topics:

* The oscillator values in strm32H7xx_hal_conf.h are not needed any more.

* The defines for SDCARD_MMC have a conflict with the defines in mpconfigport_common.h

Thanks @robert-hh, that'll help when I finally get a chance to return to this PR!

P.S.: I wonder why you included the networking support but did not define e.g. Ethernet pins, like these:

I should have; I was just collating various mpconfig files and must have removed the eth details. Will add them.

mattytrentini avatar Feb 15 '24 13:02 mattytrentini

Today I added a LAN8720 breakout board to my STM32H750 board and tested it using the changes in PR #13630. To get it working, I had to add a few lines to mpconfigboard. Without these, the clock frequency for the MDIO CLK signal was too high, 4.5MHz instead of 2 MHz. With that change, Ethernet works well. I did not check other devices like UART, SPI, etc. after that change.

// Bus clock divider values
#define MICROPY_HW_CLK_AHB_DIV          (RCC_HCLK_DIV2)
#define MICROPY_HW_CLK_APB1_DIV         (RCC_APB1_DIV2)
#define MICROPY_HW_CLK_APB2_DIV         (RCC_APB2_DIV2)
#define MICROPY_HW_CLK_APB3_DIV         (RCC_APB3_DIV2)
#define MICROPY_HW_CLK_APB4_DIV         (RCC_APB4_DIV2)

Edit: I use the H743 files for the H750. I ordered a H743, but it did not yet arrive.

robert-hh avatar Feb 17 '24 19:02 robert-hh

This is an automated heads-up that we've just merged a Pull Request that removes the STATIC macro from MicroPython's C API.

See https://github.com/micropython/micropython/pull/13763

A search suggests this PR might apply the STATIC macro to some C code. If it does, then next time you rebase the PR (or merge from master) then you should please replace all the STATIC keywords with static.

Although this is an automated message, feel free to @-reply to me directly if you have any questions about this.

projectgus avatar Mar 07 '24 23:03 projectgus

@mattytrentini are you still interested in updating this PR based on the above feedback?

dpgeorge avatar Aug 22 '24 01:08 dpgeorge

Yes, just lacking time right now. Will try to revisit it soon!

mattytrentini avatar Aug 22 '24 01:08 mattytrentini