Skip to content

Make BFLB not use the SDK code #91977

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

VynDragon
Copy link
Collaborator

What's in the title.

Large update that cannot be cut without breaking functionality.

Some drivers are getting entirely revamped, such as uart and pinctrl, do not consider those as updates of the older drivers, but rather new drivers (which is true to some large extent).

@VynDragon VynDragon requested a review from nandojve June 21, 2025 19:54
@VynDragon VynDragon changed the title Make BFLB not used the SDK code Make BFLB not use the SDK code Jun 21, 2025
@VynDragon VynDragon force-pushed the bl60x_nosdk branch 5 times, most recently from 6e0c76d to f2a098f Compare June 21, 2025 20:59
@kartben kartben requested a review from Copilot July 6, 2025 16:14
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes reliance on the Bouffalo Lab SDK code and replaces it with custom, in-tree drivers and build logic tailored for the BL60x series.

  • Deletes legacy vector, IRQ, and common interrupt files in favor of new “e24” implementations
  • Updates SOC headers and initialization routines to use sys_read32/sys_write32 instead of HAL wrappers
  • Overhauls the UART and pinctrl drivers, Kconfig, CMakeLists, and DTS bindings for custom flash partition support

Reviewed Changes

Copilot reviewed 42 out of 42 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
soc/bflb/common/vector.S Removed legacy reset vector assembly
soc/bflb/common/soc_irq.S Removed old IRQ handler assembly
soc/bflb/common/soc_common_irq.c Deleted common CLIC-based interrupt code
soc/bflb/common/soc_common.h Removed shared interrupt number definitions
soc/bflb/common/e24/soc_irq_privileged.c Added new privileged IRQ driver
soc/bflb/common/e24/intc_clic.S Added CLIC interrupt assembly hooks
soc/bflb/common/e24/clic.h Defined new CLIC CSR registers
soc/bflb/common/CMakeLists.txt Switched source inclusion to e24 under BL60x
soc/bflb/bl60x/soc.h Dropped SDK header include; now minimal SOC defs
soc/bflb/bl60x/soc.c Rewrote early init to use sys_read32/sys_write32
soc/bflb/bl60x/CMakeLists.txt Updated linker script and code relocation calls
modules/hal_bouffalolab/{include,src,CMakeLists} Removed SDK HAL headers/sources; simplified include paths
drivers/serial/uart_bflb.c Major rewrite to use register‐access APIs
drivers/pinctrl/pinctrl_bflb[.c,_bl60x_70x.c] Switched pinctrl logic to sys_read32/sys_write32
drivers/clock_control/clock_control_bl60x.c Increased NOP settle loops; moved settle call
dts/riscv/bflb/bl60x.dtsi Updated interrupt-parent to CLIC and flash dividers
boards/**/*.dts Replaced legacy SPI controller with flash partitions
boards/**/support/*.cfg Adjusted OpenOCD adapter speeds and reset regs
Comments suppressed due to low confidence (1)

modules/hal_bouffalolab/CMakeLists.txt:6

  • This block now only adds include directories and no longer compiles any HAL sources for Bouffalo Lab, likely disabling all HAL functionality. Restore zephyr_library_sources for enabled modules or adjust the condition.
if(CONFIG_SOC_FAMILY_BFLB)

@@ -4,8 +4,9 @@

zephyr_include_directories(.)

if(CONFIG_SOC_SERIES_BL60X)
Copy link
Preview

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

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

Removing vector.S, soc_irq.S, and soc_common_irq.c unconditionally and only adding e24 sources under CONFIG_SOC_SERIES_BL60X will break startup and IRQ handling for non-BL60X SoCs. Consider wrapping legacy sources in an else block or guarding removals similarly.

Copilot uses AI. Check for mistakes.

PINCTRL_DT_INST_DEFINE(n); \

#define BFLB_UART_INIT(instance) \
PINCTRL_DT_INST_DEFINE(instance); \
PM_DEVICE_DT_INST_DEFINE(n, uart_bflb_pm_control); \
Copy link
Preview

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

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

The BFLB_UART_INIT macro uses n here instead of the macro parameter instance, causing incorrect device definitions. Replace n with instance.

Suggested change
PM_DEVICE_DT_INST_DEFINE(n, uart_bflb_pm_control); \
PM_DEVICE_DT_INST_DEFINE(instance, uart_bflb_pm_control); \

Copilot uses AI. Check for mistakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

+ BFLB_PINMUX_GET_SIGNAL(pins[i])
);

if ((BFLB_PINMUX_GET_FUN(pins[i]) & 0xFF) == BFLB_PINMUX_FUN_INST_uart0) {
Copy link
Preview

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

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

[nitpick] Masking with 0xFF to extract function bits is a magic operation. Consider defining a named constant or helper to clarify the intent and ensure future compatibility.

Suggested change
if ((BFLB_PINMUX_GET_FUN(pins[i]) & 0xFF) == BFLB_PINMUX_FUN_INST_uart0) {
if ((BFLB_PINMUX_GET_FUN(pins[i]) & BFLB_PINMUX_FUN_MASK) == BFLB_PINMUX_FUN_INST_uart0) {

Copilot uses AI. Check for mistakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@nandojve
Copy link
Member

nandojve commented Jul 6, 2025

Because merely having the sdk built (and so having the pinctrl driver from it) is likely to break everything else, then everything is interdependent (uart needs clock control working, interrupts need soc update, etc), and mostly i don't want to spend 5-10 hours working out a transition that reduces the review time by ~10 minutes (or rather the idea of the review time, because imo having a coherent changeset and not having to check 3 different sets make it faster), at some point demands got to be symmetrical, and I highly doubt any reviewer beside you will do anything but quickly check over the code.

Also looking at other sets, it's not even big for basically reintroducing a SoC

Unless you have crystal ball or a oracle you should not try to guess people opinions.

Copy link
Member

@nandojve nandojve left a comment

Choose a reason for hiding this comment

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

Your sequence do not bisect. You must fixed.

Comment on lines 14 to 18
#if defined(CONFIG_SOC_SERIES_BL60X)
#include <zephyr/dt-bindings/pinctrl/bl60x-pinctrl.h>
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Add an else to generate an error

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@VynDragon
Copy link
Collaborator Author

VynDragon commented Jul 6, 2025

Your sequence do bisect. You must fixed.

What does that mean here?

@VynDragon VynDragon force-pushed the bl60x_nosdk branch 3 times, most recently from d70de46 to 4a5f872 Compare July 6, 2025 17:36
@nandojve
Copy link
Member

nandojve commented Jul 6, 2025

Your sequence do bisect. You must fixed.

What does that mean here?

Each commit must build individually otherwise you broke the git bisect operation.

@VynDragon
Copy link
Collaborator Author

VynDragon commented Jul 6, 2025

Your sequence do bisect. You must fixed.

What does that mean here?

Each commit must build individually otherwise you broke the git bisect operation.

Yea it's easier to get once the english is fixed.

Why do you think those commits are inseparable? They cannot be made to compile in separate PRs, they cannot be made to compile individually, would you rather I squash them?


/* Disable output anyway */
regval = sys_read32(GLB_BASE + GLB_GPIO_CFGCTL34_OFFSET + ((real_pin >> 5) << 2));
regval &= ~(1 << (pin & 0x1f));
Copy link
Collaborator

Choose a reason for hiding this comment

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

real_pin?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

uh, yea? Would you prefer something like 'pin_number' ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nah I mean this line should be s/pin/real_pin/?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pin is already used as the input to the function, this is the pin number extracted from that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah no wait sorry, let me check. 1f should be function

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You were correct, it's the output enable setting by pin number and it's a overflow prevention mask.


if (data->user_cb) {
data->user_cb(dev, data->user_data);
}
/* clear interrupts that require ack*/
tmp = sys_read32(cfg->base_reg + UART_INT_CLEAR_OFFSET);
tmp = tmp | UART_CR_URX_RTO_CLR;
Copy link
Collaborator

@kartben kartben Jul 7, 2025

Choose a reason for hiding this comment

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

I think there's more that needs clearing, e.g. you've enabled PCE so UART_CR_URX_PCE_CLR ; probably UART_CR_URX_END_CLR and UART_CR_UTX_END_CLR as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay no, deleted message was right but i looked at the wrong place UART_CR_URX_END_CLR and UART_CR_UTX_END_CLR 's interrupts should be masked and UART_CR_URX_PCE_CLR is handled in uart_bflb_err_check

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(masked = interrupt not thrown to CPU, but i think it was required for working?)

Comment on lines 25 to 32
void riscv_clic_irq_priority_set(unsigned int irq, unsigned int prio, uint32_t flags)
{
ARG_UNUSED(irq);
ARG_UNUSED(prio);
ARG_UNUSED(flags);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

would be good to document why it's not being implemented? Or... should it be implemented?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It should probably yes, will look into it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Shell sample isnt working on this PR while it should anyway so i have some checks to do...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It works with debugger.... uuuurgh

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixing this has had the knock-off effect of somehow fixing the shell sample without the little wait I just added... Sometimes I really dont understand those chips...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment on lines 196 to 200
tmp = sys_read32(cfg->base_reg + UART_STATUS_OFFSET);
rc = tmp & UART_STS_UTX_BUS_BUSY;
tmp = sys_read32(cfg->base_reg + UART_FIFO_CONFIG_1_OFFSET);
rc += tmp & UART_TX_FIFO_CNT_MASK;
return (rc > 0 ? 1 : 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think you have the logic backwards?
irq_tx_complete returns 1 If nothing remains to be transmitted ; 0 If transmission is not completed.

tx is probably not complete if UART_STS_UTX_BUS_BUSY is set or if FIFO still contains data?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds like it yes

Copy link
Collaborator Author

@VynDragon VynDragon Jul 7, 2025

Choose a reason for hiding this comment

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

Done

Note tx fifo count is inverted, it counts free bytes.

Comment on lines +127 to +144
int uart_bflb_irq_tx_ready(const struct device *dev)
{
const struct bflb_config *const cfg = dev->config;
uint32_t tmp = 0;

tmp = sys_read32(cfg->base_reg + UART_FIFO_CONFIG_1_OFFSET);
return (tmp & UART_TX_FIFO_CNT_MASK) > 0;
}

int uart_bflb_irq_rx_ready(const struct device *dev)
{
const struct bflb_config *const cfg = dev->config;
uint32_t tmp = 0;

tmp = sys_read32(cfg->base_reg + UART_FIFO_CONFIG_1_OFFSET);
return (tmp & UART_RX_FIFO_CNT_MASK) > 0;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

you've setup thresholds so raw count shouldn't be used? I think this should instead check if UART_URX_FIFO_INT / UART_UTX_FIFO_INT are set/pending.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These interrupts are masked, functionally it's the same (And there might have been a reason, interrupts gave me, and continue to give me, a lot of trouble on this platform, I wouldnt remember but it's possible there was issues doing it with the interrupt).

reg mstatus 0x7800
reg mie 0x0
# reg pc 0x23000000
reg mstatus 0x80000000
Copy link
Collaborator

Choose a reason for hiding this comment

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

bit 31 of mstatus is read-only?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure where that's from, I see the same, maybe 0x0 is more appropriate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

VynDragon added 4 commits July 7, 2025 12:40
Reorganize and update soc folder files for SDK-independance

Signed-off-by: Camille BAUD <mail@massdriver.space>
Reorganize and update hal_bouffalolab files for SDK-independance

Signed-off-by: Camille BAUD <mail@massdriver.space>
Reorganize and update soc files for SDK-independance

Signed-off-by: Camille BAUD <mail@massdriver.space>
Update driver file for SDK-independance

Signed-off-by: Camille BAUD <mail@massdriver.space>
VynDragon added 5 commits July 7, 2025 13:32
Update driver file for SDK-independance

Signed-off-by: Camille BAUD <mail@massdriver.space>
mostly makes things a little bit safer

Signed-off-by: Camille BAUD <mail@massdriver.space>
Update to new bl60x support and fixup openocd config

Signed-off-by: Camille BAUD <mail@massdriver.space>
Update to new bl60x support

Signed-off-by: Camille BAUD <mail@massdriver.space>
update to new bl60x support

Signed-off-by: Camille BAUD <mail@massdriver.space>
Copy link

sonarqubecloud bot commented Jul 7, 2025

@VynDragon VynDragon requested review from kartben and nandojve July 10, 2025 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants