Skip to content

Commit c5debfe

Browse files
authored
Merge pull request #628 from ckormanyos/esp32s3_cop_pwm_led
LED dimming show RISC-V-ULP processor
2 parents 6f52c50 + 3cd8182 commit c5debfe

8 files changed

Lines changed: 154 additions & 126 deletions

File tree

readme.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,17 @@ features a bare-metal startup _without_ using any of the SDK.
403403
The bare-metal startup was taken from the work of
404404
[Chalandi/Baremetal_esp32s3_nosdk](https://github.com/Chalandi/Baremetal_esp32s3_nosdk).
405405
The multicore system first boots core0 which subsequently
406-
starts up core1 and also starts up the RISCV coprocessor core.
406+
starts up core1 and also starts up the RISC-V-ULP coprocessor core.
407407
Blinky runs in the standard `ref_app`
408408
on core0 toggling `port7` while an endless timer loop on core1
409409
toggles `port6`. These LED ports togle in near unison
410410
at the normal blinky feequency of $\frac{1}{2}~\text{Hz}$.
411-
The RISCV coprocessor toggles `port17` at a randomly chosen
412-
frequency slightly higher than that of the regular blinky show.
411+
The RISC-V-ULP coprocessor performs an LED dimming
412+
show on `port17` at a randomly chosen frequency
413+
that is asynchronous to the regular blinky show.
413414
Self-procured LEDs and resistors need to be fitted externally
414-
on the port pins in order to observe blinking on this particular board.
415+
on the port pins in order to observe blinking and dimming
416+
on this particular board.
415417

416418
The NXP(R) OM13093 LPC11C24 board ARM(R) Cortex(R)-M0+ configuration
417419
called `target lpc11c24` toggles the LED on `port0.8`.

ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_port.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
static auto set_direction_output() -> void
3131
{
3232
mcal::reg::reg_access_static<std::uint32_t, std::uint32_t, io_rtc_padxx_reg, UINT32_C(19)>::bit_set();
33-
mcal::reg::reg_access_static<std::uint32_t, std::uint32_t, gpio_pinxx_reg, UINT32_C(0)>::reg_set();
3433

3534
// Set the pin to output low.
3635
mcal::reg::reg_access_static<std::uint32_t, std::uint32_t, mcal::reg::gpio::rtc_gpio_out_reg, std::uint32_t { UINT32_C(10) + bpos }>::bit_clr();

ref_app/target/micros/xtensa_esp32_s3/startup/coprocessor_binary.S

Lines changed: 89 additions & 85 deletions
Large diffs are not rendered by default.

ref_app/target/micros/xtensa_esp32_s3_riscv_cop/make/xtensa_esp32_s3_riscv_cop.ld

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ SECTIONS
6060
. = ALIGN(4);
6161
*(.rodata*)
6262
. = ALIGN(4);
63-
PROVIDE(__INTVECT_BASE_ADDRESS = .);
64-
*(.intvect_core*)
65-
. = ALIGN(4);
6663
} > D_SRAM
6764

6865
/* Section for constructors */

ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Appli/main.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <mcal_led.h>
2828
#include <mcal_port.h>
2929

30-
extern "C" void main();
30+
extern "C" auto main() -> int;
3131

3232
namespace mcal
3333
{
@@ -44,25 +44,47 @@ namespace
4444
{
4545
volatile std::uint32_t main_counter { };
4646

47-
auto delay() -> void
47+
auto delay(const std::uint32_t loop_count) -> void
4848
{
49-
constexpr std::uint32_t loop_count{ UINT32_C(0x00060000) };
50-
51-
for (std::uint32_t loop{ UINT32_C(0) }; loop < loop_count; ++loop)
49+
for (std::uint32_t loop { UINT32_C(0) }; loop < loop_count; ++loop)
5250
{
5351
main_counter = std::uint32_t { main_counter + UINT8_C(1) };
5452
}
5553
}
5654
}
5755

58-
extern "C" void main()
56+
extern "C" auto main() -> int
5957
{
6058
mcal::init();
6159

60+
unsigned prescaler { UINT8_C(0) };
61+
unsigned cycle { UINT8_C(0) };
62+
6263
for(;;)
6364
{
64-
mcal::led::led0().toggle();
65+
switch(unsigned { cycle % unsigned { UINT8_C(16) } })
66+
{
67+
case unsigned { UINT8_C( 0) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C(60) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 4) }); break;
68+
case unsigned { UINT8_C( 1) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C(32) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C(32) }); break;
69+
case unsigned { UINT8_C( 2) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 8) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C(56) }); break;
70+
case unsigned { UINT8_C( 3) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 6) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C(58) }); break;
71+
case unsigned { UINT8_C( 4) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 4) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C(60) }); break;
72+
case unsigned { UINT8_C( 5) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 3) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C(61) }); break;
73+
case unsigned { UINT8_C( 6) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 2) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C(62) }); break;
74+
case unsigned { UINT8_C( 7) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 1) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C(63) }); break;
75+
case unsigned { UINT8_C( 8) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 1) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C(60) }); break;
76+
case unsigned { UINT8_C( 9) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 2) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C(32) }); break;
77+
case unsigned { UINT8_C(10) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 3) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 8) }); break;
78+
case unsigned { UINT8_C(11) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 4) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 6) }); break;
79+
case unsigned { UINT8_C(12) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 6) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 4) }); break;
80+
case unsigned { UINT8_C(13) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 8) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 3) }); break;
81+
case unsigned { UINT8_C(14) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C(32) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 2) }); break;
82+
case unsigned { UINT8_C(15) }: mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C(60) }); mcal::led::led0().toggle(); delay(std::uint32_t { UINT8_C( 1) }); break;
83+
}
6584

66-
delay();
85+
if(unsigned { ++prescaler % unsigned { UINT8_C(1024) } } == unsigned { UINT8_C(0) })
86+
{
87+
++cycle;
88+
}
6789
}
6890
}

ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/IntVectTable.S

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,39 @@
88
// Originally from:
99
/******************************************************************************************
1010
Filename : IntVectTable.S
11-
11+
1212
Core : RISC-V
13-
13+
1414
MCU : ESP32-S3
15-
15+
1616
Author : Chalandi Amine
17-
17+
1818
Owner : Chalandi Amine
19-
19+
2020
Date : 22.02.2025
21-
21+
2222
Description : interrupt vector table implementation for ULP-RISC-V Co-processor
23-
23+
2424
******************************************************************************************/
2525

2626
/*******************************************************************************************
27-
\brief
28-
29-
\param
30-
31-
\return
27+
\brief
28+
29+
\param
30+
31+
\return
3232
********************************************************************************************/
3333
.section .vector
3434
.type _InterruptVectorTable, @function
3535
.align 4
36-
.extern _IRQ_VECTORS
3736
.globl _InterruptVectorTable
3837

3938
_InterruptVectorTable:
40-
/* reset vector */
41-
j _start
42-
39+
/* reset vector */
40+
.org _InterruptVectorTable + 0x00
41+
j _start
42+
43+
.org _InterruptVectorTable + 0x0C
44+
AlignmentDummy:
45+
nop // 2-byte op
46+
nop // 2-byte op

ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/boot.S

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@
2424
******************************************************************************************/
2525

2626
/*******************************************************************************************
27-
\brief
28-
29-
\param
30-
31-
\return
27+
\brief
28+
29+
\param
30+
31+
\return
3232
********************************************************************************************/
3333
.section .boot
3434
.type _start, @function
3535
.align 4
3636
.extern __STACK_TOP
37-
.extern Startup_Init
37+
.extern __my_startup
3838
.globl _start
3939

4040
_start:
4141
/* setup the stack pointer */
4242
la sp, __STACK_TOP
4343

4444
/* setup C/C++ runtime environment */
45-
j Startup_Init
45+
j __my_startup
4646

4747
.size _start, .-_start

ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/from_no_sdk/Code/Startup/crt0.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ extern "C"
1919
{
2020
extern auto main() -> int;
2121

22-
void Startup_Init() __attribute__((used, noinline));
22+
void __my_startup() __attribute__((used, noinline));
2323
}
2424

25-
void Startup_Init()
25+
void __my_startup()
2626
{
2727
// Initialize statics from ROM to RAM.
2828
// Zero-clear default-initialized static RAM.

0 commit comments

Comments
 (0)