if i only needed to use neopixel then yeh spi could be used but spi is currently used by external flash.
if i only needed to use neopixel then yeh spi could be used but spi is currently used by external flash.
1) write to GPIOD->BSHR takes more than one instruction, check the compiler output to see exactly what; but it usually involves loading the constant from memory and writing it to another address
li a1,0x8
sw a1,16(a0) ; GPIOD base addr already in in A0
You may also want to try relocating time-critical code into the SRAM. This way you will not be incurring flash wait state penalty.
I know with esp32 series mcus you use IRAM_ATTR to put the code in iram but what is the attr for wch.
#define IRAM_ATTR __attribute__((section(".iram1")))
__attribute__((section(".data.my_function")))
void my_function(int blah, int foo) {
// etc...
}
tried putting code in the .data section like you said. Theres no difference. So im guessing they havent added the code to support it yet in 1.0.4 source
/* includes, init functions, etc snipped for brevity */
static void systick_init(void) {
SysTick->CNT = 0;
SysTick->SR = 0;
SysTick->CMP = UINT32_MAX;
SysTick->CTLR = STK_STRE | STK_STCLK;
}
static inline void systick_start(void) {
SysTick->CNT = 0;
SysTick->SR = 0;
SysTick->CTLR |= STK_STE;
}
static inline uint32_t systick_stop(void) {
SysTick->CTLR &= ~STK_STE;
return SysTick->CNT;
}
#define TEST_ITERATIONS 200000
#define TEST_FUNC_BODY(i) \
do { \
volatile uint32_t count = (i); \
while(count-- > 0); \
while(count++ < (i)); \
while(count-- > 0); \
} while(0)
__attribute__((noinline)) static void test_func_flash(const uint32_t iters) {
TEST_FUNC_BODY(iters);
}
__attribute__((section(".data.test_func_ram"), noinline)) static void test_func_ram(const uint32_t iters) {
TEST_FUNC_BODY(iters);
}
int main(void) {
uint32_t ticks_flash, ticks_ram;
clock_init();
gpio_init();
systick_init();
uart_init(HSI_VALUE, UART_BAUD_RATE);
printf("----------------------------------------\n");
printf("RAM EXEC TEST\n");
printf("----------------------------------------\n");
printf("test_func_flash() address: %p\n", test_func_flash);
printf("test_func_ram() address: %p\n", test_func_ram);
systick_start();
test_func_flash(TEST_ITERATIONS);
ticks_flash = systick_stop();
printf("test_func_flash() execution: %lu ticks\n", ticks_flash);
systick_start();
test_func_ram(TEST_ITERATIONS);
ticks_ram = systick_stop();
printf("test_func_ram() execution: %lu ticks\n", ticks_ram);
while(true);
}
.text.test_func_flash
0x00000828 0x28 obj\Release\main.o
.data.test_func_ram
0x20000000 0x28 obj\Release\main.o
----------------------------------------
RAM EXEC TEST
----------------------------------------
test_func_flash() address: 0x828
test_func_ram() address: 0x20000000
test_func_flash() execution: 1600035 ticks
test_func_ram() execution: 1600038 ticks

sw zero,8(s0) sw zero,8(s0)
sw zero,4(s0) sw zero,4(s0)
lw a5,0(s0) lw a5,0(s0)
lui a0,0x31 lui a0,0x31
addi a0,a0,-704 # 30d40 <_data_lma+0x301a8> addi a0,a0,-704 # 30d40 <_data_lma+0x301a8>
ori a5,a5,1 ori a5,a5,1
sw a5,0(s0) sw a5,0(s0)
jal 828 <test_func_flash> auipc ra,0x1ffff
jalr 1690(ra) # 20000000 <test_func_ram>
if i only needed to use neopixel then yeh spi could be used but spi is currently used by external flash.
----------------------------------------
RAM EXEC TEST
----------------------------------------
test_func_flash() address: 0x828
test_func_ram() address: 0x20000000
test_func_flash() execution: 2000039 ticks
test_func_ram() execution: 1600041 ticks
has anyone gotten gpio to work with 30/50MHz in Output mode. Idk datasheet Port Configuration Register(GPIOx_CFGLR) says max is 30 MHz but wch chip diagram show HB bus Fmax as 50 MHz.
WS2812? Use UART. You can encode 3 bit values per a transmitted byte.
WS2812? Use UART. You can encode 3 bit values per a transmitted byte.
WS2812? Use UART. You can encode 3 bit values per a transmitted byte.
How do you hide the start and stop bits? You must have to use something like 2.5 Mbps, which probably very few UARTs can do -- that's 22x the highest commonly used speed! (115200)
Think you'd also need an inverter.
#define BIT1_0 0x03
#define BIT1_1 0x02
#define BIT2_0 0x18
#define BIT2_1 0x10
#define BIT3_0 0xc0
#define BIT3_1 0x80BIT1_0 | BIT2_1 | BIT3_1#define BASE 0x92
#define BIT1 0x01
#define BIT2 0x08
#define BIT2 0x40WS2812? Use UART. You can encode 3 bit values per a transmitted byte.
How do you hide the start and stop bits? You must have to use something like 2.5 Mbps, which probably very few UARTs can do -- that's 22x the highest commonly used speed! (115200)
Think you'd also need an inverter.
WS2812? Use UART. You can encode 3 bit values per a transmitted byte.
How do you hide the start and stop bits? You must have to use something like 2.5 Mbps, which probably very few UARTs can do -- that's 22x the highest commonly used speed! (115200)
Think you'd also need an inverter.
Yes, you need to invert the output, which I suppose and modern UART module can do.
Before inversion, to encode 1 you need to transmit the following bauds: 001, to transmit 011
The start bit is always 0 which is coinsides with the start bit, then 2 bits of data, then 3 bits for the second datum, and then 3 bits for the third. The stop bit will give you a pause.
Something like thisCode: [Select]#define BIT1_0 0x02
#define BIT1_1 0x03
#define BIT2_0 0x10
#define BIT2_1 0x18
#define BIT3_0 0x80
#define BIT3_1 0xc0
combine these as needed with or and send. For exampleCode: [Select]BIT1_0 | BIT2_1 | BIT3_1
will send 0 - 1 - 1 to WS2812
orCode: [Select]#define BASE 0x92
#define BIT1 0x01
#define BIT2 0x08
#define BIT2 0x40
As to the speed, you need around 3 Mbaud. For 24 MHz clock, it is CLK/8. Shouldn't be a problem for an UART module. You don't need very precise baud rate as WS2812 has a huge margin.
Something else that can be useful to know is that although bit-to-bit speed is fairly critical, many ( all?) WS2812 style chips will tolerate inter-byte gaps of up to a couple of hundred uS before seeing the gap as a frame reset
WS2812? Use UART. You can encode 3 bit values per a transmitted byte.
How do you hide the start and stop bits? You must have to use something like 2.5 Mbps, which probably very few UARTs can do -- that's 22x the highest commonly used speed! (115200)
Think you'd also need an inverter.Most UARTS can do at least clk/16, some up to clk/4.