Skip to content

Commit

Permalink
feat!: update DmaStm to support new dma peripherals in G0, G4 and WB …
Browse files Browse the repository at this point in the history
…devices (#169)

* chore: added .cache folder to gitignore

* chore: added vscode settings for compileCommands and clangd

* chore: removed peripheral address from StreamBase

* refactor: changed DmaStm to support stream and channel based dma peripherals

* chore: fixed DmaStm typos

* refactor: reworked DmaStm configuration lists for channel based dma peripherals

* feat: added default clock config for g474 nucleo

* refactor: reworkedexamples to match supported nucleo boards and added helloworld example

* feat: added g474 linker script

* build: added stm32g474 cmake configuration

* chore: added stm32wb55 stlink-remote debug target

* build: removed 144pin configuration from helloworld targets

* refactor: cleaned up NucleoUi.hpp

* refactor: removed old dma implementation

* refactor: removed old default dma configurations

* chore: removed obsolete comment

* chore: moved code to correct location in header

* refactor: separated template definitions and implementations

* refactor: removed incorrect include

* removed DacStm

* fixed AnalogToDigitalPinStm to work with G4 devices

* Fixed using incorrect register flag to determine FIFO/RX status

* Reworked UartStmDuplexDma

- properly handles ReceiveTimeoutInterrupt when DMA has wrapped around back to the beginning
- removed code duplication

* Added IsInterruptPending to DmaStm

* fixed incorrect uartRts/uartCts initialization

* chore: fixed missing cmakepresets build entries

* chore: removed unused includes

* chore: refactored UartStmDma to remove duplication

* chore: remove duplication from UartStmDuplexDma

* chore: updated formatting

* chore: revert invalid comparison change

* chore: added noexcept to DmaStm::Stream::move-ctor

* feat: updated intialization of dma based peripherals, moved Uart*::Config to a detail namespace to workaround a default-ctor issue

* chore: cat CMakePresets.json

* chore: remove cat CMakePresets.json

* chore: update CMakePresets.json

* chore: resolved comments

* feat: add SetPierpheralTransferSize to all DMA streams

* fix: fixed SpiDataSizeConfiguratorStm not using the provided dataSize when activating the configuration

* fix: fxed incorrect ISR flag check to determine if the uart fifo is empty

* feat: added setting peripheral transfer size when changing the datasize for SpimasterStmDma periperhals

* Fixed issue with ReceivedSize

* feat: refactored DmaStm to remove all instances of CRTP and simplified all interfaces/inheritance trees

* chore: updated EchoFromCloud with new Dma structure

* chore: changed 1000ms to 1ms

* hal_stl/stm32fxxx/UartStm: remove hwFlowControl from Config

* hal_st/stm32fxxx: Rename DefalutClockNucleoG474RET to DefaultClockNucleoG474RE

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* hal_st/stm32fxxx/QuadSpiStmDma: rename transceiveStreamBase to transceiveStream

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* hal_st/instantiations/NucleoUi: Move UARTs to helloworld example

---------

Co-authored-by: Richard Peters <richard@rpeters.org>
Co-authored-by: Richard Peters <richard.peters@philips.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Feb 21, 2024
1 parent eb44953 commit d62e03e
Show file tree
Hide file tree
Showing 34 changed files with 7,819 additions and 640 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.cache
.vs/
.vscode/.cortex-debug*
build/
Expand Down
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@
"type": "cortex-debug",
"servertype": "jlink",
"device": "STM32G070RB"
},
{
"name": "stm32wb55rg",
"cwd": "${workspaceFolder}",
"executable": "${command:cmake.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"device": "STM32WB55RG",
"servertype": "external",
"runToEntryPoint": "main",
"showDevDebugOutput": "both",
"gdbTarget": "host.docker.internal:61234",
"overrideLaunchCommands": [
"monitor reset",
"-target-download",
"monitor reset"
],
"overrideRestartCommands": [
"monitor reset"
]
}
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cmake.copyCompileCommands": "${workspaceFolder}/build/compile_commands.json",
"sonarlint.pathToCompileCommands": "${workspaceFolder}/build/compile_commands.json",
"clangd.arguments": ["--query-driver=/**/arm-none-eabi-*"],
"C_Cpp.autoAddFileAssociations": false
}
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (HALST_STANDALONE)
FetchContent_Declare(
emil
GIT_REPOSITORY https://github.com/philips-software/amp-embedded-infra-lib.git
GIT_TAG 419f636bd76f2c0ee2f7524ca548e724bf479e27 # unreleased
GIT_TAG 16dde0b5e8a10acae790e00e1cbb75e891f5925f # unreleased
)

FetchContent_MakeAvailable(emil)
Expand Down
15 changes: 14 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"binaryDir": "${sourceDir}/build/${presetName}",
"installDir": "${sourceDir}/install",
"cacheVariables": {
"HALST_BUILD_EXAMPLES": true
"HALST_BUILD_EXAMPLES": true,
"CMAKE_EXPORT_COMPILE_COMMANDS": "On"
}
},
{
Expand Down Expand Up @@ -134,6 +135,18 @@
"HALST_BUILD_EXAMPLES_FREERTOS": true,
"FREERTOS_CONFIG_FILE_DIRECTORY": "${sourceDir}/examples/freertos/config"
}
},
{
"name": "stm32g474",
"displayName": "stm32g474",
"description": "Build for stm32g474",
"inherits": "stm32",
"toolchainFile": "${sourceDir}/build/${presetName}/_deps/emil-src/cmake/toolchain-arm-gcc-m4-fpv4-sp-d16.cmake",
"cacheVariables": {
"TARGET_CORTEX": "m4",
"TARGET_MCU_FAMILY": "stm32g4xx",
"TARGET_MCU": "stm32g474"
}
}
],
"buildPresets": [
Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(blink)
add_subdirectory(freertos)
add_subdirectory(helloworld)
17 changes: 14 additions & 3 deletions examples/blink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
add_executable(hal_st.blink_nucleo144 Main.cpp)
emil_build_for(hal_st.blink_nucleo144 TARGET_MCU_VENDOR st PREREQUISITE_BOOL HALST_BUILD_EXAMPLES)
emil_build_for(hal_st.blink_nucleo144
TARGET_MCU stm32f429
TARGET_MCU stm32f746
TARGET_MCU stm32f767
PREREQUISITE_BOOL HALST_BUILD_EXAMPLES
)

target_compile_definitions(hal_st.blink_nucleo144 PUBLIC
NUCLEO=Nucleo144Ui
Expand All @@ -18,10 +23,16 @@ emil_generate_artifacts(TARGET hal_st.blink_nucleo144 LST MAP BIN HEX)
######################################################################

add_executable(hal_st.blink_nucleo64 Main.cpp)
emil_build_for(hal_st.blink_nucleo64 TARGET_MCU_VENDOR st PREREQUISITE_BOOL HALST_BUILD_EXAMPLES)
emil_build_for(hal_st.blink_nucleo64
TARGET_MCU stm32g431
TARGET_MCU stm32g474
TARGET_MCU stm32wb55
PREREQUISITE_BOOL HALST_BUILD_EXAMPLES
)

target_compile_definitions(hal_st.blink_nucleo64 PUBLIC
NUCLEO=Nucleo64Ui
$<$<NOT:$<STREQUAL:${TARGET_MCU},stm32wb55>>:NUCLEO=Nucleo64Ui>
$<$<STREQUAL:${TARGET_MCU},stm32wb55>:NUCLEO=Nucleo64WBUi>
)

target_link_libraries(hal_st.blink_nucleo64 PRIVATE
Expand Down
21 changes: 21 additions & 0 deletions examples/helloworld/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
add_executable(hal_st.helloworld_nucleo64 Main.cpp)
emil_build_for(hal_st.helloworld_nucleo64
TARGET_MCU stm32g474
TARGET_MCU stm32wb55
PREREQUISITE_BOOL HALST_BUILD_EXAMPLES
)

target_compile_definitions(hal_st.helloworld_nucleo64 PUBLIC
$<$<NOT:$<STREQUAL:${TARGET_MCU},stm32wb55>>:NUCLEO=Nucleo64Ui>
$<$<STREQUAL:${TARGET_MCU},stm32wb55>:NUCLEO=Nucleo64WBUi>
)

target_link_libraries(hal_st.helloworld_nucleo64 PRIVATE
services.util
hal_st.instantiations
)

halst_target_default_linker_scripts(hal_st.helloworld_nucleo64)
halst_target_default_init(hal_st.helloworld_nucleo64)

emil_generate_artifacts(TARGET hal_st.helloworld_nucleo64 LST MAP BIN HEX)
51 changes: 51 additions & 0 deletions examples/helloworld/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "hal/interfaces/Gpio.hpp"
#include "hal_st/instantiations/NucleoUi.hpp"
#include "hal_st/instantiations/StmEventInfrastructure.hpp"
#include "infra/timer/Timer.hpp"
#include "services/tracer/GlobalTracer.hpp"
#include "services/tracer/StreamWriterOnSerialCommunication.hpp"
#include "services/tracer/Tracer.hpp"
#include "services/tracer/TracerWithDateTime.hpp"
#include "services/util/DebugLed.hpp"
#include <array>
#include <chrono>

unsigned int hse_value = 24'000'000;

int main()
{
HAL_Init();

static main_::StmEventInfrastructure eventInfrastructure;
static main_::NUCLEO ui;
static services::DebugLed debugLed(ui.ledGreen);
static hal::DmaStm dmaStm;

#if defined(STM32G0) || defined(STM32G4)
static hal::GpioPinStm stLinkUartTxPin{ hal::Port::A, 2 };
static hal::GpioPinStm stLinkUartRxPin{ hal::Port::A, 3 };
static hal::DmaStm::TransmitStream transmitStream{ dmaStm, hal::DmaChannelId{ 1, 1, DMA_REQUEST_USART2_TX } };
static hal::UartStmDma stLinkUartDma{ transmitStream, 2, stLinkUartTxPin, stLinkUartRxPin };
#endif

#if defined(STM32WB)
static hal::GpioPinStm stLinkUartTxPin{ hal::Port::B, 6 };
static hal::GpioPinStm stLinkUartRxPin{ hal::Port::B, 7 };
static hal::DmaStm::TransmitStream transmitStream{ dmaStm, hal::DmaChannelId{ 1, 1, DMA_REQUEST_USART1_TX } };
static hal::UartStmDma stLinkUartDma{ transmitStream, 1, stLinkUartTxPin, stLinkUartRxPin };
#endif

static services::StreamWriterOnSerialCommunication::WithStorage<64> streamWriterOnSerialCommunication{ stLinkUartDma };
static infra::TextOutputStream::WithErrorPolicy textOutputStream{ streamWriterOnSerialCommunication };
static services::TracerWithDateTime tracerWithDateTime{ textOutputStream };

services::SetGlobalTracerInstance(tracerWithDateTime);

static infra::TimerRepeating timerRepeating{ std::chrono::seconds{ 1 }, []
{
services::GlobalTracer().Trace() << "Hello World !";
} };

eventInfrastructure.Run();
__builtin_unreachable();
}
2 changes: 2 additions & 0 deletions hal_st/instantiations/NucleoUi.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef HAL_ST_NUCLEO_UI_HPP
#define HAL_ST_NUCLEO_UI_HPP

#include "hal_st/stm32fxxx/DmaStm.hpp"
#include "hal_st/stm32fxxx/GpioStm.hpp"
#include "hal_st/stm32fxxx/UartStmDma.hpp"

namespace main_
{
Expand Down
13 changes: 5 additions & 8 deletions hal_st/stm32fxxx/AnalogToDigitalPinStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,20 @@ namespace hal
{
ADC_ChannelConfTypeDef channelConfig;
channelConfig.Channel = adcChannel[analogPin.AdcChannel(adc.index + 1)];
#if !defined(STM32WB)
channelConfig.Rank = 1;
#else
#if defined(STM32WB) || defined(STM32G0) || defined(STM32G4)
channelConfig.Rank = ADC_REGULAR_RANK_1;
#else
channelConfig.Rank = 1;
#endif
#if defined(STM32F0) || defined(STM32F3)
channelConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
#elif defined(STM32WB)
#elif defined(STM32WB) || defined(STM32G4)
channelConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
channelConfig.Offset = 0;
channelConfig.OffsetNumber = ADC_OFFSET_NONE;
channelConfig.SingleDiff = ADC_SINGLE_ENDED;
#elif defined(STM32G0)
channelConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES_5;
#elif defined(STM32G4)
channelConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES_5;
channelConfig.Offset = 0;
#else
channelConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
channelConfig.Offset = 0;
Expand Down Expand Up @@ -100,7 +97,7 @@ namespace hal
#if !defined(STM32F3)
handle.Init.DMAContinuousRequests = DISABLE;
#endif
#if defined(STM32WB)
#if defined(STM32WB) || defined(STM32G0) || defined(STM32G4)
handle.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
#elif !defined(STM32F3)
handle.Init.EOCSelection = DISABLE;
Expand Down
5 changes: 5 additions & 0 deletions hal_st/stm32fxxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ target_sources(hal_st.stm32fxxx PRIVATE
$<$<STREQUAL:${TARGET_MCU},stm32g070>:DefaultClockNucleoG070RB.hpp>
$<$<STREQUAL:${TARGET_MCU},stm32g431>:DefaultClockNucleoG431RB.cpp>
$<$<STREQUAL:${TARGET_MCU},stm32g431>:DefaultClockNucleoG431RB.hpp>
$<$<STREQUAL:${TARGET_MCU},stm32g474>:DefaultClockNucleoG474RE.cpp>
$<$<STREQUAL:${TARGET_MCU},stm32g474>:DefaultClockNucleoG474RE.hpp>
$<$<STREQUAL:${TARGET_MCU},stm32wb55>:DefaultClockNucleoWB55RG.cpp>
$<$<STREQUAL:${TARGET_MCU},stm32wb55>:DefaultClockNucleoWB55RG.hpp>
DigitalToAnalogPinStm.cpp
Expand Down Expand Up @@ -111,6 +113,9 @@ if (TARGET_MCU_VENDOR STREQUAL st)
elseif (TARGET_MCU STREQUAL stm32g431)
set(gpio_xml "${CMAKE_CURRENT_SOURCE_DIR}/ip/GPIO-STM32G43x_gpio_v1_0_Modes.xml")
set(mcu_xml "${CMAKE_CURRENT_SOURCE_DIR}/mcu/STM32G431R(6-8-B)Tx.xml")
elseif (TARGET_MCU STREQUAL stm32g474)
set(gpio_xml "${CMAKE_CURRENT_SOURCE_DIR}/ip/GPIO-STM32G47x_gpio_v1_0_Modes.xml")
set(mcu_xml "${CMAKE_CURRENT_SOURCE_DIR}/mcu/STM32G474R(B-C-E)Tx.xml")
elseif (TARGET_MCU_VARIANT STREQUAL stm32wb55rg)
set(gpio_xml "${CMAKE_CURRENT_SOURCE_DIR}/ip/GPIO-STM32WB55x_gpio_v1_0_Modes.xml")
set(mcu_xml "${CMAKE_CURRENT_SOURCE_DIR}/mcu/STM32WB55RGVx.xml")
Expand Down
47 changes: 47 additions & 0 deletions hal_st/stm32fxxx/DefaultClockNucleoG474RE.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include DEVICE_HEADER
#include "hal_st/stm32fxxx/DefaultClockNucleoG474RE.hpp"

/* The system Clock is configured as follows:
* System Clock source = PLL (HSE)
* SYSCLK(Hz) = 170,000,000
* HCLK(Hz) = 170,000,000
* AHB Prescaler = 1
* APB1 Prescaler = 1
* APB2 Prescaler = 1
* HSI Frequency(Hz) = 24MHz
* VDD(V) = 3.3
* Main regulator output voltage = Scale1 mode
*/
void ConfigureDefaultClockNucleo474RE()
{
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };

/** Configure the main internal regulator output voltage
*/
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST);

/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV6;
RCC_OscInitStruct.PLL.PLLN = 85;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
HAL_RCC_OscConfig(&RCC_OscInitStruct);

/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
}
6 changes: 6 additions & 0 deletions hal_st/stm32fxxx/DefaultClockNucleoG474RE.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef HAL_ST_DEFAULT_CLOCK_HPP
#define HAL_ST_DEFAULT_CLOCK_HPP

void ConfigureDefaultClockNucleo474RE();

#endif
Loading

0 comments on commit d62e03e

Please sign in to comment.