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

Introduce Bouffalo Lab SoC's #78795

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b169a89
drivers: timer: Enable clic riscv machine timer
nandojve Aug 31, 2024
c71987d
west: Introduce hal bouffalo lab
nandojve Jul 18, 2021
0d79fd0
dts: bindings: vendor-prefixes: Add Bouffalo Lab prefix
nandojve Oct 14, 2024
60d4562
dts: riscv: bouffalolab: Add bl6 series cpu
nandojve Aug 3, 2021
5318a75
soc: riscv: bouffalolab: Add bl6 series cpu
nandojve Aug 3, 2021
d3ac8c9
soc: riscv: bouffalolab: Change to riscv-privileged
nandojve Jan 29, 2024
ba4daeb
drivers: pinctrl: bouffalolab: Add bflb pinctrl driver
nandojve Jan 27, 2024
784efc1
drivers: serial: bouffalolab: Add bflb serial driver
nandojve Aug 3, 2021
df8f88d
drivers: serial: bouffalolab: Add support to interrupts
nandojve Nov 11, 2021
b20d5ad
scripts: runner: Introduce blflash runner
nandojve Aug 7, 2021
2757196
boards: riscv: Introduce bl604e_iot_dvk
nandojve Apr 2, 2022
01828de
west.yml: Drop bouffalolab SDK dependency
VynDragon Aug 31, 2024
b45434d
soc: riscv: Rework bl60x to be SDK independent
VynDragon Aug 31, 2024
d032c73
dts: riscv: bouffalolab: Update bl60x series cpu
VynDragon Aug 31, 2024
902bb4e
drivers: pinctrl: bouffalolab: Update pinctrl driver
VynDragon Aug 31, 2024
dcaf4eb
drivers: gpio: bouffalolab: Add bflb gpio driver
VynDragon Aug 31, 2024
a32c5ce
drivers: serial: bouffalolab: Update serial driver
VynDragon Aug 31, 2024
3173294
scripts: runner: Introduce bflb_mcu_tool runner
VynDragon Aug 31, 2024
a699d4f
boards: riscv: bl604e_iot_dvk: Move to bl60x directory
nandojve Sep 9, 2024
5613e36
scripts: runner: Drop blflash in favor of bflb_mcu_tool
nandojve Sep 9, 2024
6cfc420
MAINTAINERS.yml: Add Bouffalo Lab entries
nandojve Sep 21, 2024
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
2 changes: 1 addition & 1 deletion modules/hal_bouffalolab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ zephyr_library_compile_definitions(
BFLB_USE_CUSTOM_LD_SECTIONS
)

set(bflb_soc ${CONFIG_SOC_SUB_SERIES})
set(bflb_soc ${CONFIG_SOC_SERIES}02)
nandojve marked this conversation as resolved.
Show resolved Hide resolved
set(bflb_drv_dir ${ZEPHYR_HAL_BOUFFALOLAB_MODULE_DIR}/drivers/${bflb_soc}_driver)
set(bflb_common_dir ${ZEPHYR_HAL_BOUFFALOLAB_MODULE_DIR}/common)
set(bflb_drv_src_dir ${bflb_drv_dir}/std_drv/src)
Expand Down
14 changes: 14 additions & 0 deletions modules/hal_bouffalolab/include/bflb_glb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2021-2024 Gerson Fernando Budke <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_HAL_BFLB_GLB_H_
#define ZEPHYR_HAL_BFLB_GLB_H_

#ifdef CONFIG_SOC_SERIES_BL6
#include <bl602_glb.h>
#endif
nandojve marked this conversation as resolved.
Show resolved Hide resolved

#endif /* ZEPHYR_HAL_BFLB_GLB_H_ */
14 changes: 14 additions & 0 deletions modules/hal_bouffalolab/include/bflb_hbn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2021-2024 Gerson Fernando Budke <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_HAL_BFLB_HBN_H_
#define ZEPHYR_HAL_BFLB_HBN_H_

#ifdef CONFIG_SOC_SERIES_BL6
#include <bl602_hbn.h>
#endif
nandojve marked this conversation as resolved.
Show resolved Hide resolved

#endif /* ZEPHYR_HAL_BFLB_HBN_H_ */
6 changes: 6 additions & 0 deletions soc/bouffalolab/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2021-2024 ATL Electronics
#
# SPDX-License-Identifier: Apache-2.0

add_subdirectory(common)
add_subdirectory(${SOC_SERIES})
12 changes: 12 additions & 0 deletions soc/bouffalolab/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2021-2024 ATL Electronics
#
# SPDX-License-Identifier: Apache-2.0

config SOC_FAMILY_BFLB
select HAS_BFLB_HAL

if SOC_FAMILY_BFLB

rsource "*/Kconfig"

endif # SOC_FAMILY_BFLB
9 changes: 9 additions & 0 deletions soc/bouffalolab/Kconfig.defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2021-2024 ATL Electronics
#
# SPDX-License-Identifier: Apache-2.0

if SOC_FAMILY_BFLB

rsource "*/Kconfig.defconfig"

endif # SOC_FAMILY_BFLB
11 changes: 11 additions & 0 deletions soc/bouffalolab/Kconfig.soc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2021-2024 ATL Electronics
#
# SPDX-License-Identifier: Apache-2.0

config SOC_FAMILY_BFLB
bool

config SOC_FAMILY
default "bflb" if SOC_FAMILY_BFLB

rsource "*/Kconfig.soc"
10 changes: 10 additions & 0 deletions soc/bouffalolab/bl6/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2021-2024 ATL Electronics
#
# SPDX-License-Identifier: Apache-2.0

zephyr_include_directories(.)
zephyr_sources(soc.c)

zephyr_linker_sources_ifdef(CONFIG_SOC_SERIES_BL6 RODATA rodata.ld)

set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/riscv/common/linker.ld CACHE INTERNAL "")
21 changes: 21 additions & 0 deletions soc/bouffalolab/bl6/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2021-2024 ATL Electronics
#
# SPDX-License-Identifier: Apache-2.0

config SOC_SERIES_BL6
select RISCV
select RISCV_HAS_CPU_IDLE
select RISCV_MACHINE_TIMER
select ATOMIC_OPERATIONS_C
select COMPRESSED_ISA
select CPU_HAS_FPU
select INCLUDE_RESET_VECTOR
select SOC_EARLY_INIT_HOOK
select XIP

select RISCV_ISA_RV32I
select RISCV_ISA_EXT_M
select RISCV_ISA_EXT_A
select RISCV_ISA_EXT_C
select RISCV_ISA_EXT_ZICSR
select RISCV_ISA_EXT_ZIFENCEI
13 changes: 13 additions & 0 deletions soc/bouffalolab/bl6/Kconfig.defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2021-2024 ATL Electronics
#
# SPDX-License-Identifier: Apache-2.0

if SOC_SERIES_BL6

config SYS_CLOCK_HW_CYCLES_PER_SEC
default 192000000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grab from DT

Copy link
Member Author

@nandojve nandojve Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On SiFive e24, mtime is a fixed 1 000 000 per second rate. The riscv_machine_timer uses mtime as if it was mcycle and expects. This is what is configured.

However, to make the SDK 1.4.2 version to work it is necessary to keep this way. If I try to get from devicetree the build fails.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this not in dts properly then?


config NUM_IRQS
default 64

endif # SOC_SERIES_BL6
nandojve marked this conversation as resolved.
Show resolved Hide resolved
49 changes: 49 additions & 0 deletions soc/bouffalolab/bl6/Kconfig.soc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (c) 2021-2024 ATL Electronics
#
# SPDX-License-Identifier: Apache-2.0

config SOC_SERIES_BL6
bool
select SOC_FAMILY_BFLB
help
Enable support for BouffaloLab BL6xx MCU series

config SOC_SERIES
default "bl6" if SOC_SERIES_BL6

config SOC_BL602C00Q2I
bool
select SOC_SERIES_BL6

config SOC_BL602C20Q2I
bool
select SOC_SERIES_BL6

config SOC_BL602C20Q2IS
bool
select SOC_SERIES_BL60X

config SOC_BL602C40Q2IS
bool
select SOC_SERIES_BL60X

config SOC_BL602l10Q2H
bool
select SOC_SERIES_BL60X

config SOC_BL602l20Q2H
bool
select SOC_SERIES_BL60X

config SOC_BL604E20Q2I
bool
select SOC_SERIES_BL6

config SOC
default "bl602c00q2i" if SOC_BL602C00Q2I
default "bl602c20q2i" if SOC_BL602C20Q2I
default "bl602c20q2is" if SOC_BL602C20Q2IS
default "bl602c40q2is" if SOC_BL602C40Q2IS
default "bl602l10q2h" if SOC_BL602l10Q2H
default "bl602l20q2h" if SOC_BL602l20Q2H
default "bl604e20q2i" if SOC_BL604E20Q2I
17 changes: 17 additions & 0 deletions soc/bouffalolab/bl6/rodata.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2021-2024 ATL Electronics
*
* SPDX-License-Identifier: Apache-2.0
*/

KEEP(*(SORT_NONE( EXCLUDE_FILE( *bl602_glb.o \
*bl602_pds.o \
*bl602_common.o \
*bl602_sf_cfg.o \
*bl602_sf_cfg_ext*.o* \
*bl602_sf_ctrl.o \
*bl602_sflash.o \
*bl602_sflash_ext*.o* \
*bl602_xip_sflash.o \
*bl602_xip_sflash_ext*.o* \
*bl602_ef_ctrl.o) .rodata*)))
126 changes: 126 additions & 0 deletions soc/bouffalolab/bl6/soc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright (c) 2021-2024 ATL Electronics
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file
* @brief Bouffalo Lab RISC-V MCU series initialization code
*/

#include <zephyr/device.h>
#include <zephyr/init.h>
#include <zephyr/irq.h>

#include <bflb_hbn.h>
#include <bflb_glb.h>
#include <clic.h>

/* clang-format off */
nandojve marked this conversation as resolved.
Show resolved Hide resolved

#define ROOT_FCLK_DIV (0)
#define ROOT_BCLK_DIV (1)
#define ROOT_UART_CLOCK_DIV (0)

static void system_bor_init(void)
{
HBN_BOR_CFG_Type borCfg = { 1 /* pu_bor */, 0 /* irq_bor_en */,
1 /* bor_vth */, 1 /* bor_sel */ };
HBN_Set_BOR_Cfg(&borCfg);
}

static uint32_t mtimer_get_clk_src_div(void)
{
return ((SystemCoreClockGet() / (GLB_Get_BCLK_Div() + 1))
/ 1000 / 1000 - 1);
}

static void system_clock_init(void)
{
GLB_Set_System_CLK(GLB_PLL_XTAL_40M, GLB_SYS_CLK_PLL160M);
GLB_Set_System_CLK_Div(ROOT_FCLK_DIV, ROOT_BCLK_DIV);
GLB_Set_MTimer_CLK(1, GLB_MTIMER_CLK_BCLK, mtimer_get_clk_src_div());
}

static void peripheral_clock_init(void)
{
GLB_Set_UART_CLK(1, HBN_UART_CLK_160M, ROOT_UART_CLOCK_DIV);
}

void soc_early_init_hook(void)
{
uint32_t key;
uint32_t *p;
uint32_t i = 0;
uint32_t tmp = 0;

key = irq_lock();

__disable_irq();

/* disable hardware_pullup_pull_down (reg_en_hw_pu_pd = 0) */
tmp = BL_RD_REG(HBN_BASE, HBN_IRQ_MODE);
tmp = BL_CLR_REG_BIT(tmp, HBN_REG_EN_HW_PU_PD);
BL_WR_REG(HBN_BASE, HBN_IRQ_MODE, tmp);

/* GLB_Set_EM_Sel(GLB_EM_0KB); */
tmp = BL_RD_REG(GLB_BASE, GLB_SEAM_MISC);
tmp = BL_SET_REG_BITS_VAL(tmp, GLB_EM_SEL, GLB_EM_0KB);
BL_WR_REG(GLB_BASE, GLB_SEAM_MISC, tmp);

/* Fix 26M xtal clkpll_sdmin */
tmp = BL_RD_REG(PDS_BASE, PDS_CLKPLL_SDM);

if (BL_GET_REG_BITS_VAL(tmp, PDS_CLKPLL_SDMIN) == 0x49D39D) {
tmp = BL_SET_REG_BITS_VAL(tmp, PDS_CLKPLL_SDMIN, 0x49D89E);
BL_WR_REG(PDS_BASE, PDS_CLKPLL_SDM, tmp);
}

/* Restore default setting*/

/* GLB_UART_Sig_Swap_Set(UART_SIG_SWAP_NONE); */
tmp = BL_RD_REG(GLB_BASE, GLB_PARM);
tmp = BL_SET_REG_BITS_VAL(tmp, GLB_UART_SWAP_SET, UART_SIG_SWAP_NONE);
BL_WR_REG(GLB_BASE, GLB_PARM, tmp);

/* GLB_JTAG_Sig_Swap_Set(JTAG_SIG_SWAP_NONE); */
tmp = BL_RD_REG(GLB_BASE, GLB_PARM);
tmp = BL_SET_REG_BITS_VAL(tmp, GLB_JTAG_SWAP_SET, JTAG_SIG_SWAP_NONE);
BL_WR_REG(GLB_BASE, GLB_PARM, tmp);

/* CLear all interrupt */
p = (uint32_t *)(CLIC_HART0_ADDR + CLIC_INTIE);

for (i = 0; i < (IRQn_LAST + 3) / 4; i++) {
p[i] = 0;
}

p = (uint32_t *)(CLIC_HART0_ADDR + CLIC_INTIP);

for (i = 0; i < (IRQn_LAST + 3) / 4; i++) {
p[i] = 0;
}

/* init bor for all platform */
system_bor_init();
/* global IRQ enable */
__enable_irq();

system_clock_init();
peripheral_clock_init();

irq_unlock(key);
}

/* identify flash config automatically */
extern BL_Err_Type flash_init(void);

void System_Post_Init(void)
{
PDS_Trim_RC32M();
HBN_Trim_RC32K();
flash_init();
}

/* clang-format on */
49 changes: 49 additions & 0 deletions soc/bouffalolab/bl6/soc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2021-2024 ATL Electronics
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file
* @brief Board configuration macros
*
* This header file is used to specify and describe board-level aspects
*/

#ifndef _SOC__H_
nandojve marked this conversation as resolved.
Show resolved Hide resolved
#define _SOC__H_

#include <zephyr/sys/util.h>
#include <../common/soc_common.h>

#ifndef _ASMLANGUAGE

/* Add include for DTS generated information */
#include <zephyr/devicetree.h>

#if defined(CONFIG_SOC_SERIES_BL6)
#include <bl602.h>
#else
#error Library does not support the specified device.
#endif

/* clang-format off */

/* RISC-V Machine Timer configuration */
#define RISCV_MTIME_BASE 0x0200BFF8
#define RISCV_MTIMECMP_BASE 0x02004000

/* lib-c hooks required RAM defined variables */
#define RISCV_RAM_BASE DT_SRAM_BASE_ADDRESS
#define RISCV_RAM_SIZE KB(DT_SRAM_SIZE)

#define SOC_BOUFFALOLAB_BL_PLL160_FREQ_HZ (160000000)
#define SOC_BOUFFALOLAB_BL_HCLK_FREQ_HZ \
DT_PROP(DT_PATH(cpus, cpu_0), clock_frequency)

/* clang-format on */

#endif /* !_ASMLANGUAGE */

#endif /* _SOC__H_ */
11 changes: 11 additions & 0 deletions soc/bouffalolab/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2021-2024 ATL Electronics
#
# SPDX-License-Identifier: Apache-2.0

zephyr_include_directories(.)

zephyr_sources(
soc_irq.S
soc_common_irq.c
vector.S
)
Loading