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

example of LPUART for MAX78000? #1265

Open
khavernathy opened this issue Nov 11, 2024 · 2 comments
Open

example of LPUART for MAX78000? #1265

khavernathy opened this issue Nov 11, 2024 · 2 comments

Comments

@khavernathy
Copy link

khavernathy commented Nov 11, 2024

Hi, I see an example of using UART for the MAX78000, but can I see one for LPUART? I guess I need to change some parameters, for example the clock selection.

Is there a cap on baud-rate for the LPUART?

Are there any other special considerations I should have in mind when writing code for it?

Currently my application gets stuck in an infinite loop here, in .../MaximSDK/Libraries/PeriphDrivers/Source/UART/uart_ai85.c

    if (freq > 0) {
        // Enable baud clock and wait for it to become ready.
        uart->ctrl |= MXC_F_UART_CTRL_BCLKEN;
        while (((uart->ctrl & MXC_F_UART_CTRL_BCLKRDY) >> MXC_F_UART_CTRL_BCLKRDY_POS) == 0) {}
    }

after a call to
error = MXC_UART_Init(MXC_UART_GET_UART(3), 9600, MXC_UART_IBRO_CLK);

I have the same inf loop issue when i try MXC_UART_ERTCO_CLK as well.

@khavernathy
Copy link
Author

khavernathy commented Nov 12, 2024

More context here on how I'm initializing the UART. I'm using a MAX78000 FTHR.

void UART_Handler(void) {MXC_UART_AsyncHandler(MXC_UART_GET_UART(SIG_UART));}
void readCallback(mxc_uart_req_t* req, int error) {READ_FLAG = error;LED_Toggle(LED2);}

void uart_init() {

    // set P0.16 and P0.17 as GPIO "inputs" so they remain high impedance and don't interfere with LPUART.
    // TODO: do this properly somehow.
    mxc_gpio_cfg_t fakeGPIO;
    fakeGPIO.port = MXC_GPIO0;
    fakeGPIO.mask = MXC_GPIO_PIN_16;
    fakeGPIO.pad  = MXC_GPIO_PAD_NONE; // neither pull-up nor pull-down
    fakeGPIO.func = MXC_GPIO_FUNC_IN; // as input
    fakeGPIO.vssel= MXC_GPIO_VSSEL_VDDIOH; //voltage on pin set to 3.3v,
    mxc_gpio_cfg_t fakeGPIO2;
    fakeGPIO2.port = MXC_GPIO0;
    fakeGPIO2.mask = MXC_GPIO_PIN_17;
    fakeGPIO2.pad  = MXC_GPIO_PAD_NONE;
    fakeGPIO2.func = MXC_GPIO_FUNC_IN;
    fakeGPIO2.vssel= MXC_GPIO_VSSEL_VDDIOH; //voltage on pin set to 3.3v,
    MXC_GPIO_Config(&fakeGPIO);
    MXC_GPIO_Config(&fakeGPIO2);

    //UART init
    int error;

    NVIC_ClearPendingIRQ(MXC_UART_GET_IRQ(SIG_UART));
    NVIC_DisableIRQ(MXC_UART_GET_IRQ(SIG_UART));
    MXC_NVIC_SetVector(MXC_UART_GET_IRQ(SIG_UART), UART_Handler);
    NVIC_EnableIRQ(MXC_UART_GET_IRQ(SIG_UART));

    // use MXC_UART_ERTCO_CLK or MXC_UART_IBRO_CLK for UART3 (LPUART); MXC_UART_IBRO_CLK for UART0.
    error = MXC_UART_Init(MXC_UART_GET_UART(SIG_UART), UART_BAUD, MXC_UART_IBRO_CLK); // inf loop here
    if (error != E_NO_ERROR) {
        printf("-->Error initializing UART: %d\n", error);
        printf("HALTED\n");
        LED_On(LED1);
        while (1);
    }


    //## set the real UART pin to 3.3V 
    
    /* works for UART 0 */
    
    mxc_gpio_cfg_t gpioTXD;
    gpioTXD.port = MXC_GPIO1;  // MXC_GPIO0 for UART0; MXC_GPIO1 for UART2 according to datasheet...?  I was using MXC_GPIO1 with UART0 though..
    gpioTXD.mask = MXC_GPIO_PIN_1;
    gpioTXD.pad  = MXC_GPIO_PAD_NONE;
    gpioTXD.func = MXC_GPIO_FUNC_ALT1;
    gpioTXD.vssel= MXC_GPIO_VSSEL_VDDIOH; //voltage on UART pin set to 3.3v, important for iMX board
    MXC_GPIO_Config(&gpioTXD);
    
    mxc_gpio_cfg_t gpioTXD2 = { MXC_GPIO2, MXC_GPIO_PIN_7, MXC_GPIO_FUNC_ALT1, // p2.7 is LPUART TX. P2.6 is LPUART RX.
                                        MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0 };
    MXC_GPIO_Config(&gpioTXD2);

    MXC_UART_ClearRXFIFO(MXC_UART_GET_UART(SIG_UART));
    MXC_UART_ClearTXFIFO(MXC_UART_GET_UART(SIG_UART));

    /*
    mxc_uart_req_t uread_req;
    uread_req.uart     = MXC_UART_GET_UART(SIG_UART);
    uread_req.rxData   = uartRxData;
    uread_req.txData   = uartTxData;
    uread_req.rxLen    = BUFF_SIZE;
    uread_req.txLen    = BUFF_SIZE;
    uread_req.callback = readCallback;
    */

    mxc_uart_req_t uwrite_req;
    uwrite_req.uart     = MXC_UART_GET_UART(SIG_UART);
    uwrite_req.txData   = uartTxData;
    uwrite_req.rxData   = uartRxData;
    uwrite_req.txLen    = BUFF_SIZE;
    uwrite_req.rxLen    = 0;
    uwrite_req.callback = NULL;

    READ_FLAG = 1;

    int dma_channel;
    int ret = 0;

    printf("UART Firmware started on UART %i\n", SIG_UART);

}

@khavernathy
Copy link
Author

khavernathy commented Nov 20, 2024

I think it has something to do with this MR: #1123

It appears the merged changes in the MR are somehow not currently in the main branch of the code... @sihyung-maxim @EricB-ADI . Maybe it was reverted later?

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

1 participant