Skip to content

Commit

Permalink
add cmake for all board in stm32f4. fix build, also move ci for f4 fr…
Browse files Browse the repository at this point in the history
…om makefile to cmake
  • Loading branch information
hathach committed Aug 4, 2023
1 parent 81aca17 commit 25bace5
Show file tree
Hide file tree
Showing 17 changed files with 188 additions and 118 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build_arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:
- 'samd51 same5x'
- 'saml2x'
- 'stm32f2 stm32f3'
- 'stm32f4'
- 'stm32l0 stm32u5 stm32wb'
- 'tm4c123 xmc4000'
steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/cmake_arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
- 'rp2040'
- 'stm32f0'
- 'stm32f1'
- 'stm32f4'
- 'stm32f7'
- 'stm32g0'
- 'stm32g4'
Expand Down
3 changes: 2 additions & 1 deletion .idea/cmake.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hw/bsp/stm32f4/FreeRTOSConfig/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configQUEUE_REGISTRY_SIZE 2
#define configQUEUE_REGISTRY_SIZE 4
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 0
#define configUSE_NEWLIB_REENTRANT 0
Expand Down
10 changes: 10 additions & 0 deletions hw/bsp/stm32f4/boards/feather_stm32f405/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(MCU_VARIANT stm32f405xx)
set(JLINK_DEVICE stm32f405rg)

set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F405RGTx_FLASH.ld)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
STM32F405xx
)
endfunction()
10 changes: 10 additions & 0 deletions hw/bsp/stm32f4/boards/pyboardv11/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(MCU_VARIANT stm32f405xx)
set(JLINK_DEVICE stm32f405rg)

set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F405RGTx_FLASH.ld)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
STM32F405xx
)
endfunction()
10 changes: 10 additions & 0 deletions hw/bsp/stm32f4/boards/stm32f401blackpill/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(MCU_VARIANT stm32f401xc)
set(JLINK_DEVICE stm32f401cc)

set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F401VCTx_FLASH.ld)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
STM32F405xx
)
endfunction()
9 changes: 2 additions & 7 deletions hw/bsp/stm32f4/boards/stm32f407blackvet/board.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ set(MCU_VARIANT stm32f407xx)
set(JLINK_DEVICE stm32f407ve)

set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F407VETx_FLASH.ld)
set(LD_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/linker/${MCU_VARIANT}_flash.icf)

set(STARTUP_FILE_GNU ${ST_CMSIS}/Source/Templates/gcc/startup_${MCU_VARIANT}.s)
set(STARTUP_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/startup_${MCU_VARIANT}.s)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
STM32F407xx
HSE_VALUE=8000000
CORE_CM4
BOARD_TUD_RHPORT=0
BOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
BOARD_TUD_RHPORT=0
BOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
)
endfunction()
10 changes: 10 additions & 0 deletions hw/bsp/stm32f4/boards/stm32f407disco/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(MCU_VARIANT stm32f407xx)
set(JLINK_DEVICE stm32f407vg)

set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F407VGTx_FLASH.ld)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
STM32F407xx
)
endfunction()
10 changes: 10 additions & 0 deletions hw/bsp/stm32f4/boards/stm32f411blackpill/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(MCU_VARIANT stm32f411xe)
set(JLINK_DEVICE stm32f411ce)

set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F411CEUx_FLASH.ld)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
STM32F411xE
)
endfunction()
10 changes: 10 additions & 0 deletions hw/bsp/stm32f4/boards/stm32f411disco/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(MCU_VARIANT stm32f411xe)
set(JLINK_DEVICE stm32f411ve)

set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F411VETx_FLASH.ld)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
STM32F411xE
)
endfunction()
10 changes: 10 additions & 0 deletions hw/bsp/stm32f4/boards/stm32f412disco/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(MCU_VARIANT stm32f412zx)
set(JLINK_DEVICE stm32f412zg)

set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F412ZGTx_FLASH.ld)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
STM32F412Zx
)
endfunction()
10 changes: 10 additions & 0 deletions hw/bsp/stm32f4/boards/stm32f412nucleo/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(MCU_VARIANT stm32f412zx)
set(JLINK_DEVICE stm32f412zg)

set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F412ZGTx_FLASH.ld)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
STM32F412Zx
)
endfunction()
10 changes: 10 additions & 0 deletions hw/bsp/stm32f4/boards/stm32f439nucleo/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(MCU_VARIANT stm32f439xx)
set(JLINK_DEVICE stm32f439zi)

set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F439ZITX_FLASH.ld)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
STM32F439xx
)
endfunction()
86 changes: 45 additions & 41 deletions hw/bsp/stm32f4/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void)
{
void OTG_FS_IRQHandler(void) {
tud_int_handler(0);
}

void OTG_HS_IRQHandler(void)
{
void OTG_HS_IRQHandler(void) {
tud_int_handler(1);
}

Expand All @@ -46,8 +44,7 @@ void OTG_HS_IRQHandler(void)
//--------------------------------------------------------------------+
UART_HandleTypeDef UartHandle;

void board_init(void)
{
void board_init(void) {
board_clock_init();
//SystemCoreClockUpdate();

Expand All @@ -62,7 +59,7 @@ void board_init(void)
NVIC_SetPriority(OTG_FS_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
#endif

GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitTypeDef GPIO_InitStruct;

// LED
GPIO_InitStruct.Pin = LED_PIN;
Expand All @@ -82,22 +79,22 @@ void board_init(void)

#ifdef UART_DEV
// UART
GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = UART_GPIO_AF;
HAL_GPIO_Init(UART_GPIO_PORT, &GPIO_InitStruct);

UartHandle = (UART_HandleTypeDef){
.Instance = UART_DEV,
.Init.BaudRate = CFG_BOARD_UART_BAUDRATE,
.Init.WordLength = UART_WORDLENGTH_8B,
.Init.StopBits = UART_STOPBITS_1,
.Init.Parity = UART_PARITY_NONE,
.Init.HwFlowCtl = UART_HWCONTROL_NONE,
.Init.Mode = UART_MODE_TX_RX,
.Init.OverSampling = UART_OVERSAMPLING_16
UartHandle = (UART_HandleTypeDef) {
.Instance = UART_DEV,
.Init.BaudRate = CFG_BOARD_UART_BAUDRATE,
.Init.WordLength = UART_WORDLENGTH_8B,
.Init.StopBits = UART_STOPBITS_1,
.Init.Parity = UART_PARITY_NONE,
.Init.HwFlowCtl = UART_HWCONTROL_NONE,
.Init.Mode = UART_MODE_TX_RX,
.Init.OverSampling = UART_OVERSAMPLING_16
};
HAL_UART_Init(&UartHandle);
#endif
Expand Down Expand Up @@ -148,56 +145,63 @@ void board_init(void)
// Board porting API
//--------------------------------------------------------------------+

void board_led_write(bool state)
{
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1-LED_STATE_ON));
void board_led_write(bool state) {
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
}

uint32_t board_button_read(void)
{
uint32_t board_button_read(void) {
return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
}

int board_uart_read(uint8_t* buf, int len)
{
(void) buf; (void) len;
size_t board_get_unique_id(uint8_t id[], size_t max_len) {
(void) max_len;
volatile uint32_t *stm32_uuid = (volatile uint32_t *) UID_BASE;
uint32_t *id32 = (uint32_t *) (uintptr_t) id;
uint8_t const len = 12;

id32[0] = stm32_uuid[0];
id32[1] = stm32_uuid[1];
id32[2] = stm32_uuid[2];

return len;
}

int board_uart_read(uint8_t *buf, int len) {
(void) buf;
(void) len;
return 0;
}

int board_uart_write(void const * buf, int len)
{
int board_uart_write(void const *buf, int len) {
#ifdef UART_DEV
HAL_UART_Transmit(&UartHandle, (uint8_t*)(uintptr_t) buf, len, 0xffff);
HAL_UART_Transmit(&UartHandle, (uint8_t *) (uintptr_t) buf, len, 0xffff);
return len;
#else
(void) buf; (void) len; (void) UartHandle;
return 0;
#endif
}

#if CFG_TUSB_OS == OPT_OS_NONE
#if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0;
void SysTick_Handler (void)
{

void SysTick_Handler(void) {
HAL_IncTick();
system_ticks++;
}

uint32_t board_millis(void)
{
uint32_t board_millis(void) {
return system_ticks;
}

#endif

void HardFault_Handler (void)
{
void HardFault_Handler(void) {
__asm("BKPT #0\n");
}

// Required by __libc_init_array in startup code if we are compiling using
// -nostdlib/-nostartfiles.
void _init(void)
{

void _init(void) {
}
Loading

0 comments on commit 25bace5

Please sign in to comment.