This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-EM-CC2340R5: Any code examples communicating with external flash?

Part Number: LP-EM-CC2340R5
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

Hey! I'm curious about using the external flash (MX25R8035F) . We are thinking about using the same flash in our project and are creating HALs to read and write to it. 

I see in my sysconfig generated files there lives a bit-bang function used to put the flash into sleep mode. 

void Board_sendExtFlashByte(uint8_t byte)
{
    uint8_t i;

    /* SPI Flash CS */
    GPIO_write(BOARD_EXT_FLASH_SPI_CS, 0);

    for (i = 0; i < 8; i++) {
        GPIO_write(BOARD_EXT_FLASH_SPI_CLK, 0); /* SPI Flash CLK */

        /* SPI Flash PICO */
        GPIO_write(BOARD_EXT_FLASH_SPI_PICO, (byte >> (7 - i)) & 0x01);
        GPIO_write(BOARD_EXT_FLASH_SPI_CLK, 1);  /* SPI Flash CLK */

        /*
         * Waste a few cycles to keep the CLK high for at
         * least 45% of the period.
         * 3 cycles per loop: 8 loops @ 48 MHz = 0.5 us.
         */
        CPUDelay(8);
    }

    GPIO_write(BOARD_EXT_FLASH_SPI_CLK, 0);  /* CLK */
    GPIO_write(BOARD_EXT_FLASH_SPI_CS, 1);  /* CS */

    /*
     * Keep CS high at least 40 us
     * 3 cycles per loop: 700 loops @ 48 MHz ~= 44 us
     */
    CPUDelay(700);
}


I see on some older CC devices, there are OTA example code which uses some external Flash communication. Anything like that for the CC23xx family? Especially anything deeper than the send ExtFlashByte, reading examples would be appreciated. Thanks!

  • well...  kinda answered my own question and evolved my question: how should I keep CS low long enough to let my peripheral speak back to me?


    Just realized I can use sysconfig with SPI easily. In case anyone else reading this struggles with SPI, make sure you hold the CS line low long enough to get peripheral's response! No wonder MISO always low...

    My problem was a CS line toggle between command writes.That little 500ns CS bloop resets most peripherals buffers I just learned Slight smile



  • Hello Cameron,

    Here is a small snippet for external flash:

    (#include "ti/common/flash/no_rtos/extFlash/ext_flash.h") 

        extFlashOpen();
    
        if (false == extFlashErase(offset, 0x42FFF))
        {
            while (1)
            {
                ;
            }
        }
    
        if (false == extFlashRead(offset, sizeof(uint32_t), (uint8_t *)&buf))
        {
            while (1)
            {
                ;
            }
        }
        else
        {
            if (buf != 0xffffffff)
            {
                while (1)
                {
                    ;
                }
            }
        }

    Thanks,
    Alex F

  • You're my hero Alex- This shows how extFlashSelect manually holds CS line low. That was the missing piece of the puzzle.

    Anyways, I have a working solution. I think it's ugly so I'd love your $0.02 if you know a better way:
    What I do:
    • Disable automatic CSN pin control via SPI_control(spiFlashHandle, SPILPF3DMA_CMD_CLEAR_CSN_PIN, NULL);
    • my custom SPI transfer: GPIO write CS low -> SPI_transfer -> write CS high

    My fear is something behind the scenes re-enables this SPI CS control and flash appears dead

  • Hello Cameron,

    If we are concerned that something else might interrupt your process you can utilize a Semaphore to protect your operation.

    Thanks,
    Alex F