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

ports/stm32/boards: Add WEACT_STM32H743 board. #12540

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mattytrentini
Copy link
Sponsor Contributor

Adds a board definition for the WeAct Studio STM32H743 board.

@mattytrentini
Copy link
Sponsor Contributor Author

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 mattytrentini force-pushed the add-weact-stm32h743-board branch 2 times, most recently from 690eb56 to 46103a3 Compare September 28, 2023 06:38
Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
@JohnieBraaf
Copy link
Contributor

JohnieBraaf commented Oct 3, 2023

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);

Copy link
Contributor

@JohnieBraaf JohnieBraaf left a comment

Choose a reason for hiding this comment

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

Added some comments

// https://community.st.com/t5/embedded-software-mcus/issue-with-bootloader-on-stm32h743-using-boot0-and-inline/td-p/73183

// CAN buses
#define MICROPY_HW_CAN1_TX (pin_B9)
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively:
#define FDCAN_FILTER_RANGE ((uint32_t)0x00000000U) /*!< Range filter from FilterID1 to FilterID2 /
#define FDCAN_FILTER_DUAL ((uint32_t)0x00000001U) /
!< Dual ID filter for FilterID1 or FilterID2 /
#define FDCAN_FILTER_MASK ((uint32_t)0x00000002U) /
!< Classic filter: FilterID1 = filter, FilterID2 = mask /
#define FDCAN_FILTER_RANGE_NO_EIDM ((uint32_t)0x00000003U) /
!< Range filter from FilterID1 to FilterID2, EIDM mask not applied */

// FDCAN bus
#define MICROPY_HW_CAN1_NAME "FDCAN1"
#define MICROPY_HW_CAN1_TX (pin_D1)
#define MICROPY_HW_CAN1_RX (pin_D0)

#define MICROPY_HW_CAN2_NAME "FDCAN2"
#define MICROPY_HW_CAN2_TX (pin_B13)
#define MICROPY_HW_CAN2_RX (pin_B12)

#define MICROPY_HW_CLK_PLLVCO (RCC_PLL1VCOWIDE)
#define MICROPY_HW_CLK_PLLFRAC (0)

#define MICROPY_HW_CLK_PLL3M (25)
Copy link
Contributor

Choose a reason for hiding this comment

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

I was using this, not sure which is better:
#define MICROPY_HW_CLK_PLL3M (5)
#define MICROPY_HW_CLK_PLL3N (48)


#define MICROPY_HW_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)

Copy link
Contributor

Choose a reason for hiding this comment

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

There are some extra pins that can be mapped
#define MICROPY_HW_UART3_TX (pin_B10)
#define MICROPY_HW_UART3_RX (pin_B11)

#define MICROPY_HW_UART4_TX (pin_C11)
#define MICROPY_HW_UART4_RX (pin_C10)

#define MICROPY_HW_UART5_TX (pin_B12) // or SPI2
#define MICROPY_HW_UART5_RX (pin_B13) // or SPI2

#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)

#define MICROPY_HW_UART7_TX (pin_E8)
#define MICROPY_HW_UART7_RX (pin_E7)

#define MICROPY_HW_SDCARD_D1 (pin_C9)
#define MICROPY_HW_SDCARD_D2 (pin_C10)
#define MICROPY_HW_SDCARD_D3 (pin_C11)

Copy link
Contributor

Choose a reason for hiding this comment

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

#define MICROPY_HW_SDCARD_DETECT_PIN (pin_D4)

#define MICROPY_HW_SDCARD_D3 (pin_C11)

// USB config
#define MICROPY_HW_USB_FS (1)
Copy link
Contributor

Choose a reason for hiding this comment

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

#define MICROPY_HW_USB_FS (1)

// LEDs
#define MICROPY_HW_LED1 (pin_E3) // blue

#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
// NOTE: LEDs are active high.
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRR = (pin->pin_mask << 16))
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRR = pin->pin_mask)

@mattytrentini
Copy link
Sponsor Contributor Author

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!

@JohnieBraaf
Copy link
Contributor

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

@@ -0,0 +1,115 @@
PA0,PA0
Copy link
Member

Choose a reason for hiding this comment

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

This should be A0,PA0 so the A0 matches the silk screen.

#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0)

// Clock config
#define MICROPY_HW_CLK_PLLM (5)
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment stating the frequency of the external HSE crystal (and if it's a crystal or an oscillator).

_micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS);
_micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);

/* Define output sections */
Copy link
Member

Choose a reason for hiding this comment

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

This section can go.

@JohnieBraaf
Copy link
Contributor

@robert-hh
Copy link
Contributor

robert-hh commented Feb 15, 2024

@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)

@mattytrentini
Copy link
Sponsor Contributor Author

@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.

@robert-hh
Copy link
Contributor

robert-hh commented Feb 17, 2024

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.

@projectgus
Copy link
Contributor

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 #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.

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

Successfully merging this pull request may close these issues.

None yet

6 participants