CubeMX: SPI4 + SDMMC1/FatFs + I2S6, audio BSP et debug VS Code (Linux)

Regeneration CubeMX (Appli) preparant le driver ST67W611M1 et la carte SD :
- SPI4 (PE12/13/14, CS PF8) + DMA GPDMA1 canaux 4/5, SPI_RDY (PD12/EXTI12),
  CHIP_EN (PD13) et BOOT (PD15) pour la X-NUCLEO-67W61M1 sur l'Arduino
- SDMMC1 + FatFs (appels d'init non generes dans main, IRQ SDMMC1 prio 14),
  PM14 en open-drain ; I2S6_CK sur PA5 pour liberer PC12 (SDMMC1_CK)
- HAL UART retire ; USE_BSP_COM_FEATURE=0
- Audio preserve : ADF 4/16/24, prio IRQ 2, DMA canal 0 en priorite haute,
  GPDMA1_Channel2_IRQHandler deplace dans audio_irq.c (hors fichiers generes),
  BSP_MX_I2S6_Init (renommage dans le BSP pour eviter le conflit avec CubeMX)
- Middlewares/ST/ST67W6X_Network_Driver, FatFs et sources HAL SPI/SD ajoutes
  (driver ST67 pas encore integre au build)

Build et debug sous Linux :
- gcc/toolchain-env.sh, gdbserver.sh, arm-gdb.sh : outils de STM32CubeIDE par
  glob ; flash.sh les retrouve ; ruby_compat.rb pour Ruby >= 3.2 (TouchGFX)
- makefile_appli : sources SD/SPI/FatFs/audio_irq ; chmod +x des .out TouchGFX
- Objets de build (*.o, *.d, *.su) retires de l'index (deja dans .gitignore)
- AGENTS.md : toolchain Linux, configs VS Code (cppdbg et ST stlinkgdbtarget),
  pieges de l'extension ST (.settings/ide.store.json, preRunCommands reset)

Verifie sur carte : audio OK, debug Appli/Boot OK.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
thomasandClaude Sonnet 5.5 committed 2026-10-23 22:49:06 +02:00
1 parent b119a6abd7
commit 66bb319423
1092 files changed
+172728 -133236

No files matched your search

@@ -0,0 +1,61 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file bsp_conf.h
* @author ST67 Application Team
* @brief This file contains definitions for the BSP interface
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef BSP_CONF_H
#define BSP_CONF_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/** Interfaces the SPI instance to be used for NCP communication */
#define NCP_SPI_HANDLE hspi4
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Global variables ----------------------------------------------------------*/
/** SPI handle */
extern SPI_HandleTypeDef NCP_SPI_HANDLE;
/* USER CODE BEGIN GV */
/* USER CODE END GV */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* BSP_CONF_H */
@@ -0,0 +1,53 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file logging_config.h
* @author ST67 Application Team
* @brief Header file for the W6X Logging configuration module
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef LOGGING_CONFIG_H
#define LOGGING_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes ------------------------------------------------------------------*/
#include "logging_levels.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported constants --------------------------------------------------------*/
/*
* All available configuration defines can be found in
* Middlewares\ST\ST67W6X_Network_Driver\Conf\logging_config_template.h
*/
/** Global verbosity level (LOG_NONE, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG) */
#define LOG_LEVEL LOG_DEBUG
/* USER CODE BEGIN EC */
/* USER CODE END EC */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* LOGGING_CONFIG_H */
@@ -0,0 +1,51 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file shell_config.h
* @author ST67 Application Team
* @brief Header file for the W6X Shell configuration module
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef SHELL_CONFIG_H
#define SHELL_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes ------------------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported constants --------------------------------------------------------*/
/*
* All available configuration defines can be found in
* Middlewares\ST\ST67W6X_Network_Driver\Conf\shell_config_template.h
*/
/** Enable the shell component */
#define SHELL_ENABLE 0
/* USER CODE BEGIN EC */
/* USER CODE END EC */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* SHELL_CONFIG_H */
@@ -0,0 +1,379 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file spi_port.c
* @author ST67 Application Team
* @brief SPI bus interface porting layer implementation
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/**
* This file is based on QCC74xSDK provided by Qualcomm.
* See https://git.codelinaro.org/clo/qcc7xx/QCCSDK-QCC74x for more information.
*
* Reference source: examples/stm32_spi_host/QCC743_SPI_HOST/Core/Src/spi_iface.c
*/
/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "bsp_conf.h"
#include "spi_port.h"
#include "logging.h"
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Global variables ----------------------------------------------------------*/
/* USER CODE BEGIN GV */
/* USER CODE END GV */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private defines -----------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macros ------------------------------------------------------------*/
/** SysTick Reload Value Register */
#define SYSTICK_LOAD ( * ( ( volatile uint32_t * ) 0xe000e014 ) )
/** SysTick Current Value Register */
#define SYSTICK_VALUE ( * ( ( volatile uint32_t * ) 0xe000e018 ) )
/**
* @brief Wait function to ensure a minimum wait time (in CPU cycles)
* @param _start_tick Tick value when the wait period started
* @param _nb_tick Number of ticks to wait
* @retval None
*/
#define WAIT_FROM(_start_tick, _nb_tick) do \
{\
int32_t _end_tick = (_start_tick) - (_nb_tick); \
if (_end_tick < 0) /* Wrap */ \
{ \
_end_tick += SYSTICK_LOAD; \
} \
while( SYSTICK_VALUE> _end_tick) {} \
}while(0)
/** Convert microseconds to ticks */
#define MICROSECOND_TO_TICK( _us ) ( (_us) * (SystemCoreClock>>20) )
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/** SPI transaction complete callback */
static spi_transaction_complete_t spi_port_transaction_complete_cb = NULL;
static const char spi_port_error_str[] = "SPI not initialized\n";
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Functions Definition ------------------------------------------------------*/
void *spi_port_memcpy(void *dest, const void *src, unsigned int len)
{
/* USER CODE BEGIN memcpy_1 */
/* USER CODE END memcpy_1 */
uint8_t *d = (uint8_t *)dest;
const uint8_t *s = (const uint8_t *)src;
/* Copy bytes until the destination address is aligned to 4 bytes */
while (((uint32_t) d % 4 != 0) && len > 0)
{
*d++ = *s++;
len--;
}
/* Copy 4-byte blocks */
uint32_t *d32 = (uint32_t *)d;
const uint32_t *s32 = (const uint32_t *)s;
while (len >= 4U)
{
*d32++ = *s32++;
len -= 4U;
}
/* Copy remaining bytes */
d = (uint8_t *)d32;
s = (const uint8_t *)s32;
while (len > 0U)
{
*d++ = *s++;
len--;
}
/* USER CODE BEGIN memcpy_2 */
/* USER CODE END memcpy_2 */
return dest;
/* USER CODE BEGIN memcpy_End */
/* USER CODE END memcpy_End */
}
int32_t spi_port_init(spi_transaction_complete_t transaction_complete_cb)
{
/* USER CODE BEGIN spi_port_init_1 */
/* USER CODE END spi_port_init_1 */
if (NCP_SPI_HANDLE.State == HAL_SPI_STATE_RESET)
{
LogError(spi_port_error_str);
return -1;
}
/* Powering up the NCP using GPIO CHIP_EN */
HAL_GPIO_WritePin(CHIP_EN_GPIO_Port, CHIP_EN_Pin, GPIO_PIN_SET);
if (transaction_complete_cb != NULL)
{
spi_port_transaction_complete_cb = transaction_complete_cb;
}
/* USER CODE BEGIN spi_port_init_2 */
/* USER CODE END spi_port_init_2 */
return 0;
/* USER CODE BEGIN spi_port_init_End */
/* USER CODE END spi_port_init_End */
}
int32_t spi_port_deinit(void)
{
/* USER CODE BEGIN spi_port_deinit_1 */
/* USER CODE END spi_port_deinit_1 */
/* Switch off the NCP using GPIO CHIP_EN */
HAL_GPIO_WritePin(CHIP_EN_GPIO_Port, CHIP_EN_Pin, GPIO_PIN_RESET);
spi_port_transaction_complete_cb = NULL;
/* USER CODE BEGIN spi_port_deinit_2 */
/* USER CODE END spi_port_deinit_2 */
return 0;
/* USER CODE BEGIN spi_port_deinit_End */
/* USER CODE END spi_port_deinit_End */
}
int32_t spi_port_transfer(void *tx_buf, void *rx_buf, uint16_t len, uint32_t timeout)
{
/* USER CODE BEGIN spi_port_transfer_1 */
/* USER CODE END spi_port_transfer_1 */
HAL_StatusTypeDef status;
if (NCP_SPI_HANDLE.State == HAL_SPI_STATE_RESET)
{
LogError(spi_port_error_str);
return -1;
}
#if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
SCB_CleanInvalidateDCache_by_Addr(rx_buf, len);
#endif /* __DCACHE_PRESENT */
/* Check whether host data is to be transmitted to the NCP, otherwise read only data from the NCP */
if (tx_buf != NULL)
{
#if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
SCB_CleanDCache_by_Addr(tx_buf, len);
#endif /* __DCACHE_PRESENT */
status = HAL_SPI_TransmitReceive(&NCP_SPI_HANDLE, tx_buf, rx_buf, len, timeout);
}
else
{
assert_param(len <= SPI_DMA_XFER_SIZE_THRESHOLD);
uint8_t tx_dummy[SPI_DMA_XFER_SIZE_THRESHOLD] = {0};
status = HAL_SPI_TransmitReceive(&NCP_SPI_HANDLE, tx_dummy, rx_buf, len, timeout);
}
/* USER CODE BEGIN spi_port_transfer_2 */
/* USER CODE END spi_port_transfer_2 */
return ((status == HAL_OK) ? 0 : -1);
/* USER CODE BEGIN spi_port_transfer_End */
/* USER CODE END spi_port_transfer_End */
}
int32_t spi_port_transfer_dma(void *tx_buf, void *rx_buf, uint16_t len)
{
/* USER CODE BEGIN spi_port_transfer_dma_1 */
/* USER CODE END spi_port_transfer_dma_1 */
HAL_StatusTypeDef status;
if (NCP_SPI_HANDLE.State == HAL_SPI_STATE_RESET)
{
LogError(spi_port_error_str);
return -1;
}
#if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
SCB_CleanInvalidateDCache_by_Addr(rx_buf, len);
#endif /* __DCACHE_PRESENT */
/* Check whether host data is to be transmitted to the NCP, otherwise read only data from the NCP */
if (tx_buf != NULL)
{
#if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
SCB_CleanDCache_by_Addr(tx_buf, len);
#endif /* __DCACHE_PRESENT */
/* USER CODE BEGIN spi_port_transfer_dma_trx */
status = HAL_SPI_TransmitReceive_DMA(&NCP_SPI_HANDLE, tx_buf, rx_buf, len);
/* USER CODE END spi_port_transfer_dma_trx */
}
else
{
/* USER CODE BEGIN spi_port_transfer_dma_rx */
status = HAL_SPI_Receive_DMA(&NCP_SPI_HANDLE, rx_buf, len);
/* USER CODE END spi_port_transfer_dma_rx */
}
/* USER CODE BEGIN spi_port_transfer_dma_2 */
/* USER CODE END spi_port_transfer_dma_2 */
return ((status == HAL_OK) ? 0 : -1);
/* USER CODE BEGIN spi_port_transfer_dma_End */
/* USER CODE END spi_port_transfer_dma_End */
}
int32_t spi_port_is_ready(void)
{
/* USER CODE BEGIN spi_port_is_ready_1 */
/* USER CODE END spi_port_is_ready_1 */
/* Check whether NCP data are available on the SPI bus */
return (int32_t)HAL_GPIO_ReadPin(SPI_RDY_GPIO_Port, SPI_RDY_Pin);
/* USER CODE BEGIN spi_port_is_ready_End */
/* USER CODE END spi_port_is_ready_End */
}
int32_t spi_port_set_cs(int32_t state)
{
static int32_t last_falling_tick;
/* USER CODE BEGIN spi_port_set_cs_1 */
/* USER CODE END spi_port_set_cs_1 */
if (state == 1)
{
WAIT_FROM(last_falling_tick, MICROSECOND_TO_TICK(2));
/* Activate Chip Select before starting transfer */
HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET);
}
else
{
/* Disable Chip Select when transfer is complete */
HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET);
last_falling_tick = SYSTICK_VALUE;
}
/* USER CODE BEGIN spi_port_set_cs_2 */
/* USER CODE END spi_port_set_cs_2 */
return 0;
/* USER CODE BEGIN spi_port_set_cs_End */
/* USER CODE END spi_port_set_cs_End */
}
/* USER CODE BEGIN FD */
/* USER CODE END FD */
/* Weak functions redefinition -----------------------------------------------*/
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
{
/* USER CODE BEGIN HAL_SPI_TxCpltCallback_1 */
/* USER CODE END HAL_SPI_TxCpltCallback_1 */
if (hspi == &NCP_SPI_HANDLE)
{
spi_port_transaction_complete_cb();
}
/* USER CODE BEGIN HAL_SPI_TxCpltCallback_End */
/* USER CODE END HAL_SPI_TxCpltCallback_End */
}
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
{
/* USER CODE BEGIN HAL_SPI_RxCpltCallback_1 */
/* USER CODE END HAL_SPI_RxCpltCallback_1 */
if (hspi == &NCP_SPI_HANDLE)
{
spi_port_transaction_complete_cb();
}
/* USER CODE BEGIN HAL_SPI_RxCpltCallback_End */
/* USER CODE END HAL_SPI_RxCpltCallback_End */
}
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
{
/* USER CODE BEGIN HAL_SPI_TxRxCpltCallback_1 */
/* USER CODE END HAL_SPI_TxRxCpltCallback_1 */
if (hspi == &NCP_SPI_HANDLE)
{
spi_port_transaction_complete_cb();
}
/* USER CODE BEGIN HAL_SPI_TxRxCpltCallback_End */
/* USER CODE END HAL_SPI_TxRxCpltCallback_End */
}
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi)
{
/* USER CODE BEGIN HAL_SPI_ErrorCallback_1 */
/* USER CODE END HAL_SPI_ErrorCallback_1 */
if (hspi == &NCP_SPI_HANDLE)
{
Error_Handler();
}
/* USER CODE BEGIN HAL_SPI_ErrorCallback_End */
/* USER CODE END HAL_SPI_ErrorCallback_End */
}
/* USER CODE BEGIN WFR */
/* USER CODE END WFR */
@@ -0,0 +1,75 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file w61_driver_config.h
* @author ST67 Application Team
* @brief Header file for the W61 configuration module
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef W61_DRIVER_CONFIG_H
#define W61_DRIVER_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes ------------------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported constants --------------------------------------------------------*/
/** ============================
* AT Wi-Fi
* All available configuration defines in
* Middlewares\ST\ST67W6X_Network_Driver\Driver\W61_at\w61_default_config.h
* ============================
*/
/** Maximum number of detected AP during the scan. Cannot be greater than 50 */
#define W61_WIFI_MAX_DETECTED_AP 20U
/** Enable/Disable Wi-Fi module logging */
#define WIFI_LOG_ENABLE 1
/** ============================
* AT Common
* All available configuration defines in
* Middlewares\ST\ST67W6X_Network_Driver\Driver\W61_at\w61_at_common.h
* ============================
*/
/** Maximum SPI buffer size */
#define W61_MAX_SPI_XFER 1520U
/** Enable/Disable System module logging */
#define SYS_LOG_ENABLE 1
/** Debugging only: Enable/Disable AT log, i.e. logs the AT commands incoming/outcoming from/to the NCP */
#define W61_AT_LOG_ENABLE 0
#include "logging.h"
/** Enable/Disable Modem command log */
#define MDM_CMD_LOG_ENABLE 0
/* USER CODE BEGIN EC */
/* USER CODE END EC */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* W61_DRIVER_CONFIG_H */
@@ -0,0 +1,81 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file w6x_config.h
* @author ST67 Application Team
* @brief Header file for the W6X configuration module
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef W6X_CONFIG_H
#define W6X_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes ------------------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported constants --------------------------------------------------------*/
/*
* All available configuration defines can be found in
* Middlewares\ST\ST67W6X_Network_Driver\Conf\w6x_config_template.h
*/
/** ============================
* System
*
* All available configuration defines in
* Middlewares\ST\ST67W6X_Network_Driver\Core\w6x_default_config.h
* ============================
*/
/** NCP power save mode : 0: NCP stays always active / 1: NCP goes in low power mode when idle */
#define W6X_POWER_SAVE_AUTO 1
/** NCP clock mode : 1: Internal RC oscillator, 2: External passive crystal, 3: External active crystal */
#define W6X_CLOCK_MODE 1U
/** ============================
* Wi-Fi
*
* All available configuration defines in
* Middlewares\ST\ST67W6X_Network_Driver\Core\w6x_default_config.h
* ============================
*/
/** Boolean to enable/disable autoconnect functionality */
#define W6X_WIFI_AUTOCONNECT 0
/** Define the region code, supported values : [CN, JP, US, EU, 00] */
#define W6X_WIFI_COUNTRY_CODE "EU"
/** Define if the country code will match AP's one.
* 0: match AP's country code,
* 1: static country code */
#define W6X_WIFI_ADAPTIVE_COUNTRY_CODE 0
/* USER CODE BEGIN EC */
/* USER CODE END EC */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* W6X_CONFIG_H */