Skip to content

Commit c3b8e49

Browse files
committed
Use C++-ified regs but port_pin still needed
1 parent 5ef4f9e commit c3b8e49

4 files changed

Lines changed: 49 additions & 23 deletions

File tree

readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ The reference application supports the following targets (in alpha-numeric order
7676
| `atmega4809` | MICROCHIP(R) [former ATMEL(R)] AVR(R) ATmegax4809 | X |
7777
| `avr` (as used in the book) | MICROCHIP(R) [former ATMEL(R)] AVR(R) ATmega328P | X |
7878
| `bcm2835_raspi_b` | RaspberryPi(R) Zero with ARM1176-JZFS(TM) | X |
79+
| `bl602_sifive_e24_riscv` | BL602 single-core RISC-V (SiFive E24) | X |
7980
| `Debug`/`Release` | PC on `Win*` via MSVC x64 compiler `Debug`/`Release` | |
8081
| `host` | PC/Workstation on `Win*`/`mingw64`/`*nix` via host compiler | |
8182
| `lpc11c24` | NXP(R) OM13093 LPC11C24 board ARM(R) Cortex(R)-M0+ | |
@@ -415,6 +416,13 @@ called `target avr` (as used in the book) runs
415416
on a classic ARDUINO(R) compatible board.
416417
The program toggles the yellow LED on `portb.5`.
417418

419+
Target `bl602_sifive_e24_riscv` contains a fully manually-written bare-metal project
420+
for the BL602 single-core RISC-V (SiFive E24), making no use of any SDK.
421+
The boot code and bare-metal register interactions are based
422+
on the creative work in
423+
[`Chalandi/Baremetal_BL602_SiFive_E24_RISC-V`](https://github.com/Chalandi/Baremetal_BL602_SiFive_E24_RISC-V).
424+
This configuration toggles pin `IO3` and requires a self-fitted LED.
425+
418426
The ARM(R) 1176-JZF-S configuration (called `target bcm2835_raspi_b`) runs on the
419427
RaspberryPi(R) Zero (PiZero) single core controller.
420428
This project creates a bare-metal program for the PiZero.

ref_app/src/mcal/bl602_sifive_e24_riscv/BL602.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef BL602_H
33
#define BL602_H
44

5+
#if 0
56
#include "stdint.h"
67

78
#ifdef __cplusplus
@@ -1150,4 +1151,6 @@ typedef struct { /*!< glb Structure
11501151
}
11511152
#endif
11521153

1154+
#endif
1155+
11531156
#endif /* BL602_H */

ref_app/src/mcal/bl602_sifive_e24_riscv/mcal_led.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,52 @@
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
66
//
77

8-
#include <mcal_led.h>
98
#include <mcal_led/mcal_led_boolean_state_base.h>
9+
#include <mcal_led.h>
1010
#include <mcal_reg.h>
1111
#include <util/utility/util_time.h>
1212

13-
#include "BL602.h"
14-
15-
#include <cstdint>
13+
namespace
14+
{
15+
constexpr std::uint32_t GPIO_FUN_SDIO { UINT32_C( 1) };
16+
constexpr std::uint32_t GPIO_FUN_FLASH { UINT32_C( 2) };
17+
constexpr std::uint32_t GPIO_FUN_SPI { UINT32_C( 4) };
18+
constexpr std::uint32_t GPIO_FUN_I2C { UINT32_C( 6) };
19+
constexpr std::uint32_t GPIO_FUN_UART { UINT32_C( 7) };
20+
constexpr std::uint32_t GPIO_FUN_PWM { UINT32_C( 8) };
21+
constexpr std::uint32_t GPIO_FUN_EXT_PA { UINT32_C( 9) };
22+
constexpr std::uint32_t GPIO_FUN_ANALOG { UINT32_C(10) };
23+
constexpr std::uint32_t GPIO_FUN_SWGPIO { UINT32_C(11) };
24+
constexpr std::uint32_t GPIO_FUN_JTAG { UINT32_C(14) };
25+
} // anonymous namespace
1626

1727
class led_port_tmp_bl606 : public mcal::led::led_boolean_state_base
1828
{
1929
public:
2030
led_port_tmp_bl606() noexcept
2131
{
22-
/* configure IO3 as output */
23-
glb->GPIO_CFGCTL1.bit.reg_gpio_3_func_sel = GPIO_FUN_SWGPIO;
24-
glb->GPIO_CFGCTL1.bit.reg_gpio_3_ie = 0ul;
25-
glb->GPIO_CFGCTL1.bit.reg_gpio_3_drv = 0ul;
26-
glb->GPIO_CFGCTL1.bit.reg_gpio_3_smt = 0ul;
27-
glb->GPIO_CFGCTL34.bit.reg_gpio_3_oe = 1ul;
32+
// Configure IO3 as output, low.
33+
// glb->GPIO_CFGCTL1.bit.reg_gpio_3_func_sel = GPIO_FUN_SWGPIO;
34+
// glb->GPIO_CFGCTL1.bit.reg_gpio_3_ie = 0ul;
35+
// glb->GPIO_CFGCTL1.bit.reg_gpio_3_smt = 0ul;
36+
// glb->GPIO_CFGCTL1.bit.reg_gpio_3_drv = 0ul;
37+
// glb->GPIO_CFGCTL34.bit.reg_gpio_3_oe = 1ul;
38+
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, mcal::reg::gpio_cfgctl1, static_cast<std::uint32_t>(GPIO_FUN_SWGPIO << 24U)>::template reg_msk<static_cast<std::uint32_t>(UINT32_C(0xF) << 24U)>();
39+
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, mcal::reg::gpio_cfgctl1, UINT32_C(16)>::bit_clr();
40+
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, mcal::reg::gpio_cfgctl1, UINT32_C(17)>::bit_clr();
41+
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, mcal::reg::gpio_cfgctl1, UINT32_C(0) << 18U>::template reg_msk<UINT32_C(3) << 18U>();
42+
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, mcal::reg::gpio_cfgctl34, UINT32_C(3)>::bit_set();
2843
}
2944

3045
~led_port_tmp_bl606() override = default;
3146

3247
auto toggle() noexcept -> void override
3348
{
34-
using base_class_type = led_boolean_state_base;
35-
3649
// Toggle the IO3 pin.
50+
// glb->GPIO_CFGCTL32.bit.reg_gpio_3_o ^= 1ul;
3751
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, mcal::reg::gpio_cfgctl32, UINT32_C(3)>::bit_not();
38-
//glb->GPIO_CFGCTL32.bit.reg_gpio_3_o ^= 1ul;
52+
53+
using base_class_type = led_boolean_state_base;
3954

4055
base_class_type::toggle();
4156
}

ref_app/src/mcal/bl602_sifive_e24_riscv/mcal_reg.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
constexpr std::uintptr_t clic_clk_gate { clic_ctrl_addr + UINT32_C(0x007FF000) };
2323

2424
constexpr std::uintptr_t glb_base { UINT32_C(0x40000000) };
25-
constexpr std::uintptr_t gpio_cfgctl0 { glb_base + UINT32_C(0x40) };
26-
constexpr std::uintptr_t gpio_cfgctl1 { glb_base + UINT32_C(0x44) };
27-
constexpr std::uintptr_t gpio_cfgctl2 { glb_base + UINT32_C(0x48) };
28-
constexpr std::uintptr_t gpio_cfgctl3 { glb_base + UINT32_C(0x4C) };
29-
constexpr std::uintptr_t gpio_cfgctl4 { glb_base + UINT32_C(0x50) };
30-
constexpr std::uintptr_t gpio_cfgctl30 { glb_base + UINT32_C(0x180) };
31-
constexpr std::uintptr_t gpio_cfgctl31 { glb_base + UINT32_C(0x184) };
32-
constexpr std::uintptr_t gpio_cfgctl32 { glb_base + UINT32_C(0x188) };
33-
constexpr std::uintptr_t gpio_cfgctl33 { glb_base + UINT32_C(0x18C) };
34-
constexpr std::uintptr_t gpio_cfgctl34 { glb_base + UINT32_C(0x190) };
25+
constexpr std::uintptr_t gpio_cfgctl0 { glb_base + UINT32_C(0x00000100) };
26+
constexpr std::uintptr_t gpio_cfgctl1 { glb_base + UINT32_C(0x00000104) };
27+
constexpr std::uintptr_t gpio_cfgctl2 { glb_base + UINT32_C(0x00000108) };
28+
constexpr std::uintptr_t gpio_cfgctl3 { glb_base + UINT32_C(0x0000010C) };
29+
constexpr std::uintptr_t gpio_cfgctl4 { glb_base + UINT32_C(0x00000104) };
30+
constexpr std::uintptr_t gpio_cfgctl30 { glb_base + UINT32_C(0x00000180) };
31+
constexpr std::uintptr_t gpio_cfgctl31 { glb_base + UINT32_C(0x00000184) };
32+
constexpr std::uintptr_t gpio_cfgctl32 { glb_base + UINT32_C(0x00000188) };
33+
constexpr std::uintptr_t gpio_cfgctl33 { glb_base + UINT32_C(0x0000018C) };
34+
constexpr std::uintptr_t gpio_cfgctl34 { glb_base + UINT32_C(0x00000190) };
3535
}
3636
}
3737

0 commit comments

Comments
 (0)