Skip to content

Commit

Permalink
mcu/stm32: Add STM32G4 MCU files
Browse files Browse the repository at this point in the history
This adds support for STM32G4 MCU family.

Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
  • Loading branch information
kasjer committed Mar 5, 2024
1 parent a2ee892 commit a4e8b8c
Show file tree
Hide file tree
Showing 31 changed files with 3,182 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hw/bus/drivers/spi_stm32/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pkg.deps.MCU_STM32F4:
pkg.deps.MCU_STM32F7:
- hw/bus/drivers/spi_stm32/stm32f7xx

pkg.deps.MCU_STM32G4:
- hw/bus/drivers/spi_stm32/stm32g4xx

pkg.deps.MCU_STM32L0:
- hw/bus/drivers/spi_stm32/stm32l0xx

Expand Down
159 changes: 159 additions & 0 deletions hw/bus/drivers/spi_stm32/stm32g4xx/include/spidmacfg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include <stdint.h>
#include <stm32g4xx_hal_dma.h>

struct stm32_dma_cfg {
uint8_t dma_ch;
uint8_t irqn;
void (*irq_handler)(void);
DMA_Channel_TypeDef *regs;
DMA_InitTypeDef init;
};

#define SPI_DMA_RX_CHANNEL(dma, ch, spi_num) \
extern const struct stm32_dma_cfg DMA ## dma ## _channel ## ch ## _spi ## spi_num ## _rx;

#define SPI_DMA_TX_CHANNEL(dma, ch, spi_num) \
extern const struct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MA_TX_CHANNEL(2, 7, 4);
#endif
28 changes: 28 additions & 0 deletions hw/bus/drivers/spi_stm32/stm32g4xx/pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

pkg.name: hw/bus/drivers/spi_stm32/stm32g4xx
pkg.description: STM32G4 specific part of STM32 SPI driver
pkg.author: "Apache Mynewt <dev@mynewt.apache.org>"
pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:

pkg.deps:
- hw/bus
- hw/bus/drivers/spi_stm32
182 changes: 182 additions & 0 deletions hw/bus/drivers/spi_stm32/stm32g4xx/src/spidmacfg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include <spidmacfg.h>
#include <stm32g4xx_hal_dma.h>
#include <stm32_common/stm32_dma.h>

#define SPI_DMA_RX_CHANNEL_DEFINE(dma, ch, spi_num) \
const struct stm32_dma_cfg DMA ## dma ## _channel ## ch ## _spi ## spi_num ## _rx = { \
DMA ## dma ## _CH ## ch, \
DMA ## dma ## _Channel ## ch ## _IRQn, \
stm32_dma ## dma ## _ ## ch ## _irq_handler, \
.regs = DMA ## dma ## _Channel ## ch, \
.init = { \
.Request = DMA_REQUEST_SPI ## spi_num ## _RX, \
.Direction = DMA_PERIPH_TO_MEMORY, \
.PeriphInc = DMA_PINC_DISABLE, \
.MemInc = DMA_MINC_ENABLE, \
.PeriphDataAlignment = DMA_PDATAALIGN_BYTE, \
.MemDataAlignment = DMA_MDATAALIGN_BYTE, \
.Mode = DMA_NORMAL, \
.Priority = DMA_PRIORITY_LOW, \
} \
}

#define SPI_DMA_TX_CHANNEL_DEFINE(dma, ch, spi_num) \
const struct stm32_dma_cfg DMA ## dma ## _channel ## ch ## _spi ## spi_num ## _tx = { \
DMA ## dma ## _CH ## ch, \
DMA ## dma ## _Channel ## ch ## _IRQn, \
stm32_dma ## dma ## _ ## ch ## _irq_handler, \
.regs = DMA ## dma ## _Channel ## ch, \
.init = { \
.Request = DMA_REQUEST_SPI ## spi_num ## _TX, \
.Direction = DMA_MEMORY_TO_PERIPH, \
.PeriphInc = DMA_PINC_DISABLE, \
.MemInc = DMA_MINC_ENABLE, \
.PeriphDataAlignment = DMA_PDATAALIGN_BYTE, \
.MemDataAlignment = DMA_MDATAALIGN_BYTE, \
.Mode = DMA_NORMAL, \
.Priority = DMA_PRIORITY_LOW, \
} \
}

SPI_DMA_RX_CHANNEL_DEFINE(1, 1, 1);
SPI_DMA_RX_CHANNEL_DEFINE(1, 2, 1);
SPI_DMA_RX_CHANNEL_DEFINE(1, 3, 1);
SPI_DMA_RX_CHANNEL_DEFINE(1, 4, 1);
SPI_DMA_RX_CHANNEL_DEFINE(1, 5, 1);
SPI_DMA_RX_CHANNEL_DEFINE(1, 6, 1);
SPI_DMA_RX_CHANNEL_DEFINE(1, 7, 1);
SPI_DMA_RX_CHANNEL_DEFINE(2, 1, 1);
SPI_DMA_RX_CHANNEL_DEFINE(2, 2,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3);
SPI_DMA_RX_CHANNEL_DEFINE(2, 6, 3);
SPI_DMA_RX_CHANNEL_DEFINE(2, 7, 3);

#if defined(SPI4)
SPI_DMA_RX_CHANNEL_DEFINE(1, 1, 4);
SPI_DMA_RX_CHANNEL_DEFINE(1, 2, 4);
SPI_DMA_RX_CHANNEL_DEFINE(1, 3, 4);
SPI_DMA_RX_CHANNEL_DEFINE(1, 4, 4);
SPI_DMA_RX_CHANNEL_DEFINE(1, 5, 4);
SPI_DMA_RX_CHANNEL_DEFINE(1, 6, 4);
SPI_DMA_RX_CHANNEL_DEFINE(1, 7, 4);
SPI_DMA_RX_CHANNEL_DEFINE(2, 1, 4);
SPI_DMA_RX_CHANNEL_DEFINE(2, 2, 4);
SPI_DMA_RX_CHANNEL_DEFINE(2, 3, 4);
SPI_DMA_RX_CHANNEL_DEFINE(2, 4, 4);
SPI_DMA_RX_CHANNEL_DEFINE(2, 5, 4);
SPI_DMA_RX_CHANNEL_DEFINE(2, 6, 4);
SPI_DMA_RX_CHANNEL_DEFINE(2, 7, 4);
#endif

SPI_DMA_TX_CHANNEL_DEFINE(1, 1, 1);
SPI_DMA_TX_CHANNEL_DEFINE(1, 2, 1);
SPI_DMA_TX_CHANNEL_DEFINE(1, 3, 1);
SPI_DMA_TX_CHANNEL_DEFINE(1, 4, 1);
SPI_DMA_TX_CHANNEL_DEFINE(1, 5, 1);
SPI_DMA_TX_CHANNEL_DEFINE(1, 6, 1);
SPI_DMA_TX_CHANNEL_DEFINE(1, 7, 1);
SPI_DMA_TX_CHANNEL_DEFINE(2, 1, 1);
SPI_DMA_TX_CHANNEL_DEFINE(2, 2, 1);
SPI_DMA_TX_CHANNEL_DEFINE(2, 3, 1);
SPI_DMA_TX_CHANNEL_DEFINE(2, 4, 1);
SPI_DMA_TX_CHANNEL_DEFINE(2, 5, 1);
SPI_DMA_TX_CHANNEL_DEFINE(2, 6, 1);
SPI_DMA_TX_CHANNEL_DEFINE(2, 7, 1);

SPI_DMA_TX_CHANNE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A_TX_CHANNEL_DEFINE(1, 4, 4);
SPI_DMA_TX_CHANNEL_DEFINE(1, 5, 4);
SPI_DMA_TX_CHANNEL_DEFINE(1, 6, 4);
SPI_DMA_TX_CHANNEL_DEFINE(1, 7, 4);
SPI_DMA_TX_CHANNEL_DEFINE(2, 1, 4);
SPI_DMA_TX_CHANNEL_DEFINE(2, 2, 4);
SPI_DMA_TX_CHANNEL_DEFINE(2, 3, 4);
SPI_DMA_TX_CHANNEL_DEFINE(2, 4, 4);
SPI_DMA_TX_CHANNEL_DEFINE(2, 5, 4);
SPI_DMA_TX_CHANNEL_DEFINE(2, 6, 4);
SPI_DMA_TX_CHANNEL_DEFINE(2, 7, 4);
#endif
Loading

0 comments on commit a4e8b8c

Please sign in to comment.