/STM32Core

STM32 peripheral libraries such as ADC, UART, SPI, I2C etc.

Primary LanguageCMIT LicenseMIT

STM32Core

STM32 LL(Low Layer) peripheral libraries such as ADC, UART, SPI, I2C etc.

Features

  • Specifically designed for embedded applications
  • Ultra lightweight
  • Easy import to the project and use
  • Full feature support
  • No HAL dependencies

Add as CPM project dependency

How to add CPM to the project, check the link

CPMAddPackage(
        NAME STM32Core
        GITHUB_REPOSITORY ximtech/STM32Core
        GIT_TAG origin/main)

ADC

An ADC (Analog-To-Digital) converter is an electronic circuit that takes in an analog voltage as input and converts it into digital data, a value that represents the voltage level in binary code.

Project configuration

  1. Start project with STM32CubeMX:

  2. Select: Project Manager -> Advanced Settings -> ADC -> LL

  3. Generate Code

  4. Add sources to project:

# add in CmakeLists_template.txt or directly to CmakeLists.txt
# link libraries to project
# Polling ADC
add_subdirectory(${STM32_CORE_SOURCE_DIR}/ADC/Polling)
# Interrupt based ADC
add_subdirectory(${STM32_CORE_SOURCE_DIR}/ADC/IT)
# DMA based ADC
add_subdirectory(${STM32_CORE_SOURCE_DIR}/ADC/DMA)

include_directories(${includes}
        ${ADC_POLLING_DIRECTORY}
        ${ADC_IT_DIRECTORY}
        ${ADC_DMA_DIRECTORY})

file(GLOB_RECURSE SOURCES ${sources}
        ${ADC_POLLING_SOURCES}
        ${ADC_IT_SOURCES}
        ${ADC_DMA_SOURCES})

target_link_libraries(${PROJECT_NAME}.elf Vector)   # add vector if ADC_IT or ADC_DMA is used
  1. Then Build -> Clean -> Rebuild Project

Usage

  1. Polling ADC code examples:
  2. Interrupt ADC code examples:
  3. DMA ADC code examples:

For Interrupt and DMA ADC set handler functions in stm32fXxx_it.c

/******************************************************************************/
/* STM32FXxx STM32 Peripheral Interrupt Handlers                              */
/* Add here the Interrupt Handlers for the used peripherals.                  */
/* For the available peripheral interrupt handler names,                      */
/* please refer to the startup file (startup_stm32fXxx.s).                    */
/******************************************************************************/

// This function handles ADC1 global interrupt.
void ADC_IRQHandler(void) {
    conventionCompleteCallbackADC(ADC1, ADC_REGULAR_CHANNEL);   // set ADC type and channel type
}

// This function handles DMA2 stream0 global interrupt.
void DMA2_Stream0_IRQHandler(void) {
    transferCompleteCallbackADC_DMA(DMA2, LL_DMA_STREAM_0); // set DMA type and stream
}

I2C

Inter-Integrated Circuit (I2C) is a communication bus protocol developed by Philips Semiconductor (now NXP Semiconductors) in 1982. It is a relatively slow protocol but has seen widespread use due to its simplicity and robustness.

Project configuration

  1. Start project with STM32CubeMX:

  2. Select: Project Manager -> Advanced Settings -> I2C -> LL

  3. Generate Code

  4. Add sources to project:

# add in CmakeLists_template.txt or directly to CmakeLists.txt
# link libraries
add_subdirectory(${STM32_CORE_SOURCE_DIR}/I2C/Polling)
add_subdirectory(${STM32_CORE_SOURCE_DIR}/I2C/IT)
add_subdirectory(${STM32_CORE_SOURCE_DIR}/I2C/DMA)

include_directories(${includes}
        ${I2C_POLLING_DIRECTORY}
        ${I2C_IT_DIRECTORY}
        ${I2C_DMA_DIRECTORY})

file(GLOB_RECURSE SOURCES ${sources}
        ${I2C_POLLING_SOURCES}
        ${I2C_IT_SOURCES}
        ${I2C_DMA_SOURCES})

add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT}) # executable declaration should be before libraries

target_link_libraries(${PROJECT_NAME}.elf RingBuffer)   # add ring buffer if I2C_IT is used
target_link_libraries(${PROJECT_NAME}.elf Vector)   # add vector if I2C_DMA is used
  1. Then Build -> Clean -> Rebuild Project

Usage

  1. Polling I2C code examples:
  2. TODO: add more examples

USART

The USART peripheral is used to interconnect STM32 MPU devices with other systems, typically via RS232 or RS485 protocols.

Project configuration

  1. Start project with STM32CubeMX:

  2. Select: Project Manager -> Advanced Settings -> USART -> LL

  3. Generate Code

  4. Add sources to project:

# add in CmakeLists_template.txt or directly to CmakeLists.txt
# link libraries
add_subdirectory(${STM32_CORE_SOURCE_DIR}/USART/DMA)
add_subdirectory(${STM32_CORE_SOURCE_DIR}/USART/IT)
add_subdirectory(${STM32_CORE_SOURCE_DIR}/USART/Polling)

include_directories(${includes}
        ${USART_POLLING_DIRECTORY}
        ${USART_IT_DIRECTORY}
        ${USART_DMA_DIRECTORY})

file(GLOB_RECURSE SOURCES ${sources}
        ${USART_POLLING_SOURCES}
        ${USART_IT_SOURCES}
        ${USART_DMA_SOURCES})

target_link_libraries(${PROJECT_NAME}.elf RingBuffer)   # add ring buffer if USART_IT is used
target_link_libraries(${PROJECT_NAME}.elf Vector)   # add vector if USART_DMA is used
  1. Then Build -> Clean -> Rebuild Project

Usage

  1. Polling USART code example:
  2. Interrupt USART code example:
  3. DMA USART code example:

SPI

SPI is an acronym for (Serial Peripheral Interface) pronounced as “S-P-I” or “Spy”. Which is an interface bus typically used for serial communication between microcomputer systems and other devices, memories, and sensors.

Project configuration

  1. Start project with STM32CubeMX:

  2. Select: Project Manager -> Advanced Settings -> SPI -> LL

  3. Generate Code

  4. Add sources to project:

# add in CmakeLists_template.txt or directly to CmakeLists.txt
# link libraries
add_subdirectory(${STM32_CORE_SOURCE_DIR}/SPI/Polling)
add_subdirectory(${STM32_CORE_SOURCE_DIR}/SPI/IT)
add_subdirectory(${STM32_CORE_SOURCE_DIR}/SPI/DMA)

include_directories(${includes}
        ${SPI_POLLING_DIRECTORY}
        ${SPI_IT_DIRECTORY}
        ${SPI_DMA_DIRECTORY})

file(GLOB_RECURSE SOURCES ${sources}
        ${SPI_POLLING_SOURCES}
        ${SPI_IT_SOURCES}
        ${SPI_DMA_SOURCES})

target_link_libraries(${PROJECT_NAME}.elf RingBuffer)   # add ring buffer if SPI_IT is used
target_link_libraries(${PROJECT_NAME}.elf Vector)   # add vector if SPI_DMA is used
  1. Then Build -> Clean -> Rebuild Project

Usage

  1. Polling SPI code example:
  2. Interrupt SPI code example:
  3. DMA SPI code example:

RTC

A real-time clock (RTC) is a computer clock that keeps track of the current time.

Project configuration

  1. Start project with STM32CubeMX:

  2. Select: Project Manager -> Advanced Settings -> RTC -> LL

  3. Generate Code

  4. Add sources to project:

# add in CmakeLists_template.txt or directly to CmakeLists.txt
# link libraries
CPMAddPackage(
        NAME GlobalDateTime
        GITHUB_REPOSITORY ximtech/GlobalDateTime
        GIT_TAG origin/main
        OPTIONS
        "ENABLE_TIME_ZONE_SUPPORT ON"
        "ENABLE_TIME_ZONE_HISTORIC_RULES OFF")

add_subdirectory(${STM32_CORE_SOURCE_DIR}/RTC)
include_directories(${includes} ${RTC_DIRECTORY})
file(GLOB_RECURSE SOURCES ${sources} ${RTC_SOURCES})

target_link_libraries(${PROJECT_NAME}.elf GlobalDateTime)   # library requires date-time library
  1. Then Build -> Clean -> Rebuild Project

Usage

  1. RTC code example:
  2. Interrupt SPI code example: