Skip to content

Commit

Permalink
feat: Add new family STM32WBA to hal_st (#314)
Browse files Browse the repository at this point in the history
* Add new files for mcu stm32wba52cx

* fix code review

* remove files
  • Loading branch information
cassio-lazaro authored May 30, 2024
1 parent 1d3d133 commit 112eedb
Show file tree
Hide file tree
Showing 33 changed files with 700 additions and 223 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
matrix:
configuration: ["RelWithDebInfo"]
gcc: [ "10.3-2021.10" ]
target: ["stm32wb55", "stm32g070", "stm32g431", "stm32f407", "stm32f429", "stm32f746", "stm32f767"]
target: ["stm32wb55", "stm32g070", "stm32g431", "stm32f407", "stm32f429", "stm32f746", "stm32f767", "stm32wba52"]
include:
- gcc: "7-2018-q2"
configuration: "RelWithDebInfo"
Expand Down
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@
"monitor reset"
],
"overrideRestartCommands": ["monitor reset"]
},
{
"name": "stm32wba52cg",
"cwd": "${workspaceFolder}",
"executable": "${command:cmake.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"device": "STM32WBA52CG",
"servertype": "external",
"runToEntryPoint": "main",
"showDevDebugOutput": "both",
"gdbTarget": "host.docker.internal:61234",
"overrideLaunchCommands": [
"monitor reset",
"-target-download",
"monitor reset"
],
"overrideRestartCommands": ["monitor reset"]
}
]
}
23 changes: 23 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@
"TARGET_MCU_FAMILY": "stm32g4xx",
"TARGET_MCU": "stm32g474"
}
},
{
"name": "stm32wba52",
"displayName": "stm32wba52",
"description": "Build for stm32wba52",
"inherits": "stm32",
"toolchainFile": "${sourceDir}/build/${presetName}/_deps/emil-src/cmake/toolchain-arm-gcc-m33-fpv5-sp-d16.cmake",
"cacheVariables": {
"TARGET_CORTEX": "m33",
"TARGET_MCU_FAMILY": "stm32wbaxx",
"TARGET_MCU": "stm32wba52",
"TARGET_MCU_VARIANT": "stm32wba52cg"
}
}
],
"buildPresets": [
Expand Down Expand Up @@ -216,6 +229,16 @@
"name": "stm32f767-Debug",
"configuration": "Debug",
"configurePreset": "stm32f767"
},
{
"name": "stm32wba52-RelWithDebInfo",
"configuration": "RelWithDebInfo",
"configurePreset": "stm32wba52"
},
{
"name": "stm32wba52-Debug",
"configuration": "Debug",
"configurePreset": "stm32wba52"
}
],
"testPresets": [
Expand Down
4 changes: 3 additions & 1 deletion examples/blink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ emil_build_for(hal_st.blink_nucleo64
TARGET_MCU stm32g431
TARGET_MCU stm32g474
TARGET_MCU stm32wb55
TARGET_MCU stm32wba52
PREREQUISITE_BOOL HALST_BUILD_EXAMPLES
)

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

target_link_libraries(hal_st.blink_nucleo64 PRIVATE
Expand Down
6 changes: 5 additions & 1 deletion examples/blink/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
// #include "hal_st/stm32fxxx/DefaultClockNucleoF767ZI.hpp"
#include "services/util/DebugLed.hpp"

unsigned int hse_value = 8000000;
#if defined(STM32WBA)
unsigned int hse_value = 32'000'000;
#else
unsigned int hse_value = 8'000'000;
#endif

int main()
{
Expand Down
26 changes: 25 additions & 1 deletion examples/helloworld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ add_executable(hal_st.helloworld_nucleo64 Main.cpp)
emil_build_for(hal_st.helloworld_nucleo64
TARGET_MCU stm32g474
TARGET_MCU stm32wb55
TARGET_MCU stm32wba52
PREREQUISITE_BOOL HALST_BUILD_EXAMPLES
)

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

target_link_libraries(hal_st.helloworld_nucleo64 PRIVATE
Expand All @@ -19,3 +21,25 @@ 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)

######################################################################

add_executable(hal_st.helloworld_nucleo144 Main.cpp)
emil_build_for(hal_st.helloworld_nucleo144
TARGET_MCU stm32f767
PREREQUISITE_BOOL HALST_BUILD_EXAMPLES
)

target_compile_definitions(hal_st.helloworld_nucleo144 PUBLIC
NUCLEO=Nucleo144Ui
)

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

halst_target_default_linker_scripts(hal_st.helloworld_nucleo144)
halst_target_default_init(hal_st.helloworld_nucleo144)

emil_generate_artifacts(TARGET hal_st.helloworld_nucleo144 LST MAP BIN HEX)
23 changes: 20 additions & 3 deletions examples/helloworld/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
#include <array>
#include <chrono>

#if defined(STM32WBA)
unsigned int hse_value = 32'000'000;
#else
unsigned int hse_value = 24'000'000;
#endif

int main()
{
Expand All @@ -21,21 +25,34 @@ int main()
static services::DebugLed debugLed(ui.ledGreen);
static hal::DmaStm dmaStm;

#if defined(STM32G0) || defined(STM32G4)
#if defined(STM32F7)
static hal::GpioPinStm stLinkUartTxPin{ hal::Port::D, 8 };
static hal::GpioPinStm stLinkUartRxPin{ hal::Port::D, 9 };
static hal::DmaStm::TransmitStream transmitStream{ dmaStm, hal::DmaChannelId{ 1, 3, 4 } };
static hal::UartStmDma stLinkUartDma{ transmitStream, 3, stLinkUartTxPin, stLinkUartRxPin };

#elif 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)
#elif 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 };

#elif defined(STM32WBA)
static hal::GpioPinStm stLinkUartTxPin{ hal::Port::B, 12 };
static hal::GpioPinStm stLinkUartRxPin{ hal::Port::A, 8 };

static hal::DmaStm::TransmitStream transmitStream{ dmaStm, hal::DmaChannelId{ 1, 1, GPDMA1_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 };

Expand Down
11 changes: 11 additions & 0 deletions hal_st/instantiations/NucleoUi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ namespace main_
hal::GpioPinStm ledBlue{ hal::Port::B, 5 };
};

// UM3103: MB1863 reference board with STM32WBA52CG
struct Nucleo64WBAUi
{
hal::GpioPinStm buttonOne{ hal::Port::C, 13, hal::Drive::Default, hal::Speed::Default, hal::WeakPull::Up };
hal::GpioPinStm buttonTwo{ hal::Port::B, 6, hal::Drive::Default, hal::Speed::Default, hal::WeakPull::Up };
hal::GpioPinStm buttonThree{ hal::Port::B, 7, hal::Drive::Default, hal::Speed::Default, hal::WeakPull::Up };
hal::GpioPinStm ledRed{ hal::Port::B, 8 };
hal::GpioPinStm ledGreen{ hal::Port::B, 11 };
hal::GpioPinStm ledBlue{ hal::Port::B, 4 };
};

// UM1974: MB1137 reference board with F207ZG, F303ZE, F412ZG, F413ZH, F429ZI, F439ZI, F446ZE, F722ZE, F746ZG, F756ZG, F767ZI, H743ZI
// UM2179: MB1312 reference board with L496ZG, L496ZG-P, L4A6ZG, L4P5ZG, LR5ZI, L4R5ZI-P
struct Nucleo144Ui
Expand Down
29 changes: 18 additions & 11 deletions hal_st/stm32fxxx/AnalogToDigitalPinStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#if defined(STM32F7)
extern "C"
{
#include "stm32f7xx_ll_adc.h"
#include "stm32f7xx_ll_adc.h"
}
#endif

Expand All @@ -26,11 +26,13 @@ namespace
ADC_CHANNEL_11,
ADC_CHANNEL_12,
ADC_CHANNEL_13,
#ifdef ADC_CHANNEL_18
ADC_CHANNEL_14,
ADC_CHANNEL_15,
ADC_CHANNEL_16,
ADC_CHANNEL_17,
ADC_CHANNEL_18
#endif
};
}

Expand Down Expand Up @@ -60,7 +62,7 @@ namespace hal
channelConfig.Offset = 0;
channelConfig.OffsetNumber = ADC_OFFSET_NONE;
channelConfig.SingleDiff = ADC_SINGLE_ENDED;
#elif defined(STM32G0)
#elif defined(STM32G0) || defined(STM32WBA)
channelConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES_5;
#else
channelConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
Expand All @@ -83,7 +85,7 @@ namespace hal
void AnalogToDigitalInternalTemperatureStm::Measure(std::size_t numberOfSamples, const infra::Function<void(infra::MemoryRange<uint16_t>)>& onDone)
{
ADC_ChannelConfTypeDef channelConfig;
#if !defined(STM32G4)
#if defined(ADC_CHANNEL_TEMPSENSOR)
channelConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
#else
if (adc.index == 1)
Expand All @@ -100,7 +102,7 @@ namespace hal
channelConfig.OffsetNumber = ADC_OFFSET_NONE;
channelConfig.SingleDiff = ADC_SINGLE_ENDED;
#endif
#if !defined(STM32F0) && !defined(STM32F3) && !defined(STM32G0)
#if !defined(STM32F0) && !defined(STM32F3) && !defined(STM32G0) && !defined(STM32WBA)
channelConfig.Offset = 0;
#endif
channelConfig.SamplingTime = config.samplingTime;
Expand All @@ -117,33 +119,38 @@ namespace hal
, interruptHandler(ADC1_IRQn, [this]()
#elif defined(STM32G4)
, interruptHandler(ADC1_2_IRQn, [this]()
#elif defined(STM32WBA)
, interruptHandler(ADC4_IRQn, [this]()
#else
, interruptHandler(ADC_IRQn, [this]()
#endif
{ MeasurementDone(); })
{
MeasurementDone();
})
{
EnableClockAdc(index);

handle.Instance = peripheralAdc[index];
#if !defined(STM32F3)
#if !defined(STM32F3) && !defined(STM32WBA)
handle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV4;
handle.Init.Resolution = ADC_RESOLUTION_12B;
#elif defined(STM32WBA)
handle.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;
handle.Init.Resolution = ADC_RESOLUTION_12B;
#endif
handle.Init.ScanConvMode = DISABLE;
handle.Init.ContinuousConvMode = DISABLE;
handle.Init.DiscontinuousConvMode = DISABLE;
#if !defined(STM32G0)
#if !defined(STM32G0) && !defined(STM32WBA)
handle.Init.NbrOfDiscConversion = 0;
#endif
#if !defined(STM32F3)
handle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
handle.Init.DMAContinuousRequests = DISABLE;
#endif
handle.Init.ExternalTrigConv = ADC_SOFTWARE_START;
handle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
handle.Init.NbrOfConversion = 1;
#if !defined(STM32F3)
handle.Init.DMAContinuousRequests = DISABLE;
#endif
#if defined(STM32WB) || defined(STM32G0) || defined(STM32G4)
handle.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
handle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
Expand Down Expand Up @@ -186,7 +193,7 @@ namespace hal
void AdcStm::MeasurementDone()
{
assert(onDone != nullptr);
#if defined(STM32WB) || defined(STM32G4) || defined(STM32G0)
#if defined(STM32WB) || defined(STM32G4) || defined(STM32G0) || defined(STM32WBA)
handle.Instance->ISR |= ADC_ISR_EOC | ADC_ISR_EOS;
#else
handle.Instance->SR &= ~ADC_SR_EOC;
Expand Down
10 changes: 5 additions & 5 deletions hal_st/stm32fxxx/AnalogToDigitalPinStm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ namespace hal
struct AdcStmChannelConfig
{
#if defined(STM32F0) || defined(STM32F3)
uint32_t samplingTime { ADC_SAMPLETIME_7CYCLES_5 };
uint32_t samplingTime{ ADC_SAMPLETIME_7CYCLES_5 };
#elif defined(STM32WB) || defined(STM32G4)
uint32_t samplingTime { ADC_SAMPLETIME_2CYCLES_5 };
#elif defined(STM32G0)
uint32_t samplingTime { ADC_SAMPLETIME_3CYCLES_5 };
uint32_t samplingTime{ ADC_SAMPLETIME_2CYCLES_5 };
#elif defined(STM32G0) || defined(STM32WBA)
uint32_t samplingTime{ ADC_SAMPLETIME_3CYCLES_5 };
#else
uint32_t samplingTime { ADC_SAMPLETIME_3CYCLES };
uint32_t samplingTime{ ADC_SAMPLETIME_3CYCLES };
#endif
};
}
Expand Down
2 changes: 1 addition & 1 deletion hal_st/stm32fxxx/BackupRamStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace hal
{
#if defined(STM32G0)
return infra::MakeRange(&TAMP->BKP0R, &TAMP->BKP4R + 1);
#elif defined(STM32G4)
#elif defined(STM32G4) || defined(STM32WBA)
return infra::MakeRange(&TAMP->BKP0R, &TAMP->BKP15R + 1);
#else
return infra::MakeRange(&peripheralRtc[0]->BKP0R, &peripheralRtc[0]->BKP19R + 1);
Expand Down
6 changes: 5 additions & 1 deletion hal_st/stm32fxxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ if (TARGET_MCU_VENDOR STREQUAL st)
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")
elseif (TARGET_MCU_VARIANT STREQUAL stm32wba52cg)
set(gpio_xml "${CMAKE_CURRENT_SOURCE_DIR}/ip/GPIO-STM32WBA52x_gpio_v1_0_Modes.xml")
set(mcu_xml "${CMAKE_CURRENT_SOURCE_DIR}/mcu/STM32WBA52CGUx.xml")
else()
message(FATAL_ERROR "Unknown TARGET_MCU \"${TARGET_MCU}\". Please configure HALST_XML_GPIO and HALST_XML_STM32.")
endif()
Expand All @@ -132,8 +135,9 @@ if (TARGET_MCU_VENDOR STREQUAL st)
generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PinoutTableDefault.cpp GeneratePinoutTableCpp.xsl "${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PinoutTableDefaultStructure.xml")
generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PinoutTableDefault.hpp GeneratePinoutTableHpp.xsl "${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PinoutTableDefaultStructure.xml")

generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PeripheralTableStructure.xml GeneratePeripheralTableStructure.xsl $<IF:$<STREQUAL:${TARGET_MCU_FAMILY},stm32wbxx>,PeripheralTableWbxx.xml,PeripheralTableFxxx.xml>
generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PeripheralTableStructure.xml GeneratePeripheralTableStructure.xsl $<IF:$<OR:$<STREQUAL:${TARGET_MCU_FAMILY},stm32wbaxx>,$<STREQUAL:${TARGET_MCU_FAMILY},stm32wbxx>>,PeripheralTableWbxx.xml,PeripheralTableFxxx.xml>
--stringparam mcu-document ${mcu_xml})

generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PeripheralTable.cpp GeneratePeripheralTableCpp.xsl "${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PeripheralTableStructure.xml")
generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PeripheralTable.hpp GeneratePeripheralTableHpp.xsl "${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PeripheralTableStructure.xml")

Expand Down
Loading

0 comments on commit 112eedb

Please sign in to comment.