# Using note-c library on different platform such as FreeRTOS

**URL:** https://discuss.blues.com/t/using-note-c-library-on-different-platform-such-as-freertos/1162
**Category:** Uncategorized
**Created:** [January 2, 2023, 6:38am UTC](https://discuss.blues.com/t/using-note-c-library-on-different-platform-such-as-freertos/1162 "2023-01-02T06:38:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ujur007](https://avatars.discourse-cdn.com/v4/letter/u/e9bcb4/32.png) [@ujur007](https://discuss.blues.com/u/ujur007)
#### Post date: [January 2, 2023, 6:38am UTC](https://discuss.blues.com/t/using-note-c-library-on-different-platform-such-as-freertos/1162/1 "2023-01-02T06:38:58Z")

</div>

I want to use the note-c library on architecture which uses FreeRTOS as a base.  
What I know so far is that it it possible to create a program which can do this as note-c is pure C based api.

I am following a official guide from Blues team which has done this for STM32.

> **[Sensor Tutorial with C/C++ (STM32Cube), STM32 Discovery, and Notecarrier-A -...](https://dev.blues.io/guides-and-tutorials/collecting-sensor-data/notecarrier-a/stm32-discovery/c-cpp-stm32cube/)**
>
> Build an MCU-controlled application that reads from an external sensor and sends readings to the Notecard

In that guide there are some user-defined function which are only required to get the work done.  
These are as mentioned in the guide MX\_I2C4\_DeInit, noteDebugSerialOutput, noteI2CReceive, noteI2CReset, noteI2CTransmit .

Is there anything else required to take a note of?

---

<div class="post-metadata">

### Author: ![ujur007](https://avatars.discourse-cdn.com/v4/letter/u/e9bcb4/32.png) [@ujur007](https://discuss.blues.com/u/ujur007)
#### Post date: [January 16, 2023, 8:41am UTC](https://discuss.blues.com/t/using-note-c-library-on-different-platform-such-as-freertos/1162/2 "2023-01-16T08:41:48Z")

</div>

I was working to port the note card libratry to ESP-IDF.

I have created the component for the notecard i2c communication But I have got the error regarding some undefined reference to object.  
The error is in file n\_request.c

n\_request.c:327:undefined reference to `NoteUserAgent’

The function for communication is NoteTransaction.

What I have done is that have defined the following function declaration at the top of the file and also included the hote.h file. But the error still exist while building the project.

J \*NoteUserAgent(void);

---

<div class="post-metadata">

### Author: ![zfields](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/zfields/32/29_2.png) [@zfields](https://discuss.blues.com/u/zfields)
#### Post date: [February 3, 2023, 12:32am UTC](https://discuss.blues.com/t/using-note-c-library-on-different-platform-such-as-freertos/1162/3 "2023-02-03T00:32:22Z")

</div>

Hi @ujur007,

`undefined reference` means that the **compiler** was able to find the declaration in `note.h`, but the **linker** was not able to find the objects created when you compiled `note-c`.

Normally when this happens to me, It means I have forgotten to instruct `CMake` to compile `note-c` for me.

Can you share the `ninja` build output from `CMake` (a.k.a. `idf.py build`), so we can look to see what’s happening?

Best,  
Zak

---

<div class="post-metadata">

### Author: ![ujur007](https://avatars.discourse-cdn.com/v4/letter/u/e9bcb4/32.png) [@ujur007](https://discuss.blues.com/u/ujur007)
#### Post date: [February 3, 2023, 6:30am UTC](https://discuss.blues.com/t/using-note-c-library-on-different-platform-such-as-freertos/1162/4 "2023-02-03T06:30:49Z")

</div>

Hi,  
Sorry for the inconvenience.

The thing is that there was one file n\_ua.c missing in my folder somehow.!! which make this error, and while looking for the solution previously, I forgot to check my folder, rather only looked on Github folders…!!

I will share the IDF component after testing I2C works…!

---

<div class="post-metadata">

### Author: ![ujur007](https://avatars.discourse-cdn.com/v4/letter/u/e9bcb4/32.png) [@ujur007](https://discuss.blues.com/u/ujur007)
#### Post date: [April 27, 2023, 3:28pm UTC](https://discuss.blues.com/t/using-note-c-library-on-different-platform-such-as-freertos/1162/5 "2023-04-27T15:28:24Z")

</div>

Hi,

It has been a long since I posted this thread but I was also working on this.  
So now during porting the API I have had an issue. The code compiles as needed but seems that it is not working from ESP32 I2C to notecard I2C. Following is the code for that.

```auto

bool noteI2CReset(uint16_t dev_addr);
const char * noteI2CTransmit(uint16_t dev_addr, uint8_t *pBuffer, uint16_t size);
const char * noteI2CReceive(uint16_t dev_addr, uint8_t *pBuffer, uint16_t size, uint32_t *available);
void delay(uint32_t ms);
uint32_t ticks(void);

static esp_err_t i2c_master_init(void){
    int i2c_port = CONFIG_I2C_MASTER_PORT;
    i2c_config_t conf = {
        .mode = I2C_MODE_MASTER,
        .sda_io_num = CONFIG_I2C_MASTER_SDA_IO,
        .scl_io_num = CONFIG_I2C_MASTER_SCL_IO,
        .sda_pullup_en = GPIO_PULLUP_ENABLE,
        .scl_pullup_en = GPIO_PULLUP_ENABLE,
        .master.clk_speed = I2C_MASTER_FREQ_HZ,
    };
    i2c_param_config(i2c_port, &conf);
    return i2c_driver_install(i2c_port, conf.mode, 0, 0, 0);   
}
const char * noteI2CTransmit(uint16_t dev_addr, uint8_t *pBuffer, uint16_t size){
    esp_err_t err;
    const char * errstr = NULL;
    uint8_t send_buffer[256];
    send_buffer[0] = (size & NOTE_I2C_BUFFER_SIZE);    
    memcpy(&send_buffer[1], pBuffer, send_buffer[0]);    
    err = i2c_master_write_to_device(CONFIG_I2C_MASTER_PORT, dev_addr, send_buffer, sizeof(send_buffer[0] + send_buffer[1]), 1000 / portTICK_PERIOD_MS);

    switch(err) {
    case ESP_OK:
        errstr = NULL;
        break;
    case ESP_FAIL:
        errstr = "Error in i2c Transmission";
        break;
    }    
    return errstr;
}
const char * noteI2CReceive(uint16_t dev_addr, uint8_t *pBuffer, uint16_t size, uint32_t *available){
    esp_err_t error;
    const char * errstr;    
    uint8_t query_request[2];
    query_request[0] = 0x00;
    query_request[1] = (size & NOTE_I2C_BUFFER_SIZE);

    uint8_t goodbyte = 0;
    uint8_t availbyte = 0;

    error = i2c_master_write_to_device(CONFIG_I2C_MASTER_PORT, dev_addr, query_request, sizeof(query_request), 1000 / portTICK_PERIOD_MS);

    switch(error){
    case ESP_OK:
        errstr = NULL;
        break;
    case ESP_FAIL:
        errstr = "Failed to Transmit";
        break;
    }

    if (!errstr){
        uint8_t buffer[NOTE_I2C_BUFFER_SIZE];
        int readlen = (size + 2);
        error = i2c_master_read_from_device(CONFIG_I2C_MASTER_PORT, dev_addr, buffer, readlen, 1000 / portTICK_PERIOD_MS);

        if(error == ESP_OK){
            availbyte = buffer[0];
            goodbyte = buffer[1];

            if(goodbyte != size) {
                ESP_LOGE(TAG, "i2c: incorrect amount of data");
            }
            else{
                memcpy(pBuffer, &buffer[2], buffer[1]);
            }
        }
    }
    if (errstr != NULL){
        return errstr;
    }
    *available = availbyte;
    return NULL;
}

bool noteI2CReset(uint16_t dev_addr)
{
    const char * err;
    //uint8_t buffer[NOTE_I2C_BUFFER_SIZE];
    uint32_t available = 0;
    
  // Empty the Notecard send buffer
    err = noteI2CReceive(dev_addr, NULL, 0, &available);
    return err;
}

void delay(uint32_t ms)
{
    vTaskDelay(pdMS_TO_TICKS(ms));
}

uint32_t ticks(void)
{
    return (esp_timer_get_time() / 1000);
}

```

Then inside the main function I do something like this

```auto
ESP_ERROR_CHECK(i2c_master_init());
NoteSetFn(malloc, free, delay, ticks);
    // Set Notecard I2C Interface
NoteSetFnI2C(NOTE_I2C_ADDR_DEFAULT, NOTE_I2C_BUFFER_SIZE, noteI2CReset, noteI2CTransmit, noteI2CReceive);
J *req = NoteNewRequest("hub.set");
JAddStringToObject(req, "product", BLUES_PRODUCT_UID);
JAddStringToObject(req, "mode", "continuous");
NoteRequest(req);
vTaskDelay(10 * 1000 / portTICK_PERIOD_MS);

```
