Skip to content

Commit

Permalink
init the support of stm32f4xx
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaqian12 committed May 6, 2023
1 parent 6e103d3 commit 2b48c13
Show file tree
Hide file tree
Showing 29 changed files with 2,177 additions and 101 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ It only supports DFU with MSC.
| ArteryTek | AT32F415 | |
| ST | STM32F072 | Need to copy the vector table from the Flash to the base address of the SRAM at 0x20000000 in app |
| ST | STM32F103 | |
| ST | STM32F401 | |
| ST | STM32F407 | |
| ST | STM32F411 | |
| ST | STM32G431 | |
| ST | STM32L433 | |
| WCH | CH32V307 | |
Expand Down
Binary file added bootloader/ST/cherryuf2_stm32f401ccu6.bin
Binary file not shown.
Binary file added bootloader/ST/cherryuf2_stm32f407zgt6.bin
Binary file not shown.
Binary file added bootloader/ST/cherryuf2_stm32f411ceu6.bin
Binary file not shown.
196 changes: 99 additions & 97 deletions ports/ST/stm32f0xx/boards.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,148 +27,150 @@
//--------------------------------------------------------------------+
// CherryUSB LLD
//--------------------------------------------------------------------+
__attribute__((weak)) void usb_dc_low_level_init(void)
{
/* Peripheral clock enable */
__HAL_RCC_USB_CLK_ENABLE();
/* USB interrupt Init */
HAL_NVIC_SetPriority(USB_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USB_IRQn);
__attribute__((weak)) void usb_dc_low_level_init(void) {
/* Peripheral clock enable */
__HAL_RCC_USB_CLK_ENABLE();
/* USB interrupt Init */
HAL_NVIC_SetPriority(USB_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USB_IRQn);
}

//--------------------------------------------------------------------+
// Boards api
//--------------------------------------------------------------------+
__attribute__((weak)) void board_init(void)
{
clock_init();
SystemCoreClockUpdate();

board_timer_stop();

__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();

GPIO_InitTypeDef GPIO_InitStruct = {0};

GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
__attribute__((weak)) void board_init(void) {
clock_init();
SystemCoreClockUpdate();

board_timer_stop();

__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
#ifdef GPIOD
__HAL_RCC_GPIOD_CLK_ENABLE();
#endif
#ifdef GPIOE
__HAL_RCC_GPIOE_CLK_ENABLE();
#endif
__HAL_RCC_GPIOF_CLK_ENABLE();
#ifdef GPIOG
__HAL_RCC_GPIOG_CLK_ENABLE();
#endif
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();

GPIO_InitTypeDef GPIO_InitStruct = {0};

GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

#ifdef LED_PIN
GPIO_InitStruct.Pin = LED_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
GPIO_InitStruct.Pin = LED_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);

board_led_write(1);
board_led_write(1);
#endif
}

__attribute__((weak)) void board_dfu_complete(void)
{
NVIC_SystemReset();
__attribute__((weak)) void board_dfu_complete(void) {
NVIC_SystemReset();
}

__attribute__((weak)) void board_usb_process(void)
{
// todo
__attribute__((weak)) void board_usb_process(void) {
// todo
}

__attribute__((weak)) bool board_app_valid(void)
{
volatile uint32_t const *app_vector = (volatile uint32_t const *)BOARD_FLASH_APP_START;
__attribute__((weak)) bool board_app_valid(void) {
volatile uint32_t const *app_vector = (volatile uint32_t const *)BOARD_FLASH_APP_START;

// 2nd word is App entry point (reset)
if (app_vector[1] < BOARD_FLASH_APP_START || app_vector[1] > BOARD_FLASH_APP_START + BOARD_FLASH_SIZE)
{
return false;
}
// 2nd word is App entry point (reset)
if (app_vector[1] < BOARD_FLASH_APP_START || app_vector[1] > BOARD_FLASH_APP_START + BOARD_FLASH_SIZE) {
return false;
}

return true;
return true;
}

__attribute__((weak)) void board_app_jump(void)
{
__attribute__((weak)) void board_app_jump(void) {
#ifdef LED_PIN
HAL_GPIO_DeInit(LED_PORT, LED_PIN);
HAL_GPIO_DeInit(LED_PORT, LED_PIN);
#endif

HAL_GPIO_DeInit(GPIOA, GPIO_PIN_12);
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_12);

__HAL_RCC_GPIOA_CLK_DISABLE();
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOC_CLK_DISABLE();
#ifdef GPIOD
__HAL_RCC_GPIOD_CLK_DISABLE();
#endif
#ifdef GPIOE
__HAL_RCC_GPIOE_CLK_DISABLE();
#endif
__HAL_RCC_GPIOF_CLK_DISABLE();
#ifdef GPIOG
__HAL_RCC_GPIOG_CLK_DISABLE();
#endif
__HAL_RCC_USB_CLK_DISABLE();

__HAL_RCC_GPIOA_CLK_DISABLE();
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOC_CLK_DISABLE();
__HAL_RCC_GPIOD_CLK_DISABLE();
__HAL_RCC_GPIOF_CLK_DISABLE();
__HAL_RCC_USB_CLK_DISABLE();
HAL_RCC_DeInit();
HAL_DeInit();

HAL_RCC_DeInit();
HAL_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;

SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
// Disable all Interrupts
NVIC->ICER[0] = 0xFFFFFFFF;
NVIC->ICER[1] = 0xFFFFFFFF;
NVIC->ICER[2] = 0xFFFFFFFF;
NVIC->ICER[3] = 0xFFFFFFFF;

// Disable all Interrupts
NVIC->ICER[0] = 0xFFFFFFFF;
NVIC->ICER[1] = 0xFFFFFFFF;
NVIC->ICER[2] = 0xFFFFFFFF;
NVIC->ICER[3] = 0xFFFFFFFF;
volatile uint32_t const *app_vector = (volatile uint32_t const *)BOARD_FLASH_APP_START;

volatile uint32_t const *app_vector = (volatile uint32_t const *)BOARD_FLASH_APP_START;

__set_MSP(app_vector[0]);
__set_MSP(app_vector[0]);

typedef void (*BootJump_t)(void);
BootJump_t boot_jump = *(BootJump_t *)(BOARD_FLASH_APP_START + 4);
boot_jump();
typedef void (*BootJump_t)(void);
BootJump_t boot_jump = *(BootJump_t *)(BOARD_FLASH_APP_START + 4);
boot_jump();
}

//--------------------------------------------------------------------+
// LED
//--------------------------------------------------------------------+
void board_led_write(uint32_t state)
{
(void)state;
void board_led_write(uint32_t state) {
(void)state;
#ifdef LED_PIN
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON));
#endif
}

//--------------------------------------------------------------------+
// Timer
//--------------------------------------------------------------------+
void board_timer_start(uint32_t ms)
{
SysTick_Config((SystemCoreClock / 1000) * ms);
void board_timer_start(uint32_t ms) {
SysTick_Config((SystemCoreClock / 1000) * ms);
}

void board_timer_stop(void)
{
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
void board_timer_stop(void) {
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
}

void SysTick_Handler(void)
{
board_timer_handler();
void SysTick_Handler(void) {
board_timer_handler();
}

int board_uart_write(void const *buf, int len)
{
(void)buf;
(void)len;
return 0;
int board_uart_write(void const *buf, int len) {
(void)buf;
(void)len;
return 0;
}

void _init(void)
{
}
void _init(void) {}
18 changes: 17 additions & 1 deletion ports/ST/stm32f1xx/boards.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ __attribute__((weak)) void board_init(void) {
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
#ifdef GPIOE
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_SYSCFG_CLK_ENABLE();
#endif
#ifdef GPIOF
__HAL_RCC_GPIOF_CLK_ENABLE();
#endif
#ifdef GPIOG
__HAL_RCC_GPIOG_CLK_ENABLE();
#endif
__HAL_RCC_AFIO_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();

GPIO_InitTypeDef GPIO_InitStruct = {0};
Expand Down Expand Up @@ -103,7 +111,15 @@ __attribute__((weak)) void board_app_jump(void) {
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOC_CLK_DISABLE();
__HAL_RCC_GPIOD_CLK_DISABLE();
#ifdef GPIOE
__HAL_RCC_GPIOE_CLK_DISABLE();
#endif
#ifdef GPIOF
__HAL_RCC_GPIOF_CLK_DISABLE();
#endif
#ifdef GPIOG
__HAL_RCC_GPIOG_CLK_DISABLE();
#endif
__HAL_RCC_AFIO_CLK_DISABLE();
__HAL_RCC_USB_CLK_DISABLE();

Expand Down
8 changes: 8 additions & 0 deletions ports/ST/stm32f4xx/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Port Makefile
PORTS ?= ST
include ../../make.mk
include port.mk
include ../../rules.mk

self-update:
@echo "not implemented yet"
Loading

0 comments on commit 2b48c13

Please sign in to comment.