Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


modify the behaviour of scanf() stm32f3 discovery

I’m using Mac OSX and AC6 2.0.1.201705161428 on stm32f3 discovery. I’m trying to change the behaviour of scanf() function. To made this i modify the _read() function called by scanf(). I configure the USB as CDC class device and i want take data from a serial monitor, so i write some code into CDC_Receive_FS() to do this.The function CDC_receive_FS() receive 1 character and put it into an array. I implemented CDC_getChar(), a function to get the actual character of that array. The _read() function call CDC_getChar(), obtain the char and put it into ptr. At first execution the scanf() call the _read() function and i was able to obtain the string that i write into the serial monitor. The following calls of scanf() doesn’t call the _read(), so the _read() called once and never called again. if i pass %s as format specifier and i return a number that not is a power of 2 the _read() goes in loop, if i pass %d as format specifier does not go into loop. There is my _read() implementation

int j=0;
int _read (int file, char *ptr, int len)
{
j=0;
for(int k=0;k < CDC_getDim();k++){
ptrk=CDC_getChar();
j++;
}
return j;
}

the parameter len is always 1024. the value returned by the scanf() is always 1 regardless of the value returned by the _read(). I use also the linker option - -specs=nano.specs to use the newlib-nano. What can I do to make the scanf () call _read ()?

Hi, this is the _read() function I used to redirect scanf to my uart input. The read function needs to read only one byte at the time.

int _read (int file, char *ptr, int len)
{
HAL_UART_Receive(&huart2,(uint8_t*)ptr++,1,0xffff);
HAL_UART_Transmit(&huart2,(uint8_t *)(ptr-1),1,10);
if (*(ptr-1)==0x0D){
HAL_UART_Transmit(&huart2,(uint8_t *)”\n”,1,10);
*(ptr-1)=’\n’;
}

return 1;
}


 

Newest Forum Posts

  1. SPI on Nucleo_STMH533RE by royjamil, 20:13
  2. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  3. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  4. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  5. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  6. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  7. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  8. Build a project in "release" mode by tang, 2025-02-20 10:36
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35
  10. Fail to debug in Win 11 C/C++ by mortenlund, 2024-12-26 20:27

Last-Modified Blogs