chprintf() works but not sdWrite() Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
smbryan
Posts: 2
Joined: Tue Feb 26, 2019 1:29 pm

chprintf() works but not sdWrite()

Postby smbryan » Tue Feb 26, 2019 2:09 pm

Hey all,

I've been trying to get communicate over serial to my STM32F446RE Nucleo board. I was struggling with getting sdWrite/Put/Read/Get when I decided to try chprintf(). I'm guessing that I'm overlooking something basic and would appreciate an extra set of eyes.

I'm using the nucleo's built-in ST-Link v2-1 and monitoring the serial with "cat /dev/ttyACM0" after configuring the device with stty. The code below works for as expected for chprintf, but I get no response when I switch to sdWrite:

Code: Select all

#include "ch.h"
#include "hal.h"
#include "chprintf.h"

/* Serial configuration. */
static const SerialConfig myserialcfg = {
  115200,
  0,
  USART_CR2_STOP1_BITS,
  0
};

/* Dummy LED blinker thread. */
static THD_WORKING_AREA(waThdBlinker, 128);
static THD_FUNCTION(ThdBlinker, arg) {

  (void) arg;
  chRegSetThreadName("Blinker");

  while(true) {
    palToggleLine(LINE_LED_GREEN);
    chThdSleepMilliseconds(500);
  }
}

/* Application entry point. */
int main(void) {
  /* ChibiOS/HAL and ChibiOS/RT initialization. */
  halInit();
  chSysInit();

  /* Creating a dummy blinker thread. */
  chThdCreateStatic(waThdBlinker, sizeof(waThdBlinker), NORMALPRIO, ThdBlinker,
                    NULL);

  /* Enabling event on falling edge of PC13 signal.*/
  palEnablePadEvent(GPIOC, 13U, PAL_EVENT_MODE_FALLING_EDGE);

  /* Starting Serial Driver 2 with our configuration. */
  sdStart(&SD2, NULL);

  /* main() thread loop. */
  while (true) {
    /* Waiting for a falling edge.*/
    palWaitPadTimeout(GPIOC, 13U, TIME_INFINITE);

    /* Printing a string over USART2 using Serial driver.*/
    // sdWrite(&SD2, (uint8_t*)"Test\r\n", 6);
    chprintf((BaseSequentialStream*)&SD2, "Test");
  }
}


From halconf.h:

Code: Select all

#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
#define HAL_USE_SERIAL                      TRUE
#endif


mcuconf.h:

Code: Select all

/*
 * SERIAL driver system settings.
 */
#define STM32_SERIAL_USE_USART1             FALSE
#define STM32_SERIAL_USE_USART2             TRUE
#define STM32_SERIAL_USE_USART3             FALSE
#define STM32_SERIAL_USE_UART4              FALSE
#define STM32_SERIAL_USE_UART5              FALSE
#define STM32_SERIAL_USE_USART6             FALSE
#define STM32_SERIAL_USE_UART7              FALSE
#define STM32_SERIAL_USE_UART8              FALSE
#define STM32_SERIAL_USART1_PRIORITY        12
#define STM32_SERIAL_USART2_PRIORITY        12
#define STM32_SERIAL_USART3_PRIORITY        12
#define STM32_SERIAL_UART4_PRIORITY         12
#define STM32_SERIAL_UART5_PRIORITY         12
#define STM32_SERIAL_USART6_PRIORITY        12
#define STM32_SERIAL_UART7_PRIORITY         12
#define STM32_SERIAL_UART8_PRIORITY         12


Any help would be appreciated.

User avatar
Giovanni
Site Admin
Posts: 14779
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1174 times
Been thanked: 976 times

Re: chprintf() works but not sdWrite()

Postby Giovanni » Wed Feb 27, 2019 5:20 pm

Hi,

Sorry, I am unable to make a test until next week.

Giovanni

smbryan
Posts: 2
Joined: Tue Feb 26, 2019 1:29 pm

Re: chprintf() works but not sdWrite()

Postby smbryan » Fri Mar 01, 2019 8:09 pm

Thanks for checking in. Enjoy your time off!

User avatar
Giovanni
Site Admin
Posts: 14779
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1174 times
Been thanked: 976 times

Re: chprintf() works but not sdWrite()

Postby Giovanni » Sat Mar 02, 2019 9:22 am

I wish it was time off, more like 12 hours/day into a room with lots of people trying to make a new device work.

Giovanni

jcbless
Posts: 39
Joined: Wed Apr 16, 2025 2:29 pm
Has thanked: 6 times
Been thanked: 3 times

Re: chprintf() works but not sdWrite()

Postby jcbless » Thu Dec 18, 2025 11:22 pm

Similar to this previous user, I am unable to get sdWrite() to work (on SD7), but I can get chprintf() to work on a different channel. I can only get chprintf to work on that other channel (SD3) I need sdWrite() since some of my characters may be 0x0. I am using a STM32H753 processor.

If I use sdWrite() it just blocks that thread. If I used sdWriteTimeout(), it will not block forever, but it also doesn't send any characters out on the serial bus as seen with my oscilloscope.

Thanks,
John

User avatar
Giovanni
Site Admin
Posts: 14779
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1174 times
Been thanked: 976 times

Re: chprintf() works but not sdWrite()

Postby Giovanni » Fri Dec 19, 2025 6:27 am

There must be some issues with interrupt settings of that UART, moving this topic in "bug reports".

What version are you using? try trunk code if possible.

Giovanni

jcbless
Posts: 39
Joined: Wed Apr 16, 2025 2:29 pm
Has thanked: 6 times
Been thanked: 3 times

Re: chprintf() works but not sdWrite()

Postby jcbless » Fri Dec 19, 2025 4:09 pm

I am using version 21.11 of ChibiOS (chibios_stable-21.11.x).

What is the most efficient way to switch over and use the chibios_trunk or to use github code. In other words, what needs to be switched over in makefile's or settings in eclipse to make that change?

User avatar
Giovanni
Site Admin
Posts: 14779
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1174 times
Been thanked: 976 times

Re: chprintf() works but not sdWrite()

Postby Giovanni » Fri Dec 19, 2025 6:17 pm

You need to take makefiles and configuration files from trunk demos, not very different from 21.11.x.

Just import the trunk demos in Eclipse and you can build, change the CHIBIOS workspace variable to point to the trunk chibios root directory so projects can resolve the correct paths for symbolic links.

Giovanni

jcbless
Posts: 39
Joined: Wed Apr 16, 2025 2:29 pm
Has thanked: 6 times
Been thanked: 3 times

Re: chprintf() works but not sdWrite()  Topic is solved

Postby jcbless » Fri Dec 26, 2025 4:44 pm

I determined that this was my mistake. I had not added the palSetPadMode() to the code for my pins that were serial port pins. After adding it for my desired serial port, it then functioned properly.


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 59 guests