Git Product home page Git Product logo

kendryte-standalone-sdk's Introduction

Kendryte K210 standalone SDK

Build Status License

This SDK is for Kendryte K210 without OS support. If you have any questions, please be free to contact us.

Usage

If you want to start a new project, for instance, hello_world, you only need to:

  • Linux and OSX

mkdir your project in src/, cd src && mkdir hello_world, then put your codes in it, enter SDK root directory and build it.

mkdir build && cd build
cmake .. -DPROJ=<ProjectName> -DTOOLCHAIN=/opt/riscv-toolchain/bin && make
  • Windows

Download and install latest CMake.

Download cmake-3.14.1-win64-x64.msi

Download and install latest toolchain.

Download kendryte-toolchain-win-i386-8.2.0-20190409.tar.xz

Open a Windows Powershell, cd to Project directory.

mkdir your project in src/, cd src && mkdir hello_world, then put your codes in it, and build it.

$env:Path="E:\kendryte-toolchain\bin;C:\Program Files\CMak
e\bin" +  $env:Path

mkdir build && cd build
cmake -G "MinGW Makefiles" ../../../..
make

You will get 2 key files, hello_world and hello_world.bin.

  1. If you are using JLink to run or debug your program, use hello_world
  2. If you want to flash it in UOG, using hello_world.bin, then using flash-tool(s) burn .bin to your flash.

This is very important, don't make a mistake in files.

kendryte-standalone-sdk's People

Contributors

0x00-pl avatar bernardxiong avatar bitsk avatar bj-wanghz avatar connorchristie avatar gongt avatar ideal avatar ly0 avatar lymzzyh avatar michprev avatar pillar1989 avatar sunnycase avatar vmedea avatar vowstar avatar wycwyhwyq avatar xiangbingj avatar zhen8838 avatar zzxcanaan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kendryte-standalone-sdk's Issues

UART hardware flow control

* The UART peripheral does not support hardware flow control or
* other modem control signals, or synchronous serial data
* tranfesrs.

But english datasheet (v0.1.5) says:

UART1, UART2 and UART3 are general purpose UARTs and support asynchronous communication (RS232/RS485/IRDA), baud rate up to 5Mbps, hardware flow control using CTS/RTS or (XON/XOFF).

Please clarify this.

Weird variable reset behavior when using timer interrupts

If I run the code below on the Maix Go, the variable irq_count keeps restarting at 0 at random moments. Sometimes it reaches only into the hundreds, sometimes tens of thousands. Why is this? There is nothing in the code that should make irq_count restart at 0.

#include <timer.h>
#include <unistd.h>
#include <plic.h>
#include <sysctl.h>

uint32_t dummy;
// Must use volatile variable
volatile static int irq_count;

int timer_callback(void *ctx)
{
    irq_count++;
    return 0;
}

int timer_device = 2;
int timer_channel = 2;

int main(void)
{
    // Clear IRQ count
    irq_count = 0;

    // Init Platform-Level Interrupt Controller(PLIC)
    plic_init();
    // Enable global interrupt for machine mode of RISC-V
    sysctl_enable_irq();

    // initialize the timer device
    timer_init(timer_device);
    // Set timer interval to 1ms
    timer_set_interval(timer_device, timer_channel, 1000000);
    // Set timer callback function (not single shot) method
    timer_irq_register(timer_device, timer_channel, 0, 1, timer_callback, &dummy);
    // Enable timer
    timer_set_enable(timer_device, timer_channel, 1);

    while (1)
    {
        printf("%d\n", irq_count);
    }
    return 0;
}

SPI slave not work

  • BUG REPORT
  • FEATURE REQUEST

BUG REPORT

Expected behavior

Spi slave only use just cs, miso, mosi, clk 4 pins

Actual behavior

Spi slave use just cs, mosi, clk 3 pins and some weird gpio, only accept data, can not send data.

The data is not actually received yet

Test code

#include "spi_slave.h"
#include "fpioa.h"
#include "gpiohs.h"
#include "stdio.h"

#define SPI_SLAVE_INT_PIN       18
#define SPI_SLAVE_INT_IO        4
#define SPI_SLAVE_READY_PIN     19
#define SPI_SLAVE_READY_IO      5
#define SPI_SLAVE_CS_PIN        29
#define SPI_SLAVE_CLK_PIN       28
#define SPI_SLAVE_MOSI_PIN      27
#define SPI_SLAVE_MISO_PIN      21

int spi_slave_receive_hook(void *data){
    printf("%d\n", ((spi_slave_command_t *)data)->err);
    return 0;
}

int spi_slave_init(uint8_t *data, uint32_t len){
    fpioa_set_function(SPI_SLAVE_CS_PIN, FUNC_SPI_SLAVE_SS);
    fpioa_set_function(SPI_SLAVE_CLK_PIN, FUNC_SPI_SLAVE_SCLK);
    fpioa_set_function(SPI_SLAVE_MOSI_PIN, FUNC_SPI_SLAVE_D0);
    fpioa_set_function(SPI_SLAVE_INT_PIN, FUNC_GPIOHS0 + SPI_SLAVE_INT_IO);
    fpioa_set_function(SPI_SLAVE_READY_PIN, FUNC_GPIOHS0 + SPI_SLAVE_READY_IO);
    spi_slave_config(SPI_SLAVE_INT_IO, SPI_SLAVE_READY_IO, DMAC_CHANNEL5, 8, data, len, spi_slave_receive_hook);
    return 0;
}

Document version

https://github.com/kendryte/kendryte-standalone-sdk/releases/tag/V0.5.5

Hardware

Grove AI HAT for Edge Computing

System

What system do you use?
Ubuntu 18.04/ windows


FEATURE REQUEST

Missing feature

missing spi slave send data API.

Justification

Simple, only the standard SPI four pin, asynchronous transceiver function.

Workarounds

If I could publish the register manual for the chip, maybe I could share this PR.

ai demo error

In standalone sdkv0.4.0, machine can't aceess struct ai_reg_t
Missing feature: A ai demo of the standalone sdk v0.4.0
Justification:the ai demo of software can't work on sdk v0.4.0

uart irq can't be switched frequently

BUG REPORT

Expected behavior

We found a bug when we switchuart irq frequently

Actual behavior

if we switch uart irq frequently,the program would be stopped when we opened the uart irq again

Test code

#include <stdio.h>
#include "fpioa.h"
#include <string.h>
#include "uart.h"
#include "gpiohs.h"
#include "sysctl.h"
#include "syslog.h"
#define UART_NUM    UART_DEVICE_3
int flag = 2;
char v_buf[8];
int on_uart_send(void *ctx)
{
    printk("on_uart_send\r\n");
    return 0;
}
int on_uart_recv(void *ctx)
{
 
    int ret =  uart_receive_data(UART_NUM, v_buf, 8);
	//uart_send_data(UART_NUM, v_buf,1);
	flag = 1;
    return 0;
}

void io_mux_init(void)
{
    fpioa_set_function(10, FUNC_UART1_RX + UART_NUM * 2);
    fpioa_set_function(11, FUNC_UART1_TX + UART_NUM * 2);
}

int main()
{
    io_mux_init();
    plic_init();
    sysctl_enable_irq();

    uart_init(UART_NUM);
    uart_configure(UART_NUM, 115200, 8, UART_STOP_1, UART_PARITY_NONE);
    uart_set_receive_trigger(UART_NUM, UART_RECEIVE_FIFO_8);
	uart_irq_register(UART_NUM, UART_RECEIVE, on_uart_recv, NULL, 2);
    while(1)
    {
    	if(1 == flag)
    	{
    		printf("uart_irq_unregister\r\n");
    		uart_irq_unregister(UART_NUM, UART_RECEIVE);
			printf("v_buf = %s\r\n",v_buf);//simulating data processing
			flag = 0;
    	}
		else if(0 == flag)
		{
			printf("uart_irq_register\r\n");
			uart_irq_register(UART_NUM, UART_RECEIVE, on_uart_recv, NULL, 2);
		}
    }
}

Document version

standalone sdk v0.5.2 toolchain v8.2

Hardware

we run the program on Sipeed M1w

I2C transmit function return value error, and add timeout support

  • BUG REPORT
  • FEATURE REQUEST

Test code

Pin28 and Pin29 didn't connected with any device, and run:

#include <stdio.h>
#include "bsp.h"
#include "i2c.h"
#include "fpioa.h"
#include "sleep.h"
#include "sysctl.h"

uint8_t addr = 0x26; //Invalid  address, connected with no any slave device
int main()
{
    const uint8_t data[] = {1,2,3,4,5};
    plic_init();
    sysctl_enable_irq();
    fpioa_set_function(28,FUNC_I2C0_SCLK);
    fpioa_set_function(29,FUNC_I2C0_SDA);
    i2c_init(I2C_DEVICE_0, addr, 7, 100000);

    while(1)
    {
        int ret = i2c_send_data(I2C_DEVICE_0, data, sizeof(data));
        printf("ret:%d\n",ret);
        sleep(2);
    }
}

Expected behavior

Cause I2C pin didn't connected with any device, so we should get some error hint like this:

ret:1
ret:1
ret:1
ret:1
.
.
.

Actual behavior

But we get this result:

ret:0
ret:1
ret:1
ret:1
.
.
.

_ _20181228141202

And just once wave we can see in logic analyzer, maybe the Tx abort src register not clean.

Document version

latest lib with commit c7148b55e95bb9bb1444413f49cbaf85d4e0c252

Hardware

Sipeed Maix Go/ Maix One

System

Linux18.04 with toolchain 8.2


V0.5.6 complier error

ubuntu16.04 编译V0.5.6之前的版本没问题;
编译V0.5.6版本报错如下:
[ 7%] Building C object lib/CMakeFiles/kendryte.dir/bsp/entry.c.obj
[ 7%] Building C object lib/CMakeFiles/kendryte.dir/bsp/entry_user.c.obj
[ 8%] Building C object lib/CMakeFiles/kendryte.dir/bsp/sleep.c.obj
[ 8%] Building C object lib/CMakeFiles/kendryte.dir/bsp/locks.c.obj
[ 9%] Building C object lib/CMakeFiles/kendryte.dir/bsp/syscalls.c.obj
[ 9%] Building C object lib/CMakeFiles/kendryte.dir/bsp/interrupt.c.obj
[ 10%] Building C object lib/CMakeFiles/kendryte.dir/bsp/printf.c.obj
[ 10%] Building C object lib/CMakeFiles/kendryte.dir/drivers/utils.c.obj
In file included from /home/tration/work/sdk/kendryte-standalone-sdk-develop/lib/drivers/utils.c:17:
/home/tration/work/sdk/kendryte-standalone-sdk-develop/lib/nncase/include/kernels/utils.h:16:10: fatal error: algorithm: No such file or directory
#include
^~~~~~~~~~~
compilation terminated.
lib/CMakeFiles/kendryte.dir/build.make:230: recipe for target 'lib/CMakeFiles/kendryte.dir/drivers/utils.c.obj' failed
make[2]: *** [lib/CMakeFiles/kendryte.dir/drivers/utils.c.obj] Error 1
CMakeFiles/Makefile2:126: recipe for target 'lib/CMakeFiles/kendryte.dir/all' failed
make[1]: *** [lib/CMakeFiles/kendryte.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
依赖库也有安装了,可能是编译cpp的时候没有找到相应头文件吗,还是c和c++编译兼容的问题?
以下是g++和gcc的版本:
g++ --version:
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

gcc --version:
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
有建议处理这个问题吗?谢谢!!

[FEATURE REQUEST]user custom syscall

FEATURE REQUEST

Missing feature

syscall table can't be modified

Justification

remove static attr of syscall table

Workarounds

remove static attr of syscall table

rtc functions not exposed in rtc.h


BUG REPORT

Expected behavior

All global functions from rtc.c should be declared in rtc.h as they are needed for using all the RTC timer features.

Actual behavior

Funtions not available

void rtc_timer_set_mode(rtc_timer_mode_t timer_mode);
rtc_timer_mode_t rtc_timer_get_mode(void);
int rtc_timer_set_tm(const struct tm *tm);
int rtc_timer_set_alarm_tm(const struct tm *tm);
struct tm *rtc_timer_get_tm(void);
struct tm *rtc_timer_get_alarm_tm(void);
int rtc_timer_set_alarm(int year, int month, int day, int hour, int minute, int second);
int rtc_timer_get_alarm(int *year, int *month, int *day, int *hour, int *minute, int *second);
int rtc_timer_set_clock_frequency(unsigned int frequency);
unsigned int rtc_timer_get_clock_frequency(void);
int rtc_timer_set_clock_count_value(unsigned int  count);
unsigned int rtc_timer_get_clock_count_value(void);
int rtc_tick_interrupt_set(int enable);
int rtc_tick_interrupt_get(void);
int rtc_tick_interrupt_mode_set(rtc_tick_interrupt_mode_t mode);
rtc_tick_interrupt_mode_t rtc_tick_interrupt_mode_get(void);
int rtc_alarm_interrupt_set(int enable);
int rtc_alarm_interrupt_get(void);
int rtc_alarm_interrupt_mask_set(rtc_mask_t mask);
rtc_mask_t rtc_alarm_interrupt_mask_get(void);
int rtc_protect_set(int enable);

What clock source does DVP SCCB clock use?

In this function, it seems it is based on APB1 clock, but at the end the actual frequency is computed from DVP. This is inconsistent, what is correct?

uint32_t dvp_sccb_set_clk_rate(uint32_t clk_rate)
{
    uint32_t tmp;
    uint32_t v_sccb_freq = sysctl_clock_get_freq(SYSCTL_CLOCK_APB1);
    uint16_t v_period_clk_cnt = round(v_sccb_freq / clk_rate / 2.0);
    if(v_period_clk_cnt > 255)
    {
        return 0;
    }
    tmp = dvp->sccb_cfg & (~(DVP_SCCB_SCL_LCNT_MASK | DVP_SCCB_SCL_HCNT_MASK));
    tmp |= DVP_SCCB_SCL_LCNT(v_period_clk_cnt) | DVP_SCCB_SCL_HCNT(v_period_clk_cnt);
    dvp->sccb_cfg = tmp;
    return sysctl_clock_get_freq(SYSCTL_CLOCK_DVP) / (v_period_clk_cnt * 2);
}

(dvp_set_xclk_rate does use APB1 clock consistently)

Unify DMA function signatures

Please notice different order of arguments in functions that use DMA. It would be nice to unify this I believe. For example (device_num, dmac_send_channel, dmac_receive_channel, send_buf, send_size, recv_buf, recv_size, other...).

It should be decided ASAP as any changes will break existing code.

void i2c_send_data_dma(dmac_channel_number_t dma_channel_num, i2c_device_number_t i2c_num, const uint8_t *send_buf,
size_t send_buf_len);

void i2c_recv_data_dma(dmac_channel_number_t dma_send_channel_num, dmac_channel_number_t dma_receive_channel_num,
i2c_device_number_t i2c_num, const uint8_t *send_buf, size_t send_buf_len,
uint8_t *receive_buf, size_t receive_buf_len);

void i2s_receive_data_dma(i2s_device_number_t device_num, uint32_t *buf, size_t buf_len,
dmac_channel_number_t channel_num);

void i2s_send_data_dma(i2s_device_number_t device_num, const void *buf, size_t buf_len, dmac_channel_number_t channel_num);

void spi_send_data_standard_dma(dmac_channel_number_t channel_num, spi_device_num_t spi_num,
spi_chip_select_t chip_select,
const uint8_t *cmd_buff, size_t cmd_len, const uint8_t *tx_buff, size_t tx_len);

void spi_receive_data_standard_dma(dmac_channel_number_t dma_send_channel_num,
dmac_channel_number_t dma_receive_channel_num,
spi_device_num_t spi_num, spi_chip_select_t chip_select, const uint8_t *cmd_buff,
size_t cmd_len, uint8_t *rx_buff, size_t rx_len);

void spi_send_data_multiple_dma(dmac_channel_number_t channel_num, spi_device_num_t spi_num,
spi_chip_select_t chip_select,
const uint32_t *cmd_buff, size_t cmd_len, const uint8_t *tx_buff, size_t tx_len);

void spi_receive_data_multiple_dma(dmac_channel_number_t dma_send_channel_num,
dmac_channel_number_t dma_receive_channel_num,
spi_device_num_t spi_num, spi_chip_select_t chip_select, const uint32_t *cmd_buff,
size_t cmd_len, uint8_t *rx_buff, size_t rx_len);

void spi_fill_data_dma(dmac_channel_number_t channel_num, spi_device_num_t spi_num, spi_chip_select_t chip_select,
const uint32_t *tx_buff, size_t tx_len);

void spi_send_data_normal_dma(dmac_channel_number_t channel_num, spi_device_num_t spi_num,
spi_chip_select_t chip_select,
const void *tx_buff, size_t tx_len, spi_transfer_width_t spi_transfer_width);

void spi_dup_send_receive_data_dma(dmac_channel_number_t dma_send_channel_num,
dmac_channel_number_t dma_receive_channel_num,
spi_device_num_t spi_num, spi_chip_select_t chip_select,
const uint8_t *tx_buf, size_t tx_len, uint8_t *rx_buf, size_t rx_len);

void uart_send_data_dma(uart_device_number_t uart_channel, dmac_channel_number_t dmac_channel, const uint8_t *buffer, size_t buf_len);

void uart_receive_data_dma(uart_device_number_t uart_channel, dmac_channel_number_t dmac_channel, uint8_t *buffer, size_t buf_len);

void uart_send_data_dma_irq(uart_device_number_t uart_channel, dmac_channel_number_t dmac_channel,
const uint8_t *buffer, size_t buf_len, plic_irq_callback_t uart_callback,
void *ctx, uint32_t priority);

void uart_receive_data_dma_irq(uart_device_number_t uart_channel, dmac_channel_number_t dmac_channel,
uint8_t *buffer, size_t buf_len, plic_irq_callback_t uart_callback,
void *ctx, uint32_t priority);

standard 3lines SPI support and SPI 4 lines(sck cs mosi miso) standard mode full duplex support

FEATURE REQUEST

Missing feature

SPI standard( Motorola ) 3 lines(sck, cs, data) mode support and 4 lines(sck, cs, mosi, miso) mode full duplex API support

Justification

Many SPI slave devices use standard 3/4 lines mode, it's better to provide these API

Workarounds

  • I don't how to enable 3 lines mode

  • In 4 lines mode, add full duplex support, I wrote a transfer( write and read at the same time) function

And I'm not sure if it's the best resolution, wish your opinion

void spi_transfer_data_standard(spi_device_num_t spi_num, spi_chip_select_t chip_select, const uint8_t *tx_buff,uint8_t *rx_buff,  size_t len)
{
    configASSERT(spi_num < SPI_DEVICE_MAX && spi_num != 2);
    configASSERT(len > 0);
    size_t index, fifo_len;
    size_t rx_len = len;
    size_t tx_len = rx_len;
    spi_set_tmod(spi_num, SPI_TMOD_TRANS_RECV);

    volatile spi_t *spi_handle = spi[spi_num];

    uint8_t dfs_offset;
    switch(spi_num){
        case 0:
        case 1:
            dfs_offset = 16;
            break;
        case 2:
            configASSERT(!"Spi Bus 2 Not Support!");
            break;
        case 3:
        default:
            dfs_offset = 0;
            break;
    }
    uint32_t data_bit_length = (spi_handle->ctrlr0 >> dfs_offset) & 0x1F;
    spi_transfer_width_t frame_width = spi_get_frame_size(data_bit_length);
    spi_handle->ctrlr1 = (uint32_t)(tx_len/frame_width - 1);
    spi_handle->ssienr = 0x01;
    spi_handle->ser = 1U << chip_select;
    uint32_t i = 0;
    while (tx_len)
    {
        fifo_len = 32 - spi_handle->txflr;
        fifo_len = fifo_len < tx_len ? fifo_len : tx_len;
        switch(frame_width)
        {
            case SPI_TRANS_INT:
                fifo_len = fifo_len / 4 * 4;
                for (index = 0; index < fifo_len / 4; index++)
                    spi_handle->dr[0] = ((uint32_t *)tx_buff)[i++];
                break;
            case SPI_TRANS_SHORT:
                fifo_len = fifo_len / 2 * 2;
                for (index = 0; index < fifo_len / 2; index++)
                    spi_handle->dr[0] = ((uint16_t *)tx_buff)[i++];
                break;
            default:
                for (index = 0; index < fifo_len; index++)
                    spi_handle->dr[0] = tx_buff[i++];
                break;
        }
        tx_len -= fifo_len;
    }

    while ((spi_handle->sr & 0x05) != 0x04)
        ;
    i = 0;
    while (rx_len)
    {
        fifo_len = spi_handle->rxflr;
        fifo_len = fifo_len < rx_len ? fifo_len : rx_len;
        switch(frame_width)
        {
            case SPI_TRANS_INT:
                fifo_len = fifo_len / 4 * 4;
                for (index = 0; index < fifo_len / 4; index++)
                  ((uint32_t *)rx_buff)[i++] = spi_handle->dr[0];
                break;
            case SPI_TRANS_SHORT:
                fifo_len = fifo_len / 2 * 2;
                for (index = 0; index < fifo_len / 2; index++)
                  ((uint16_t *)rx_buff)[i++] = (uint16_t)spi_handle->dr[0];
                 break;
            default:
                  for (index = 0; index < fifo_len; index++)
                      rx_buff[i++] = (uint8_t)spi_handle->dr[0];
                break;
        }

        rx_len -= fifo_len;
    }
    spi_handle->ser = 0x00;
    spi_handle->ssienr = 0x00;
}

small error in README.md

In the README.md the following line appears:
cmake .. -DPROJ=<ProjectName> -DTOOLCHAIN=/opt/riscv-toolchain/bin && make

but then it cannot find CMakeLists.txt. What the line should be (at least it then works for me) is:
cmake ../.. -DPROJ=<ProjectName> -DTOOLCHAIN=/opt/riscv-toolchain/bin && make

So, cmake should start one directory higher.

xQueueCreate bug in standalone-sdk ?

BUG REPORT

Expected behavior

Trigger IRQ behave when gpio level changed

Actual behavior

Irq failed to be tiggered, if call xQueueCreate once.
if removed "xQueueCreate" in the code piece, the IRQ can be tiggered when set connect gpio_pin to 'GND'

Test code

xIoTQueue = xQueueCreate((UBaseType_t) 1, sizeof(IoTMessage));
fpioa_set_function(PIN_KEY, FUNC_GPIOHS2);
gpiohs_set_drive_mode(GPIO_KEY, GPIO_DM_INPUT_PULL_UP);
gpiohs_set_pin_edge(GPIO_KEY, GPIO_PE_BOTH);
printf("Register gpio interupt\n");
gpiohs_irq_register(GPIO_KEY, 1, irq_gpiohs2, &g_count);

Provide a Minimal, Complete, and Verifiable example which will reproduce the problem.

# Add code here

Document version

Which branch are you on? If you know the Git revision then add it here as well.

Hardware

Which hardware do you use? K210 (SiPEED M1W)

System

What system do you use? MacOS

Double precision floating point support

Hello, the D extension is currently not enabled in the standalone SDK. It looks like there has been some going back and forth about it in past revisions.

Why is it so? Is double-precision FP in the K210 buggy or is it because of a GCC bug? Could you please document that? Knowing whether double-precision FP is usable or not in the K210 is fairly important.

I have enabled it and done some basic testing and there doesn't seem to be a problem, but I haven't tested double-precision FP extensively so far...

Vector fails to init.

*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors)

See the example here, compile it in main.cpp file:

/* Copyright 2018 Canaan Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <stdio.h>
#include "bsp.h"
#include <vector>

using namespace std;

int core1_function(void *ctx)
{
    uint64_t core = current_coreid();
    printf("Core %ld Hello world\n", core);
    while(1);
}

struct theStruct
{
    int size;
    float para;
};


class test
{
private:
    /* data */
public:
    vector<theStruct> theVector = vector<theStruct>(5);
    test(/* args */);
    ~test();
};

test::test(/* args */)
{
}

test::~test()
{
}


test mTest;

int main()
{
    printk("size:%d\r\n", mTest.theVector.size());
    uint64_t core = current_coreid();
    printf("Core %ld Hello world\n", core);
    register_core1(core1_function, NULL);
    while(1);
}

Can't assign GPIO0 to pin 0

When I try to assign FUNC_GPIO0 to pin 0, an error is raised in gpio.h line 32.
Code:

#include <gpio.h>
#include <fpioa.h>

int main() {
    fpioa_set_function(0 , FUNC_GPIO0);
    gpio_set_drive_mode(0 , GPIO_DM_OUTPUT);
    while (1) {
        gpio_set_pin(0, GPIO_PV_HIGH);
        gpio_set_pin(0, GPIO_PV_LOW);
    }
}

Error:
...kendryte-standalone-sdk/lib/drivers/gpio.c:32) io_number > 0

The code that raises the error:
configASSERT(io_number > 0);

If I change that line into:
configASSERT(io_number >= 0);
everything works fine.

Is there a reason why pin 0 cannot be assigned the FUNC_GPIO0?

Sometimes the timer interrupt will be lost.

  • BUG REPORT
  • FEATURE REQUEST

BUG REPORT

Expected behavior

All interruptions invoked intact.

Actual behavior

Some interrupts lost

I (6088014) main: Kendryte Nov  8 2018 23:29:38
I (7777915) main: Timer test
D (9134666) main: Timer enable (0, 0)=>(0)
D (10723663) main: Timer enable (0, 1)=>(1)
D (12348485) main: Timer enable (0, 2)=>(2)
D (13973339) main: Timer enable (0, 3)=>(3)
D (15598495) main: Timer enable (1, 0)=>(4)
D (17223023) main: Timer enable (1, 1)=>(5)
D (18847889) main: Timer enable (1, 2)=>(6)
D (20472741) main: Timer enable (1, 3)=>(7)
D (22097833) main: Timer enable (2, 0)=>(8)
D (23722425) main: Timer enable (2, 1)=>(9)
D (25347281) main: Timer enable (2, 2)=>(10)
D (27005977) main: Timer enable (2, 3)=>(11)
W (399135189) timer_interrupt_hander: Int stat (0, 0)=>(1)
W (401200463) timer_interrupt_hander: Int stat (0, 1)=>(1)
W (403570033) timer_interrupt_hander: Int stat (0, 2)=>(1)
W (405939609) timer_interrupt_hander: Int stat (0, 3)=>(1)
W (408309179) timer_interrupt_hander: Int stat (1, 0)=>(1)
W (410678745) timer_interrupt_hander: Int stat (1, 1)=>(1)
W (413048315) timer_interrupt_hander: Int stat (1, 2)=>(1)
W (415417883) timer_interrupt_hander: Int stat (1, 3)=>(1)
W (417787455) timer_interrupt_hander: Int stat (2, 0)=>(1)
W (420157025) timer_interrupt_hander: Int stat (2, 1)=>(1)
W (422526595) timer_interrupt_hander: Int stat (2, 2)=>(1)
W (424896167) timer_interrupt_hander: Int stat (2, 3)=>(1)
D (427265761) timer_callback: Timer callback [0], count [1]
E (429432169) timer_interrupt_hander: Timer instance (0, 0)
W (431836153) timer_interrupt_hander: Int stat (0, 0)=>(0)
W (434205189) timer_interrupt_hander: Int stat (0, 1)=>(0)
W (436574755) timer_interrupt_hander: Int stat (0, 2)=>(0)
W (438944323) timer_interrupt_hander: Int stat (0, 3)=>(0)
W (441313905) timer_interrupt_hander: Int stat (1, 0)=>(1)
W (443683465) timer_interrupt_hander: Int stat (1, 1)=>(1)
W (446053045) timer_interrupt_hander: Int stat (1, 2)=>(1)
W (448422609) timer_interrupt_hander: Int stat (1, 3)=>(1)
W (450792177) timer_interrupt_hander: Int stat (2, 0)=>(1)
W (453161747) timer_interrupt_hander: Int stat (2, 1)=>(1)
W (455531321) timer_interrupt_hander: Int stat (2, 2)=>(1)
W (457900889) timer_interrupt_hander: Int stat (2, 3)=>(1)
W (460270901) timer_interrupt_hander: Int stat (0, 0)=>(0)
W (462640031) timer_interrupt_hander: Int stat (0, 1)=>(0)
W (465009603) timer_interrupt_hander: Int stat (0, 2)=>(0)
W (467379173) timer_interrupt_hander: Int stat (0, 3)=>(0)
W (469748741) timer_interrupt_hander: Int stat (1, 0)=>(1)
W (472118313) timer_interrupt_hander: Int stat (1, 1)=>(1)
W (474487875) timer_interrupt_hander: Int stat (1, 2)=>(1)
W (476857451) timer_interrupt_hander: Int stat (1, 3)=>(1)
W (479227015) timer_interrupt_hander: Int stat (2, 0)=>(1)
W (481596587) timer_interrupt_hander: Int stat (2, 1)=>(1)
W (483966155) timer_interrupt_hander: Int stat (2, 2)=>(1)
W (486335729) timer_interrupt_hander: Int stat (2, 3)=>(1)
D (488705302) timer_callback: Timer callback [4], count [2]
E (490871736) timer_interrupt_hander: Timer instance (1, 0)
D (493275191) timer_callback: Timer callback [5], count [3]
E (495441613) timer_interrupt_hander: Timer instance (1, 1)
D (497845076) timer_callback: Timer callback [6], count [4]
E (500011496) timer_interrupt_hander: Timer instance (1, 2)
D (502414960) timer_callback: Timer callback [7], count [5]

As we can see, timer interrupt 1,2,3 are lost.

Test code

Enable all timer, and let all interrupt invoke at same time

    for(size_t j = 0; j < TIMER_DEVICE_MAX; j++) {
        /* For every timer devices , Init timer */
        timer_init(j);
        for(size_t i = 0; i < TIMER_CHANNEL_MAX; i++) {
            /* Set timer interval to 200ms */
            timer_set_interval(j, i, 200000000);
            /* Set timer callback function with repeat method */
            timer_interrupt_register(j, i, 0, 1, timer_callback, &ctx_table[j * TIMER_CHANNEL_MAX + i]);
            /* Enable timer interrupt */
            timer_set_enable(j, i, 1);
            LOGD(__func__, "Timer enable (%ld, %ld)=>(%ld)", j, i, j * TIMER_CHANNEL_MAX + i);
        }
    }

Document version

v0.5.0rc

Hardware

kd233

System

Linux 4.18.0-2-amd64 #1 SMP Debian 4.18.10-2 (2018-11-02) x86_64 GNU/Linux

cmake error

When I run cmake command I am getting path below error.

  • BUG REPORT

BUG REPORT

Document says run run below command

~/kendryte-standalone-sdk/build$ cmake ../.. -DPROJ=testpro -DTOOLCHAIN=/opt/kendryte-toolchain/bin && make

Below are the errors I am getting.

PROJ = testpro
-- Check for RISCV toolchain ...
-- Using /opt/kendryte-toolchain/bin RISCV toolchain
SOURCE_FILES=
CMake Error at cmake/executable.cmake:11 (add_executable):
  add_executable called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:30 (include)


CMake Error at cmake/executable.cmake:14 (set_target_properties):
  set_target_properties Can not find target to add properties to: testpro
Call Stack (most recent call first):
  CMakeLists.txt:30 (include)


CMake Error at cmake/executable.cmake:16 (target_link_libraries):
  Cannot specify link libraries for target "testpro" which is not built by
  this project.
Call Stack (most recent call first):
  CMakeLists.txt:30 (include)

System

Ubuntu 16.04

develop branch vs kendryte-freertos-sdk repository

I'm confused about develop branch in this repository (which looks to be the freertos sdk actually) compared to kendryte-freertos-sdk repository.
Could you, please, explain what are the differences and why are there two repositories containing freertos?

no floating point support for core dumps

A program I made caused a core dump. When studying that dump I noticed something was wrong and traced it back to 'lib/bsp/include/dump.h', and later 'lib/bsp/printf.c'.
The data of the core dump is:

core dump: illegal instruction
Cause 0x0000000000000002, EPC 0x0000000000000000
reg[00](zero ) = 0x001ffb00001ffa00, reg[01](ra   ) = 0x0000000080000760
reg[02](sp   ) = 0x000000008001c8c0, reg[03](gp   ) = 0x000000008000ea68
reg[04](tp   ) = 0x0000000080014c40, reg[05](t0   ) = 0x0000000000006000
reg[06](t1   ) = 0x0000000080001e04, reg[07](t2   ) = 0x0000000000000000
reg[08](s0/fp) = 0xfffffffffffffff8, reg[09](s1   ) = 0x000000008001cb48
reg[10](a0   ) = 0x0000000000000000, reg[11](a1   ) = 0x0000000000000031
reg[12](a2   ) = 0x000000008001cb48, reg[13](a3   ) = 0x0000000000000039
reg[14](a4   ) = 0xfffffffffffffff8, reg[15](a5   ) = 0x0000000000000000
reg[16](a6   ) = 0x0000000000000009, reg[17](a7   ) = 0x0000000000000009
reg[18](s2   ) = 0x0000000000000000, reg[19](s3   ) = 0x0000000000000000
reg[20](s4   ) = 0xfffffffffffffff8, reg[21](s5   ) = 0x000000008001cb31
reg[22](s6   ) = 0x000000008001cb37, reg[23](s7   ) = 0xfffffffffffffff9
reg[24](s8   ) = 0x0000000000000000, reg[25](s9   ) = 0x0000000000000000
reg[26](s10  ) = 0x0000000000000000, reg[27](s11  ) = 0x0000000000000000
reg[28](t3   ) = 0x0000000000000000, reg[29](t4   ) = 0x0000000000000000
reg[30](t5   ) = 0x0000000000000000, reg[31](t6   ) = 0x0000000000000000
freg[00](ft0 ) = 0xff55bcff00000000(), freg[-1610612736]() = 0x000000008000b6d0()
freg[02](ft2 ) = 0xff561cff00000000(), freg[-1610612736]() = 0x000000008000b6e0()
freg[04](ft4 ) = 0xff56b0ff00000000(), freg[536870912]() = 0x000000008000b6f0()
freg[06](ft6 ) = 0xff56a4ff00000000(), freg[-1610612736]() = 0x000000008000b700()
freg[08](fs0 ) = 0xff5822ff00000000(), freg[1610612736]() = 0x000000008000b728()
freg[10](fa0 ) = 0xff58ceff00000000(), freg[-536870912]() = 0x000000008000b758()
freg[12](fa2 ) = 0xff58feff00000000(), freg[-536870912]() = 0x000000008000b780()
freg[14](fa4 ) = 0xff597eff00000000(), freg[-536870912]() = 0x000000008000b790()
freg[16](fa6 ) = 0xff5914ff00000000(), freg[-1610612736]() = 0x000000008000b7a0()
freg[18](fs2 ) = 0xff59caff00000000(), freg[1610612736]() = 0x000000008000b7c8()
freg[20](fs4 ) = 0xff58aeff00000000(), freg[-536870912]() = 0x000000008000b7d8()
freg[22](fs6 ) = 0xff5a4aff00000000(), freg[1610612736]() = 0x000000008000b7e8()
freg[24](fs8 ) = 0xff58aeff00000000(), freg[-536870912]() = 0x000000008000b7f8()
freg[26](fs10) = 0xff57f6ff00000000(), freg[-536870912]() = 0x000000008000b808()
freg[28](ft8 ) = 0x000000ff00000000(), freg[00]() = 0x000000008000b830()
freg[30](ft10) = 0x0000005000000000(), freg[00]() = 0x000000008000b840()
W (482418156) SYSCALL: sys_exit called by core 0 with 0x539

As can be seen in the lines starting with 'freg', there is an empty '()' where a float should have been printed, and the rest of the line seems all wrong. This is caused by a dump print statement in dump.h (which is printk in printf.c) :

DUMP_PRINTF(
       "freg[%02d](%s) = 0x%016lx(%f), freg[%02d](%s) = 0x%016lx(%f)\r\n",
       i * 2, regf_usage[i * 2][0], fregs[i * 2], (float)fregs[i * 2],
       i * 2 + 1, regf_usage[i * 2 + 1][0], fregs[i * 2 + 1], (float)fregs[i * 2 + 1]);

There is a '(%f)' with corresponding '(float)', but according to the spacetimelabs website there is no floating point support.
So, best option: make printc (method: tfp_format) print floats, or: remove the printing of floats in the core dump.

SPI endian

BUG REPORT

I am not sure what exactly means data_bit_length in spi_init but SPI does not seem to work when setting endian to 1. I would expect it to swap order of sent bytes or bits but SPI sends all zeroes instead.

endian set to 1
image

endian set to 0
image

Test code

#include <stdio.h>
#include "gpio.h"
#include "bsp.h"
#include "sysctl.h"
#include "fpioa.h"
#include "spi.h"

int main()
{
    gpio_init();
    dmac_init();
    
    sysctl_set_power_mode(SYSCTL_POWER_BANK0, SYSCTL_POWER_V33);
    sysctl_set_power_mode(SYSCTL_POWER_BANK1, SYSCTL_POWER_V33);
    sysctl_set_power_mode(SYSCTL_POWER_BANK2, SYSCTL_POWER_V33);
    sysctl_set_power_mode(SYSCTL_POWER_BANK3, SYSCTL_POWER_V33);
    sysctl_set_power_mode(SYSCTL_POWER_BANK4, SYSCTL_POWER_V33);
    sysctl_set_power_mode(SYSCTL_POWER_BANK5, SYSCTL_POWER_V33);
    sysctl_set_power_mode(SYSCTL_POWER_BANK6, SYSCTL_POWER_V18);
    sysctl_set_power_mode(SYSCTL_POWER_BANK7, SYSCTL_POWER_V18);

    fpioa_set_function(9, FUNC_SPI1_SCLK);
    fpioa_set_function(10, FUNC_SPI1_D0);
    fpioa_set_function(11, FUNC_SPI1_SS0);

    spi_init(SPI_DEVICE_1, SPI_WORK_MODE_0, SPI_FF_STANDARD, 8, 1);
    spi_set_clk_rate(SPI_DEVICE_1, 1000000);

    uint8_t cmd = 0xA5;
    uint8_t data[] = { 0x01, 0x20, 0x03, 0x40 };

    while(1)
    {
        spi_send_data_standard(SPI_DEVICE_1, SPI_CHIP_SELECT_0, &cmd, 0, data, 4);
        sleep(1);
    }
}

Document version

248fbcd

Hardware

Sipeed Dan Dock

Multi core interrupt enabler and disabler modification

int plic_irq_enable(plic_irq_t irq_number)

The following code could enable and disable the Core 1 interrupt in Core 0 context and reversely. It is really necessary when you are doing some critical process in Core 0 to avoid the interrupt of Core 1.

PLZ test and merge it.

int plic_irq_enable(plic_irq_t irq_number)
{
    /* Check parameters */
    if (PLIC_NUM_SOURCES < irq_number || 0 > irq_number)
        return -1;
    
    for(int core_id = 0; core_id < 2; core_id++)
    {
        if (plic_instance[core_id][irq_number].callback != NULL) {
            /* Get current enable bit array by IRQ number */
            uint32_t current = plic->target_enables.target[core_id].enable[irq_number / 32];
            /* Set enable bit in enable bit array */
            current |= (uint32_t)1 << (irq_number % 32);
            /* Write back the enable bit array */
            plic->target_enables.target[core_id].enable[irq_number / 32] = current;
            return 0;
        }
    }
    return -1;
}

int plic_irq_disable(plic_irq_t irq_number)
{
    /* Check parameters */
    if (PLIC_NUM_SOURCES < irq_number || 0 > irq_number)
        return -1;
    
    for(int core_id = 0; core_id < 2; core_id++)
    {
        if (plic_instance[core_id][irq_number].callback != NULL) {
            /* Get current enable bit array by IRQ number */
            uint32_t current = plic->target_enables.target[core_id].enable[irq_number / 32];
            /* Clear enable bit in enable bit array */
            current &= ~((uint32_t)1 << (irq_number % 32));
            /* Write back the enable bit array */
            plic->target_enables.target[core_id].enable[irq_number / 32] = current;
            return 0;
        }
    }
    return -1;
}

reculock implementation is not multicore safe

BUG REPORT

I observed that the reculock implementation in locks.c file is not safe for use by multiple cores. reculock array is a shared resource that is not protected from simultaneous usage by separate cores. If two cores use two distinct recursive locks in parallel with high frequency, corruption occurs and system crashes.

Expected behavior

The system works in a stable manner.

Actual behavior

System crashes.

Test code

reculock_t reculock[LOCK_MAX_NUM];

...

static reculock_t *get_free_reculock(void)
{
    reculock_t *ret = NULL;
    for(uint32_t i = 0; i < LOCK_MAX_NUM; i++)
      {
        // we should make sure that this logic does not run in parallel on both cores
        if(reculock[i].lock == NULL){
          ret = &reculock[i];
          break;
        }
      }

    return ret;
}

Document version

present master

Hardware

KD233

System

Linux

cmake problem

When I use submodule, there are some c files that don't need to be compiled, but sdk compiles all the files by default, and then causes an error, how can I not compile these files (I don't want to delete those files!

lib/drivers/dvp.c configASSERT error

in function

void dvp_set_output_enable(dvp_output_mode_t index, int enable)
{
// configASSERT(index < 2);

if (index == 0)
{
    if (enable)
        dvp->dvp_cfg |= DVP_CFG_AI_OUTPUT_ENABLE;
    else
        dvp->dvp_cfg &= ~DVP_CFG_AI_OUTPUT_ENABLE;
}
else
{
    if (enable)
        dvp->dvp_cfg |= DVP_CFG_DISPLAY_OUTPUT_ENABLE;
    else
        dvp->dvp_cfg &= ~DVP_CFG_DISPLAY_OUTPUT_ENABLE;
}

}
i call it as
dvp_set_output_enable(DVP_CFG_AI_OUTPUT_ENABLE | DVP_CFG_DISPLAY_OUTPUT_ENABLE,1);

but the configASSERT is error.

执行 cmake ..-DPROJ=hello_world -G "MinGW Makefiles"没反应

Make sure you read and understand this document.
Use one of the two templates below and delete the rest.

  • BUG REPORT
  • FEATURE REQUEST

BUG REPORT
PS D:\kendryte-standalone-sdk-0.5.6\build> cmake ..-DPROJ=hello_world -G "MinGW Makefiles"
CMake Error: The source directory "D:/kendryte-standalone-sdk-0.5.6/build/..-DPROJ=hello_world" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
PS D:\kendryte-standalone-sdk-0.5.6\build>

Provide a Minimal, Complete, and Verifiable example which will reproduce the problem.

按照指南一步步执行到这执行不下去了

Output *.lst and map file

FEATURE REQUEST

Missing feature

Output *.lst and map file

Justification

I want to dig into rv64 by observing the asm generating by compiler and try mixed coding ( C and ASM ).

Workarounds

I do not find a proper solution under the build system cmake by now.

`core dump: misaligned store`, align issue

  • BUG REPORT

In spi recieve data copy code,

  switch(frame_width)
    {
       case SPI_TRANS_INT:
           for(i = 0; i < v_rx_len; i++)
               ((uint32_t *)rx_buf)[i] = v_rx_buf[i];
           break;

when the address of rx_buff is not a multiple of 4, the cast will cause a crash.

core dump: misaligned store

Expected behavior

Just not crash

Actual behavior

when the address of rx_buff is not a multiple of 4, the cast will cause a crash.

core dump: misaligned store

Test code

int main()
{
    uint8_t a[128];
    uint32_t b[4]={0x01020304, 0x05060708};
    uint8_t* p = a+1;

    printf("start test now:\n");

    for(int i=0; i<sizeof(b); ++i)
    {
	printf("---");
        ((uint32_t*)p)[i] = b[i];
    }
    printf("pass\n");
    for(int i=0; i<8; ++i)
        printf("%d ", p[i]);
    printf("test end\n");
   while(1);
}

Run this code, we got

V (5795251) SYSCALL: misaligned store recovered at 80000430. len:04,addr:8001637e,reg:14,data:0000000001020304,float:0
V (9958316) SYSCALL: misaligned store recovered at 80000430. len:04,addr:80016382,reg:14,data:0000000005060708,float:0
V (14121849) SYSCALL: misaligned store recovered at 80000430. len:04,addr:80016386,reg:14,data:0000000000000000,float:0

Although it is available on esp32 and PC

Document version

rev: 8c6b3f2 ( dev branch latest (2019.1.18) )

Hardware

Sipeed M1

System

Ubuntu 18.04 with toolchain V8.2

projects outside of SDK

  • BUG REPORT
  • FEATURE REQUEST

Missing feature

Duplicate of kendryte/kendryte-freertos-sdk#30

Justification

It is not easy to include external library to the build without Kendryte IDE. We need an option to use custom CMakeLists.txt in the project directory.

Workarounds

It is almost possible to use this template https://github.com/kendryte/kendryte-freertos-sdk/blob/develop/CMakeLists.txt.example.cmake.

This worked for me:

cmake_minimum_required(VERSION 3.0)

include("${SDK}/cmake/common.cmake")
include(${SDK}/cmake/macros.internal.cmake)
header_directories(${SDK}/lib)

project(project_name C CXX ASM)
include_directories(custom_include_directories)
add_source_files(custom_source_files)

include("${SDK}/cmake/executable.cmake")

Because there are some differences between build systems in standalone and freertos SDKs it is also needed to modify https://github.com/kendryte/kendryte-standalone-sdk/blob/develop/cmake/executable.cmake

diff --git a/cmake/executable.cmake b/cmake/executable.cmake
index 70132ad..965ede5 100644
--- a/cmake/executable.cmake
+++ b/cmake/executable.cmake
@@ -1,7 +1,11 @@
 if (NOT BUILDING_SDK)
-    add_library(kendryte STATIC IMPORTED)
-    set_property(TARGET kendryte PROPERTY IMPORTED_LOCATION ${SDK_ROOT}/libkendryte.a)
-    include_directories(${SDK_ROOT}/include/)
+    if(EXISTS ${SDK_ROOT}/libkendryte.a)
+        include_directories(${SDK_ROOT}/include/)
+        add_library(kendryte STATIC IMPORTED)
+        set_property(TARGET kendryte PROPERTY IMPORTED_LOCATION ${SDK_ROOT}/libkendryte.a)
+    else()
+        add_subdirectory(${SDK_ROOT}/lib SDK)
+    endif()
 endif ()
 
 removeDuplicateSubstring(${CMAKE_C_FLAGS} CMAKE_C_FLAGS)

Function returns error float value.

Make sure you read and understand this document.
Use one of the two templates below and delete the rest.

  • BUG REPORT

BUG REPORT

Expected behavior

Serial port:

result1:50
result2:50

Actual behavior

Serial port:

result1:50
result2:0

Test code

#include <stdio.h>

float ncc(float *f1, float *f2)
{
    float corr = 0;
    float norm1 = 0;
    float norm2 = 0;

    int size = 3 * 3;

    for(int i = 0; i < size; i++)
    {
        corr += f1[i] * f2[i];
        norm1 += f1[i] * f1[i];
        norm2 += f2[i] * f2[i];
    }

    // normalization to <0,1>

    return (corr / (norm1 * norm2) + 1) / 2.0f;
}

float f1[9] = {2,3,4,3,4,6,7,9,7,6,4,3};
float f2[9] = {124,233,234,124,233,234,124,233,234};

float classifyPatch()
{

    float ccorr_max_p = 0;

    //Compare patch to positive patches
    for(size_t i = 0; i < 1; i++)
    {
        float ccorr = ncc(f1, f2);

        if(ccorr > ccorr_max_p)
        {
            ccorr_max_p = ccorr;
        }
    }

    float ccorr_max_n = 0;

    //Compare patch to negative patches
    for(size_t i = 0; i < 1; i++)
    {
        float ccorr = ncc(f1, f2);

        if(ccorr > ccorr_max_n)
        {
            ccorr_max_n = ccorr;
        }
    }

    float dN = 1.0f - ccorr_max_n;
    float dP = 1.0f - ccorr_max_p;

    float distance;

    distance = dN / (dN + dP);

    printf("result1:%d\r\n", (int)(distance*100.0f));
    
    return distance;
}


int main()
{
    float hello2 = classifyPatch();

    printf("result2:%d\r\n", (int)(hello2*100.0f));
}

Document version

V0.5.3

Hardware

KD233

System

Mac OS X

Workarounds

Add volatile for distance.

plic_irq_callback_t return value

/**
* @brief Definitions for the interrupt callbacks
*/
typedef int (*plic_irq_callback_t)(void *ctx);

IRQ callback should return int but the value does not seem to be used anywhere.

plic_instance[core_id][int_num].callback(
plic_instance[core_id][int_num].ctx);

Are there any future plans to use this return value? Otherwise it might be better to change it to void to avoid confusion.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.