Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new board stm32f412 #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,26 @@ function(add_f407_target TGTNAME)
show_object_size(${TGTNAME}_fw)
endfunction()

function(add_f412_target TGTNAME)
add_executable(${TGTNAME}_fw ${SOURCE_FILES})
add_dependencies(${TGTNAME}_fw version_h)
target_include_directories(${TGTNAME}_fw PRIVATE include/ ${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(${TGTNAME}_fw PRIVATE BOARD_${TGTNAME} STM32F4 BOARD_STM32F412_DevBoard)
target_compile_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_F4})
target_link_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_F4})
target_link_options(${TGTNAME}_fw PRIVATE -T ${CMAKE_SOURCE_DIR}/ldscripts/STM32F412XE.ld)
target_link_libraries(${TGTNAME}_fw PRIVATE STM32_HAL_STM32F412xE STM32_USB_Device_Library_STM32F412xE)
make_bin_file(${TGTNAME}_fw)
dfu_flash(${TGTNAME}_fw)
show_object_size(${TGTNAME}_fw)
endfunction()

########## generate list of targets.
# the "_fw" part is appended automatically
set(TGT042_LIST "cantact" "canalyze" "canable" "usb2can" "cannette")
set(TGT072_LIST "candleLight" "CANable_MKS")
set(TGT407_LIST "STM32F4_DevBoard")

set(TGT412_LIST "STM32F412_DevBoard")

foreach (TGTNAME IN LISTS TGT042_LIST)
option(BUILD_${TGTNAME} "Build firmware for \"${TGTNAME}\" (default=yes)" ON)
Expand All @@ -189,6 +203,13 @@ foreach (TGTNAME IN LISTS TGT407_LIST)
endif()
endforeach()

foreach (TGTNAME IN LISTS TGT412_LIST)
option(BUILD_${TGTNAME} "Build firmware for \"${TGTNAME}\" (default=yes)" ON)
if (BUILD_${TGTNAME})
add_f412_target(${TGTNAME})
endif()
endforeach()

message("*******************")
message("You may now:\n\t-compile all targets ('make')\n\t-compile a single target (e.g. 'make cantact_fw'")
message("\t-flash a device (e.g. 'make flash-cantact_fw'")
19 changes: 19 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,25 @@ THE SOFTWARE.
#define USB_Pin_DM GPIO_PIN_11
#define USB_Pin_DP GPIO_PIN_12

#elif defined(BOARD_STM32F412_DevBoard)
#define USBD_PRODUCT_STRING_FS (uint8_t*) "STM32F412VE Dev Board"
#define USBD_MANUFACTURER_STRING (uint8_t*) "misc"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "STM32F412VE firmware upgrade interface"

#define LEDRX_GPIO_Port GPIOC
#define LEDRX_Pin GPIO_PIN_8
#define LEDRX_Mode GPIO_MODE_OUTPUT_OD
#define LEDRX_Active_High 0

#define LEDTX_GPIO_Port GPIOC
#define LEDTX_Pin GPIO_PIN_9
#define LEDTX_Mode GPIO_MODE_OUTPUT_OD
#define LEDTX_Active_High 0

#define USB_GPIO_Port GPIOA
#define USB_Pin_DM GPIO_PIN_11
#define USB_Pin_DP GPIO_PIN_12

#else
#error please define BOARD
#endif
7 changes: 5 additions & 2 deletions include/usbd_gs_can.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ extern USBD_ClassTypeDef USBD_GS_CAN;
# define USB_INTERFACE USB_OTG_FS
# define USB_INTERRUPT OTG_FS_IRQn
# define CAN_INTERFACE CAN1
# define CAN_CLOCK_SPEED 42000000

#if defined(BOARD_STM32F412_DevBoard)
# define CAN_CLOCK_SPEED 48000000
#else
# define CAN_CLOCK_SPEED 42000000
#endif
// RX FIFO is defined in words, so divide bytes by 4
// RX FIFO size chosen according to reference manual RM0368 which suggests
// using (largest packet size / 4) + 1
Expand Down
151 changes: 151 additions & 0 deletions ldscripts/STM32F412XE.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
__STACK_SIZE = 32K;
__HEAP_SIZE = 64K;

__FLASH_SIZE = 512K;
__NVM_SIZE = 128K;

MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = __FLASH_SIZE - __NVM_SIZE
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128K
DATA (xrw) : ORIGIN = 0x08000000 + __FLASH_SIZE - __NVM_SIZE, LENGTH = __NVM_SIZE
}


ENTRY(Reset_Handler)

SECTIONS
{
.text :
{
KEEP(*(.vectors))
*(.text*)

KEEP(*(.init))
KEEP(*(.fini))

/* .ctors */
*crtbegin.o(.ctors)
*crtbegin?.o(.ctors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT(.ctors.*))
*(.ctors)

/* .dtors */
*crtbegin.o(.dtors)
*crtbegin?.o(.dtors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
*(SORT(.dtors.*))
*(.dtors)

*(.rodata*)

KEEP(*(.eh_frame*))
} > FLASH

.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH

__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
__exidx_end = .;

.copy.table :
{
. = ALIGN(4);
__copy_table_start__ = .;
LONG (__etext)
LONG (__data_start__)
LONG (__data_end__ - __data_start__)
__copy_table_end__ = .;
} > FLASH

.zero.table :
{
. = ALIGN(4);
__zero_table_start__ = .;
__zero_table_end__ = .;
} > FLASH

__etext = ALIGN (4);

.user_data :
{
. = ALIGN(4);
*(.user_data)
. = ALIGN(4);
} > DATA

.data : AT (__etext)
{
__data_start__ = .;
*(vtable)
*(.data)
*(.data.*)

. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);

. = ALIGN(4);
/* init data */
PROVIDE_HIDDEN (__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);


. = ALIGN(4);
/* finit data */
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP(*(SORT(.fini_array.*)))
KEEP(*(.fini_array))
PROVIDE_HIDDEN (__fini_array_end = .);

KEEP(*(.jcr*))
. = ALIGN(4);
/* All data end */
__data_end__ = .;

} > RAM

.bss :
{
. = ALIGN(4);
__bss_start__ = .;
*(.bss)
*(.bss.*)
*(COMMON)
. = ALIGN(4);
__bss_end__ = .;
} > RAM AT > RAM

.heap (COPY) :
{
. = ALIGN(8);
__end__ = .;
PROVIDE(end = .);
. = . + __HEAP_SIZE;
. = ALIGN(8);
__HeapLimit = .;
} > RAM

.stack (ORIGIN(RAM) + LENGTH(RAM) - __STACK_SIZE) (COPY) :
{
. = ALIGN(8);
__StackLimit = .;
. = . + __STACK_SIZE;
. = ALIGN(8);
__StackTop = .;
} > RAM
PROVIDE(__stack = __StackTop);

ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
}
63 changes: 63 additions & 0 deletions libs/STM32_HAL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,64 @@ set(STM32F4_SOURCES
include/cmsis/device/system_stm32f4xx.h
)

set(STM32F412_SOURCES
config/stm32f4xx_hal_conf.h

include/stm32f4xx/stm32f4xx_hal_def.h
include/stm32f4xx/stm32f4xx_hal.h
src/stm32f4xx/stm32f4xx_hal.c

include/stm32f4xx/stm32f4xx_hal_can.h
src/stm32f4xx/stm32f4xx_hal_can.c

include/stm32f4xx/stm32f4xx_hal_cortex.h
src/stm32f4xx/stm32f4xx_hal_cortex.c

include/stm32f4xx/stm32f4xx_hal_flash_ex.h
src/stm32f4xx/stm32f4xx_hal_flash_ex.c
include/stm32f4xx/stm32f4xx_hal_flash.h
src/stm32f4xx/stm32f4xx_hal_flash.c

include/stm32f4xx/stm32f4xx_hal_gpio_ex.h
include/stm32f4xx/stm32f4xx_hal_gpio.h
src/stm32f4xx/stm32f4xx_hal_gpio.c

include/stm32f4xx/stm32f4xx_hal_pcd_ex.h
src/stm32f4xx/stm32f4xx_hal_pcd_ex.c
include/stm32f4xx/stm32f4xx_hal_pcd.h
src/stm32f4xx/stm32f4xx_hal_pcd.c

include/stm32f4xx/stm32f4xx_hal_rcc.h
src/stm32f4xx/stm32f4xx_hal_rcc.c
include/stm32f4xx/stm32f4xx_hal_rcc_ex.h
src/stm32f4xx/stm32f4xx_hal_rcc_ex.c

include/stm32f4xx/stm32f4xx_hal_pwr.h
src/stm32f4xx/stm32f4xx_hal_pwr.c
include/stm32f4xx/stm32f4xx_hal_pwr_ex.h
src/stm32f4xx/stm32f4xx_hal_pwr_ex.c

include/stm32f4xx/stm32f4xx_hal_tim_ex.h
src/stm32f4xx/stm32f4xx_hal_tim_ex.c
include/stm32f4xx/stm32f4xx_hal_tim.h
src/stm32f4xx/stm32f4xx_hal_tim.c

include/stm32f4xx/stm32f4xx_ll_usb.h
src/stm32f4xx/stm32f4xx_ll_usb.c

src/cmsis/system_stm32f4xx.c
include/stm32f4xx/Legacy/stm32_hal_legacy.h

include/cmsis/cmsis_compiler.h
include/cmsis/cmsis_device.h
include/cmsis/cmsis_gcc.h
include/cmsis/cmsis_version.h
include/cmsis/core_cm4.h
include/cmsis/device/stm32f4xx.h
include/cmsis/device/stm32f412zx.h
include/cmsis/device/system_stm32f4xx.h
)

set(INCLUDE_DIRS
include/
include/cmsis
Expand All @@ -134,3 +192,8 @@ add_library(STM32_HAL_STM32F407xE STATIC ${STM32F4_SOURCES})
target_include_directories(STM32_HAL_STM32F407xE PUBLIC ${INCLUDE_DIRS} include/stm32f4xx)
target_compile_options(STM32_HAL_STM32F407xE PRIVATE ${CPUFLAGS_F4} -Wno-unused-parameter)
target_compile_definitions(STM32_HAL_STM32F407xE PUBLIC STM32F407xx HAL_TARGET_PREFIX=stm32f4xx)

add_library(STM32_HAL_STM32F412xE STATIC ${STM32F412_SOURCES})
target_include_directories(STM32_HAL_STM32F412xE PUBLIC ${INCLUDE_DIRS} include/stm32f4xx)
target_compile_options(STM32_HAL_STM32F412xE PRIVATE ${CPUFLAGS_F4} -Wno-unused-parameter)
target_compile_definitions(STM32_HAL_STM32F412xE PUBLIC STM32F412Zx BOARD_STM32F412_DevBoard HAL_TARGET_PREFIX=stm32f4xx)
4 changes: 4 additions & 0 deletions libs/STM32_HAL/include/cmsis/cmsis_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
#ifdef STM32F407xx
#include <cmsis/device/stm32f407xx.h>
#endif

#ifdef STM32F412Zx
#include <cmsis/device/stm32f412zx.h>
#endif
Loading