Skip to main content
Graduate
January 12, 2024
Solved

STM32 NUCLEO-L4A6ZG Resources and Examples

  • January 12, 2024
  • 3 replies
  • 3984 views

Hey,

I'm completely new to the topic of microcontrollers and currently trying to prepare for an internship (preparation and prior knowledge are not required, but I would still like to prepare myself). Since I already the chip (STM32L4A6) I'm going to work with, I bought a board (NUCLEO-L4A6ZG) with this chip. Despite finding a diverse set of resources and examples for other boards (I also checked the GitHub repos for examples, but the board wasn't available), but the only thing I could achieve was programming the LEDs and playing around with the buttons. The configuration of printf has so far been a complete failure (I tried using UART).

I've tried using the datasheet and the user manual for help, but that hasn't really helped me so far as I felt completely overwhelmed and lost.

I'm sorry if this is not the right place to ask for tips, resources and examples for this board and chip, to start with, but it would really help me.

 

Thanks

    This topic has been closed for replies.
    Best answer by TDK

    It doesn't look like there's much out there for this board in particular. However:

    All of the Nucleo-144 boards share the same circuit board. There are a few revisions of that board but they are mostly the same. That means examples from other boards like the NUCLEO-L4R5ZI should work on your board. Certainly printf over UART will have the same configuration.

    If there's something specific you're trying to do, and it's not working, post your code with sufficient detail and folks here are typically more than willing to find the issue. Problem statements like "it's not working" are harder to respond to with useful answers.

    3 replies

    TDKAnswer
    Super User
    January 12, 2024

    It doesn't look like there's much out there for this board in particular. However:

    All of the Nucleo-144 boards share the same circuit board. There are a few revisions of that board but they are mostly the same. That means examples from other boards like the NUCLEO-L4R5ZI should work on your board. Certainly printf over UART will have the same configuration.

    If there's something specific you're trying to do, and it's not working, post your code with sufficient detail and folks here are typically more than willing to find the issue. Problem statements like "it's not working" are harder to respond to with useful answers.

    stmaxAuthor
    Graduate
    January 12, 2024

    Thanks for the quick reply, that has already helped me a lot! Just one more quick question. How exactly did you recognize that the examples for e.g. NUCLEO-L4R5ZI could be compatible? Is it because it is also a low power board and does it mean that other examples of other low power boards could also be compatible? Or are there other factors by which the revisions of that board can be recognized?

    Super User
    January 12, 2024

    >How exactly did you recognize that the examples for e.g. NUCLEO-L4R5ZI could be compatible?

    Not L4R5ZI. I wrote: STM32L496ZG. How I recognized that they are compatible... Just by intuition. Looking at the L4 names, the 3rd char after L4 is 5,6...9, A. So I assumed that "9" is closest predecessor of "A".

    Me:  Hi Copilot, another quick question: which STM32 is most similar to STM32L4A6ZG?

    Copilot: According to the web search results, one possible alternative to STM32L4A6ZG is STM32L496ZG, which has similar features and performance, but does not have the external SMPS and AES+HASH hardware accelerator[1]. Another option is STM32L4P5ZG, which has more flash memory and a higher maximum operating frequency, but is not widely available[2]. You can also use the online tool[3] to compare different STM32 microcontrollers based on your criteria.

    Frankly I'd rather expect to find this information on the ST web page of Nucleo-L4A.

     

    Super User
    January 12, 2024

    From the available ST website documentation, STM32L4A6ZG is similar to STM32L496ZG, so examples for Nucleo-L496ZG should work for your board  (or STM32L496ZG-P? there are two of them...)

    > The configuration of printf has so far been a complete failure (I tried using UART).

    It looks like a machine already does simple programming tasks better than a (beginner) human...

     

    Transcript....

    Me: Dear Copilot, can you write code for STM32L4 MCU to configure printf to send data to UART? The code should be for GCC compiler with newlib.

    Copilot: 

    This is a challenging task, but I will try to generate some code for you. Please note that this code is not tested and may not work as expected. You should always verify and modify the code according to your needs and specifications. I am not responsible for any errors or damages caused by this code.

    Here is the code I generated:

     

     

     

    #include <stdio.h>
    #include <stm32l4xx.h>
    #include <stm32l4xx_hal.h>
    
    // Define the UART handle and the baud rate
    UART_HandleTypeDef huart;
    #define BAUD_RATE 115200
    
    // Define the prototype for the putchar function
    int __io_putchar (int ch);
    
    // Initialize the UART peripheral
    void UART_Init (void)
    {
     // Enable the clock for USART2
     __HAL_RCC_USART2_CLK_ENABLE ();
    
     // Configure the UART pins
     GPIO_InitTypeDef GPIO_InitStruct = {0};
     GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3; // PA2: TX, PA3: RX
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; // Alternate function, push-pull
     GPIO_InitStruct.Pull = GPIO_NOPULL; // No pull-up or pull-down
     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; // High speed
     GPIO_InitStruct.Alternate = GPIO_AF7_USART2; // USART2 alternate function
     HAL_GPIO_Init (GPIOA, &GPIO_InitStruct); // Initialize GPIOA
    
     // Configure the UART parameters
     huart.Instance = USART2; // USART2 instance
     huart.Init.BaudRate = BAUD_RATE; // Baud rate
     huart.Init.WordLength = UART_WORDLENGTH_8B; // 8-bit data
     huart.Init.StopBits = UART_STOPBITS_1; // 1 stop bit
     huart.Init.Parity = UART_PARITY_NONE; // No parity
     huart.Init.Mode = UART_MODE_TX_RX; // Transmit and receive mode
     huart.Init.HwFlowCtl = UART_HWCONTROL_NONE; // No hardware flow control
     huart.Init.OverSampling = UART_OVERSAMPLING_16; // 16x oversampling
     HAL_UART_Init (&huart); // Initialize the UART
    }
    
    // Redirect the printf output to the UART
    int __io_putchar (int ch)
    {
     // Transmit the character using HAL_UART_Transmit
     HAL_UART_Transmit (&huart, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
     return ch;
    }
    
    // Main function
    int main (void)
    {
     // Initialize the HAL library
     HAL_Init ();
    
     // Initialize the UART
     UART_Init ();
    
     // Print a message using printf
     printf ("Hello, world!\n");
    
     // Infinite loop
     while (1)
     {
     // Do nothing
     }
    }

     

     

    Me:  Impressed! thank you!

    Copilot: You’re very welcome. I’m glad you liked the code I generated for you. I enjoy creating content for you and helping you with your tasks. Is there anything else I can do for you?

    This looks pretty good, except of missing SystemClock_Config() call after line 52. The UART_Init will be generated by Cube for the UART that you've selected, with baudrate and other options that you've selected

    Now your turn @stmax ))

     

     

    stmaxAuthor
    Graduate
    January 12, 2024

    Thanks, now i got it!