Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,41 @@ GenC0.menu.upload_method.OpenOCDDapLink.upload.tool=openocd_upload
GenC0.menu.upload_method.OpenOCDDapLink.debug.server.openocd.scripts.0=interface/cmsis-dap.cfg
GenC0.menu.upload_method.OpenOCDDapLink.debug.server.openocd.scripts.1={runtime.platform.path}/debugger/select_swd.cfg

################################################################################
# Seeed XIAO STM32C5

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It should be better to add a more generic menu name, like Seeed Studio or something like that and select the board in the pnum menu (default if first or only one). I guess that some script will fail if no pnum item.

Moreover you add only one menu when you select it with only one option for the USB.

No Serial support?
What about optimization? debug information? C Runtime Library?

XIAO_STM32C5.name=Seeed XIAO STM32C5

XIAO_STM32C5.build.core=arduino
XIAO_STM32C5.build.board=XIAO_STM32C5
XIAO_STM32C5.build.variant=STM32C5xx/C593C(E-G)(T-U)_C5A3CG(T-U)
XIAO_STM32C5.build.variant_h=variant_XIAO_STM32C5.h
XIAO_STM32C5.build.ldscript=ldscript_XIAO_STM32C5.ld
XIAO_STM32C5.build.st_extra_flags=-D{build.product_line} -DHSE_VALUE=48000000U -DUSBD_SELF_POWERED=1 -DUSBD_MAX_POWER=50 {build.enable_usb} {build.xSerial}
XIAO_STM32C5.build.mcu=cortex-m33
XIAO_STM32C5.build.fpu=-mfpu=fpv5-sp-d16
XIAO_STM32C5.build.float-abi=-mfloat-abi=hard
XIAO_STM32C5.build.series=STM32C5xx
XIAO_STM32C5.build.product_line=STM32C5A3xx
XIAO_STM32C5.build.hal=-DUSE_HALV2_DRIVER
XIAO_STM32C5.build.flash_offset=0x8000
XIAO_STM32C5.upload.maximum_size=1015808
XIAO_STM32C5.upload.maximum_data_size=262144
XIAO_STM32C5.upload.tool=uf2upload
XIAO_STM32C5.upload.protocol=serial
XIAO_STM32C5.upload.uf2.volume=XIAOC5BOOT
XIAO_STM32C5.upload.uf2.address=0x08008000
XIAO_STM32C5.upload.uf2.family=0x00C5C5C5
XIAO_STM32C5.upload.uf2.timeout=10000
XIAO_STM32C5.debug.svd_file={runtime.tools.STM32_SVD.path}/svd/STM32C5xx/STM32C5A3.svd
XIAO_STM32C5.vid.0=0x2886
XIAO_STM32C5.pid.0=0x80C5

# USB CDC is the user-facing default. The temporary None option permits
# non-USB phase-1 validation until C5 HAL v2 USB support is implemented.
XIAO_STM32C5.menu.usb.CDC=CDC (Serial)
XIAO_STM32C5.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
XIAO_STM32C5.menu.usb.none=None

################################################################################
# Generic C5
GenC5.name=Generic STM32C5 series
Expand Down
6 changes: 3 additions & 3 deletions libraries/SPI/src/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

SPIClass SPI;

void SPIClass::configSpi(const SPISettings &settings)
void SPIClass::configSpi(const SPISettings &settings, bool force)
{
if (_spiSettings != settings) {
if (force || _spiSettings != settings) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting.
It seems we introduce a regression when the ArduinoCore-API was released.
Thanks for pointing this. I will provide a fix for this. I don't think adding a new arguments is the better way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you file an issue for this, please?

_spiSettings = settings;

uint32_t clock = settings.getClockFreq();
Expand Down Expand Up @@ -79,7 +79,7 @@ void SPIClass::begin(SPIBusMode busMode)
SPI_MODE0,
busMode
);
configSpi(defaultSettings);
configSpi(defaultSettings, true);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/SPI/src/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class SPIClass : public HardwareSPI {
/* Current SPISettings */
SPISettings _spiSettings = SPISettings();

void configSpi(const SPISettings &settings);
void configSpi(const SPISettings &settings, bool force = false);
};

extern SPIClass SPI;
Expand Down
47 changes: 46 additions & 1 deletion libraries/SPI/src/utility/spi_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
extern "C" {
#endif

#if defined(USE_HALV2_DRIVER)
/* HAL v2 polling APIs use HAL_GetTick() for their timeout. On the current
* Arduino C5 clock path that tick is not guaranteed to advance while polling,
* so use the Arduino microsecond clock to bound LL polling instead. */
static bool spi_transfer_timed_out(uint32_t start_us)
{
return (SPI_TRANSFER_TIMEOUT != HAL_MAX_DELAY)
&& ((uint32_t)(micros() - start_us) >= (SPI_TRANSFER_TIMEOUT * 1000UL));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

micros() uses HAL_GetTick() so wonder if your statement is correct?

uint32_t m0 = HAL_GetTick();

}
#endif

/* Private Functions */
/**
* @brief return clock freq of an SPI instance
Expand Down Expand Up @@ -564,13 +575,22 @@ spi_status_e spi_transfer(spi_t *obj, const uint8_t *tx_buffer, uint8_t *rx_buff
{
spi_status_e ret = SPI_OK;
uint32_t tickstart, size = len;
#if defined(USE_HALV2_DRIVER)
uint32_t start_us;
#endif
if (obj == NULL || obj->spi == NP) {
return SPI_ERROR;
}
SPI_TypeDef *_SPI = obj->spi;
uint8_t *tx_buf = (uint8_t *)tx_buffer;

if (len == 0) {
ret = SPI_ERROR;
} else {
tickstart = HAL_GetTick();
#if defined(USE_HALV2_DRIVER)
start_us = micros();
#endif

#if defined(SPI_CR2_TSIZE)
/* Start transfer */
Expand All @@ -581,14 +601,32 @@ spi_status_e spi_transfer(spi_t *obj, const uint8_t *tx_buffer, uint8_t *rx_buff

while (size--) {
#if defined(SPI_SR_TXP)
#if defined(USE_HALV2_DRIVER)
while (!LL_SPI_IsActiveFlag_TXP(_SPI)) {
if (spi_transfer_timed_out(start_us)) {
ret = SPI_TIMEOUT;
goto spi_transfer_end;
}
}
#else
while (!LL_SPI_IsActiveFlag_TXP(_SPI));
#endif
Comment on lines +601 to +610

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you think it is required why not add it for all ? and replace direct HAL_GetTick usage.
As your function call micros() which call HAL_GetTick(), I did not see any advantage or I do not really understand.

#else
while (!LL_SPI_IsActiveFlag_TXE(_SPI));
#endif
LL_SPI_TransmitData8(_SPI, tx_buf ? *tx_buf++ : 0XFF);

#if defined(SPI_SR_RXP)
#if defined(USE_HALV2_DRIVER)
while (!LL_SPI_IsActiveFlag_RXP(_SPI)) {
if (spi_transfer_timed_out(start_us)) {
ret = SPI_TIMEOUT;
goto spi_transfer_end;
}
}
#else
while (!LL_SPI_IsActiveFlag_RXP(_SPI));
Comment on lines +617 to 625

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here.

#endif
#else
while (!LL_SPI_IsActiveFlag_RXNE(_SPI));
#endif
Expand All @@ -598,17 +636,24 @@ spi_status_e spi_transfer(spi_t *obj, const uint8_t *tx_buffer, uint8_t *rx_buff
LL_SPI_ReceiveData8(_SPI);
}
if ((SPI_TRANSFER_TIMEOUT != HAL_MAX_DELAY) &&
#if defined(USE_HALV2_DRIVER)
(spi_transfer_timed_out(start_us))) {
#else
(HAL_GetTick() - tickstart >= SPI_TRANSFER_TIMEOUT)) {
#endif
ret = SPI_TIMEOUT;
break;
}
}

#if defined(SPI_IFCR_EOTC)
spi_transfer_end:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think there is a trap here. For future HALV2 series based. If SPI_IFCR_EOTC is not defined goto will not reach it.

// Add a delay before disabling SPI otherwise last-bit/last-clock may be truncated
// See https://github.com/stm32duino/Arduino_Core_STM32/issues/1294
// Computed delay is half SPI clock
delayMicroseconds(obj->disable_delay);
if (ret == SPI_OK) {
delayMicroseconds(obj->disable_delay);
}

/* Close transfer */
/* Clear flags */
Expand Down
18 changes: 18 additions & 0 deletions libraries/SrcWrapper/src/stm32/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,14 @@ void uart_deinit(serial_t *obj)
#endif
#if defined(USART6_BASE)
case UART6_INDEX:
#if defined(USE_HALV2_DRIVER)
HAL_RCC_USART6_Reset();
HAL_RCC_USART6_DisableClock();
#else
__HAL_RCC_USART6_FORCE_RESET();
__HAL_RCC_USART6_RELEASE_RESET();
__HAL_RCC_USART6_CLK_DISABLE();
#endif
break;
#endif
#if defined(LPUART1_BASE)
Expand Down Expand Up @@ -725,9 +730,14 @@ void uart_deinit(serial_t *obj)
#endif
#if defined(UART7_BASE)
case UART7_INDEX:
#if defined(USE_HALV2_DRIVER)
HAL_RCC_UART7_Reset();
HAL_RCC_UART7_DisableClock();
#else
__HAL_RCC_UART7_FORCE_RESET();
__HAL_RCC_UART7_RELEASE_RESET();
__HAL_RCC_UART7_CLK_DISABLE();
#endif
break;
#elif defined(USART7_BASE)
case UART7_INDEX:
Expand Down Expand Up @@ -1460,7 +1470,11 @@ void UART5_IRQHandler(void)
#if defined(USART6_BASE) && !defined(STM32F0xx) && !defined(STM32G0xx)
void USART6_IRQHandler(void)
{
#if defined(USE_HALV2_DRIVER)
HAL_CORTEX_NVIC_ClearPendingIRQ(USART6_IRQn);
#else
HAL_NVIC_ClearPendingIRQ(USART6_IRQn);
#endif
HAL_UART_IRQHandler(uart_handlers[UART6_INDEX]);
}
#endif
Expand Down Expand Up @@ -1490,7 +1504,11 @@ void LPUART1_IRQHandler(void)
#if defined(UART7_BASE)
void UART7_IRQHandler(void)
{
#if defined(USE_HALV2_DRIVER)
HAL_CORTEX_NVIC_ClearPendingIRQ(UART7_IRQn);
#else
HAL_NVIC_ClearPendingIRQ(UART7_IRQn);
#endif
HAL_UART_IRQHandler(uart_handlers[UART7_INDEX]);
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions libraries/USBDevice/inc/usbd_cdc_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ uint8_t CDC_getStopBits(void);
uint8_t CDC_getParity(void);
uint8_t CDC_getDataBits(void);

/* Optional board hook invoked after the host changes the CDC line coding. */
void CDC_LineCodingChanged(uint32_t bitrate);

#ifdef __cplusplus
}
#endif
Expand Down
12 changes: 11 additions & 1 deletion libraries/USBDevice/inc/usbd_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ extern "C" {
#include "stm32_def.h"

#if defined(USE_HALV2_DRIVER)
#error "USB library is not yet compatible with HALv2 driver."
#if !defined(STM32C5xx)
#error "USB library is not yet compatible with this HALv2 driver."
#endif

/* STM32C5 uses the HAL v2 USB DRD FS PCD. Keep the legacy USB name and
* PMA buffer-kind names available to the common endpoint configuration. */
#define USB USB_DRD_FS
#define PCD_SNG_BUF HAL_PCD_SNG_BUF
#define PCD_DBL_BUF HAL_PCD_DBL_BUF
Comment on lines +39 to +41

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be better to add it in the stm32_def.h, other series also redefine some USB definition.

/* STM32G0xx, STM32U0xx and some STM32U5xx defined USB_DRD_FS */
#if !defined(USB) && defined(USB_DRD_FS)
#define USB USB_DRD_FS
#define PinMap_USB PinMap_USB_DRD_FS
#if defined(STM32H5xx) || defined(STM32U0xx) ||\
defined(STM32U3xx) || defined(STM32U5xx)
#define USB_BASE USB_DRD_BASE
#if !defined(__HAL_RCC_USB_CLK_ENABLE)
#if defined(__HAL_RCC_USB_FS_CLK_ENABLE)
#define __HAL_RCC_USB_CLK_ENABLE __HAL_RCC_USB_FS_CLK_ENABLE
#define __HAL_RCC_USB_CLK_DISABLE __HAL_RCC_USB_FS_CLK_DISABLE
#endif
#if defined(__HAL_RCC_USB1_CLK_ENABLE)
#define __HAL_RCC_USB_CLK_ENABLE __HAL_RCC_USB1_CLK_ENABLE
#define __HAL_RCC_USB_CLK_DISABLE __HAL_RCC_USB1_CLK_DISABLE
#endif
#endif
#endif
#endif

USB_BASE should also be defined.

#define USB_IRQn USB_DRD_FS_IRQn
#define USB_IRQHandler USB_DRD_FS_IRQHandler
Comment on lines +42 to +43

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When USB_BASE defined simply add STM32C5xx in the list:

#elif defined(STM32C0xx) || defined(STM32H5xx) || defined(STM32U0xx)

#else
#if !defined(USB_BASE) && !defined(USB_OTG_DEVICE_BASE)
#error "This board does not support USB! Select 'None' in the 'Tools->USB interface' menu"
Expand Down
13 changes: 12 additions & 1 deletion libraries/USBDevice/inc/usbd_ep_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,21 @@ typedef struct {

#ifdef USBD_USE_CDC
#define PMA_CDC_OUT_BASE (PMA_EP0_IN_ADDR + USB_MAX_EP0_SIZE)
#if defined(STM32C5xx)
/*
* The C5 USB DRD FS peripheral is used with bulk double buffering disabled.
* Keep each CDC endpoint in its own 64-byte PMA area; in particular, the
* interrupt IN endpoint must not overlap the bulk IN data buffer.
*/
#define PMA_CDC_OUT_ADDR PMA_CDC_OUT_BASE
#define PMA_CDC_IN_ADDR (PMA_CDC_OUT_BASE + USB_FS_MAX_PACKET_SIZE)
#define PMA_CDC_CMD_ADDR (PMA_CDC_IN_ADDR + USB_FS_MAX_PACKET_SIZE)
#else
#define PMA_CDC_OUT_ADDR ((PMA_CDC_OUT_BASE + USB_FS_MAX_PACKET_SIZE) | \
(PMA_CDC_OUT_BASE << 16U))
#define PMA_CDC_IN_ADDR (PMA_CDC_OUT_BASE + USB_FS_MAX_PACKET_SIZE * 2)
#define PMA_CDC_CMD_ADDR (PMA_CDC_IN_ADDR + CDC_CMD_PACKET_SIZE)
#endif
#endif /* USBD_USE_CDC */
#ifdef USBD_USE_HID_COMPOSITE
#define PMA_MOUSE_IN_ADDR (PMA_EP0_IN_ADDR + HID_MOUSE_EPIN_SIZE)
Expand All @@ -86,4 +97,4 @@ extern const ep_desc_t ep_def[DEV_NUM_EP + 1];
#endif /* USBCON */
#endif /* __USBD_EP_CONF_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
5 changes: 5 additions & 0 deletions libraries/USBDevice/src/cdc/cdc_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ uint8_t *CDC_TransmitQueue_ReadBlock(CDC_TransmitQueue_TypeDef *queue,
} else {
*size = CDC_TRANSMIT_QUEUE_BUFFER_SIZE - queue->read;
}

/* Limit the queued transaction to one endpoint packet. */
if (*size > CDC_QUEUE_MAX_PACKET_SIZE) {
*size = CDC_QUEUE_MAX_PACKET_SIZE;
}
queue->reserved = *size;
return &queue->buffer[queue->read];
}
Expand Down
12 changes: 11 additions & 1 deletion libraries/USBDevice/src/cdc/usbd_cdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,11 @@ static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
{
USBD_CDC_HandleTypeDef *hcdc;
#if defined(USE_HALV2_DRIVER)
hal_pcd_handle_t *hpcd = (hal_pcd_handle_t *)pdev->pData;
#else
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef *)pdev->pData;
#endif

if (pdev->pClassDataCmsit[pdev->classId] == NULL) {
return (uint8_t)USBD_FAIL;
Expand All @@ -710,7 +714,13 @@ static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];

if ((pdev->ep_in[epnum & 0xFU].total_length > 0U) &&
((pdev->ep_in[epnum & 0xFU].total_length % hpcd->IN_ep[epnum & 0xFU].maxpacket) == 0U)) {
((pdev->ep_in[epnum & 0xFU].total_length %
#if defined(USE_HALV2_DRIVER)
hpcd->in_ep[epnum & 0xFU].max_packet
#else
hpcd->IN_ep[epnum & 0xFU].maxpacket
#endif
) == 0U)) {
/* Update the packet total length */
pdev->ep_in[epnum & 0xFU].total_length = 0U;

Expand Down
8 changes: 7 additions & 1 deletion libraries/USBDevice/src/cdc/usbd_cdc_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ USBD_CDC_LineCodingTypeDef linecoding = {
0x08 /* nb. of bits 8*/
};

/* Boards that need a CDC line-coding side effect can override this hook. */
WEAK void CDC_LineCodingChanged(uint32_t bitrate)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK. Seems new nice feature.

{
(void)bitrate;
}

/* Private functions ---------------------------------------------------------*/

/**
Expand Down Expand Up @@ -175,6 +181,7 @@ static int8_t USBD_CDC_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
linecoding.format = pbuf[4];
linecoding.paritytype = pbuf[5];
linecoding.datatype = pbuf[6];
CDC_LineCodingChanged(linecoding.bitrate);
break;

case CDC_GET_LINE_CODING:
Expand Down Expand Up @@ -406,4 +413,3 @@ uint8_t CDC_getDataBits(void)
#endif /* USBD_USE_CDC */
#endif /* USBCON */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

5 changes: 2 additions & 3 deletions libraries/USBDevice/src/usbd_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
******************************************************************************
*/
#ifdef USBCON
#if defined(USBCON) && !defined(USE_HALV2_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "usbd_core.h"
#include "usbd_if.h"
Expand Down Expand Up @@ -718,6 +718,5 @@ void USBD_LL_Delay(uint32_t Delay)
HAL_Delay(Delay);
}
#endif /* HAL_PCD_MODULE_ENABLED */
#endif /* USBCON */
#endif /* USBCON && !USE_HALV2_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Loading
Loading