Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploading firmware issue: In bhy2_spi_write (common.c), m_tx_buf size should be length + 1 #1

Open
one-giant-leap opened this issue Sep 3, 2022 · 1 comment

Comments

@one-giant-leap
Copy link

I wasn't able to upload firmware to flash (and uploading to RAM was dependent on MAX_READ_WRITE_LEN value) until I made the following change to the initialization of m_tx_buf:

int8_t bhy2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
    (void)intf_ptr;

    uint8_t m_tx_buf[length + 1];

    volatile uint32_t * p_spim_event_end = (uint32_t *) nrfx_spim_end_event_get(&m_spi);

    // Initialize buffers
    memset(m_tx_buf, 0xff, length + 1);

    m_tx_buf[0] = reg_addr;
    memcpy(m_tx_buf + 1, reg_data, length);

    m_tx_buf[0] = reg_addr;

    nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TX(m_tx_buf, length + 1);

    int err_code = nrfx_spim_xfer(&m_spi, &xfer_desc, NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER);
    APP_ERROR_CHECK(err_code);

    if (err_code == NRF_SUCCESS)
    {
      while (*p_spim_event_end == 0)
                {};
      *p_spim_event_end = 0; 
    }
    // The driver doesn't release the ss_pin
    // So we need to do it ourselves here to tell the chip
    // that this SPI transfer is finished.
    nrf_gpio_pin_set(BSP_MEMS_CS);

    return BHY2_INTF_RET_SUCCESS;
}
@kinisy
Copy link

kinisy commented Mar 31, 2023

This solution also worked for me - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants