Become a leader in the IoT community!

New DevHeads get a 320-point leaderboard boost when joining the DevHeads IoT Integration Community. In addition to learning and advising, active community leaders are rewarded with community recognition and free tech stuff. Start your Legendary Collaboration now!

Step 1 of 5

CREATE YOUR PROFILE *Required

Change Email
OR
Step 2 of 5

WHAT BRINGS YOU TO DEVHEADS? *Choose 1 or more

Collaboration & Work 🤝
Learn & Grow 📚
Contribute Experience & Expertise 🔧
Step 3 of 5

WHAT'S YOUR INTEREST OR EXPERTISE? *Choose 1 or more

Hardware & Design 💡
Embedded Software 💻
Edge Networking
Step 4 of 5

Personalize your profile

Step 5 of 5

Read & agree to our COMMUNITY RULES

  1. We want this server to be a welcoming space! Treat everyone with respect. Absolutely no harassment, witch hunting, sexism, racism, or hate speech will be tolerated.
  2. If you see something against the rules or something that makes you feel unsafe, let staff know by messaging @admin in the "support-tickets" tab in the Live DevChat menu.
  3. No age-restricted, obscene or NSFW content. This includes text, images, or links featuring nudity, sex, hard violence, or other graphically disturbing content.
  4. No spam. This includes DMing fellow members.
  5. You must be over the age of 18 years old to participate in our community.
  6. Our community uses Answer Overflow to index content on the web. By posting in this channel your messages will be indexed on the worldwide web to help others find answers.
  7. You agree to our Terms of Service (https://www.devheads.io/terms-of-service/) and Privacy Policy (https://www.devheads.io/privacy-policy)
By clicking "Finish", you have read and agreed to the our Terms of Service and Privacy Policy.

Why isn’t my printf output showing on the SWV ITM console for STM32F401CDU6?

Good day @everyone
I am trying to use the printf and the SWV for stm32f401CDU6 board

wrote my code on the stm32cubeIDE (main.c)
I have pasted the ITM funtionality code to the syscalls.c and have done the changes needed at the write function
I have done my debugging using 84MHz(which is the board frequency)
yet my printf code is not yet played on the SWV ITM date console(i have also done the port selection)

what can I do next

  1. ZacckOsiemo#0000

    People may need to see your code, this issue always catches me off in new projects have to spend an hour and it works

  2. Okpara Elvis#0000

    ok

  3. Okpara Elvis#0000

    i didn’t use the graphic approach
    0syscall.png1mainccc.png

  4. Umesh Lokhande#0000

    In `syscalls.c` file you need to add few more lines of code at the top. Here it is

    // Debug Exception & Monitor Control Register Base Address
    #define DEMCR                     *((volatile uint32_t*) 0xE000EDFCU)
    
    //ITM Register Address
    #define ITM_STIMULUS_PORT0        *((volatile uint32_t*) 0xE0000000)
    #define ITM_TRACE_EN            *((volatile uint32_t*) 0xE0000E00)
    
    void ITM_SendChar(uint8_t ch)
    {
        // Enable TRCENA
        DEMCR |= (1<<24);
    
        // Enable Stimulus Port0
        ITM_TRACE_EN |= (1<<0);
    
        // Read FIFO Status in bit[0]:
        while(!(ITM_STIMULUS_PORT0 & 1));
    
        // Write to ITM Stimulus Port0
        ITM_STIMULUS_PORT0 = ch;
    }
    
  5. Okpara Elvis#0000

    /////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Implementation of printf like feature using ARM Cortex M3/M4/ ITM functionality
    // This function will not work for ARM Cortex M0/M0+
    // If you are using Cortex M0, then you can use semihosting feature of openOCD
    /////////////////////////////////////////////////////////////////////////////////////////////////////////

    //Debug Exception and Monitor Control Register base address
    #define DEMCR *((volatile uint32_t*) 0xE000EDFCU )

    /* ITM register addresses */
    #define ITM_STIMULUS_PORT0 *((volatile uint32_t*) 0xE0000000 )
    #define ITM_TRACE_EN *((volatile uint32_t*) 0xE0000E00 )

    void ITM_SendChar(uint8_t ch)
    {

    //Enable TRCENA
    DEMCR |= ( 1 << 24); //enable stimulus port 0 ITM_TRACE_EN |= ( 1 << 0); // read FIFO status in bit [0]: while(!(ITM_STIMULUS_PORT0 & 1)); //Write to ITM stimulus port0 ITM_STIMULUS_PORT0 = ch; }

  6. Okpara Elvis#0000

    I have added this line of code
    the output is not display

  7. Umesh Lokhande#0000

    Also, confirm if in debugger settings you have setup properly especially to enable SWV & Clock settings. In your case may change for different clock speed if you’re not running @ 16MHz
    0Screenshot_2024-12-18_140402.png

  8. Okpara Elvis#0000

    Yes I have done that; enable the SWV and set clock speed to 84

  9. Umesh Lokhande#0000

    This code seems like missing pointers to hold memory addresses. Please copy paste my suggested lines of code or compare both carefully. Following part of your code

    // Debug Exception & Monitor Control Register Base Address
    #define DEMCR                     *((volatile uint32_t*) 0xE000EDFCU)
    
    //ITM Register Address
    #define ITM_STIMULUS_PORT0        *((volatile uint32_t*) 0xE0000000)
    #define ITM_TRACE_EN            *((volatile uint32_t*) 0xE0000E00)
    
  10. Okpara Elvis#0000

    ok

  11. Okpara Elvis#0000

    I have also used your suggested code line

    do you think the problem could e from the hardware

    And its my first time using this board
    0notworl.png1blackpill.jpg

  12. Umesh Lokhande#0000

    Unfortunately, I never used STM32 BlackPill. So it’ll be difficult for me to say anything
    whether it’s an issue with stlinkv2 clones or something

  13. Okpara Elvis#0000

    ok
    thanks for your effort

  14. Umesh Lokhande#0000

    Welcome!

  15. accur4te#0000

    @elvisokpara did you update your clone st link programmer firmware ? If yes than u have bricked it

  16. Okpara Elvis#0000

    yes did

  17. Okpara Elvis#0000

    this there anything I can do about that?

  18. Okpara Elvis#0000

    but the upgrade was successful

  19. accur4te#0000

    yeah but few people have reported it, after the new 1.17 update if you update your firmware of the Chinese clone programmer via the stm32 cube programmer , it will be rendered it useless.

  20. accur4te#0000

    try using another or a new clone

  21. accur4te#0000
  22. Umesh Lokhande#0000

    Recently, I’m using official STLINK-V3MODS programmer and debugger at just $ 9.30 ~ ₹ 792.00. You can even solder this programmer & debugger on a custom motherboard/pcb for field update!
    0stlinkmodv3.png

  23. undefined2001#0

    @elvisokpara is it solved?

  24. undefined2001#0

    or should I help?

  25. undefined2001#0

    after seeing the picture of your stlink sadly it doesn’t have SWO capality

  26. undefined2001#0

    image0.jpg

  27. undefined2001#0

    you need something like this to use that

  28. undefined2001#0

    see this has a SWO pin

  29. undefined2001#0

    now you can change your stlink or I can give you another suggestions that use printf via UART

  30. undefined2001#0

    if you need any help please mention me

CONTRIBUTE TO THIS THREAD

Browse other questions tagged