2012-10-16 08:00 AM
I would use the printf function to transmit strings of hyperterminal, but if I use the printf function, the microcontroller stops!
I am developing my code on STM32F4 Discovery2012-10-16 10:25 AM
Where do you expect the data to go?
Retargeting Keil's output to a USART is pretty easy.https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/DispForm.aspx?ID=2606
2012-10-16 12:50 PM
I need to send data to the PC through the RS232, I do not need to receive from the PC but only print strings from the microcontroller to the PC, I need to use a function like
printf (string myString) I used this code include#include <
stm32f4_discovery.h
>
#include <
stdio.h
>
statement GPIO
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);
configuration USART
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
If I use USART_SendData(USART3, 0x49);
it's all right but i I us printf(''hello''); the microcontrollers stops
''this the code you suggested to another user some time ago, I found in an old debate''
I have already provided the converter levels USART -> RS232
2012-10-16 02:00 PM
it's all right but i I us printf(''hello''); the microcontrollers stops
Because it's probably ploughing into an SWI hook that it expects you to be servicing. A disassembly or trace should be illustrative. Keil suppresses this with a pragma.#pragma import(__use_no_semihosting_swi)
And then targeted to your hardware via character output routines
//******************************************************************************
// Hosting of stdio functionality through USART3
//******************************************************************************
#include <
rt_misc.h
>
#pragma import(__use_no_semihosting_swi)
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
int fputc(int ch, FILE *f)
{
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, ch);
return(ch);
}
int fgetc(FILE *f)
{
char ch;
while(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET);
ch = USART_ReceiveData(USART3);
return((int)ch);
}
int ferror(FILE *f)
{
/* Your implementation of ferror */
return EOF;
}
void _ttywrch(int ch)
{
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, ch);
}
void _sys_exit(int return_code)
{
label: goto label; /* endless loop */
}
/**************************************************************************************/
2012-10-16 02:14 PM
I'm sorry but I can not understand ...
to solve my problem di I have to define # pragma import (__use_no_semihosting_swi)??2012-10-16 06:21 PM
The take away here is that by default it links in library code using SWI calls (Software Interrupts) to perform OS level functions. Functions you don't provide, and it consequently crashes, Hard Faults, whatever.
You have to suppress that and provide IO routines to your hardware, as the library code has no idea about specific chips or boards. I have provided specific code to do this, for Keil, but you could refer to other documentation/examples of retargeting if this would help you.2012-10-17 12:43 PM
thanks
for your help
and
your kindness
!
I would like
to ask your advice
,some time
ago
you suggested
''
The DefinitiveGuide to the
ARM
Cortex-
M3''but is
there
a
similar
guide for the
M4
microcontroller
?
2012-10-17 04:36 PM
There isn't an M4 volume, but the M0 one is the newest and much thicker, to be honest they are covering a lot of the same material. So with the exception of the floating point unit they are all fairly similar. The M3 editions seem to exist fairly readily on the internet so I'd browse those first.
ARM has some very good TRM (Technical Reference Manuals) See also the resources tab herehttp://www.arm.com/products/processors/cortex-m/cortex-m4-processor.php
2012-10-19 11:20 AM
Actually the M0 book is only about 50pages longer. It looks and feels much ''thicker'', because the paper used in the M0 book is of a heavier stock. I wish they had used the same thinner paper that was used on the M3 book though.
2015-10-24 02:11 PM
Since this thread started, Joseph Yiu has a book covering the M3/M4
http://www.amazon.com/Definitive-Cortex%C2%AE-M3-Cortex%C2%AE-M4-Processors-Edition/dp/0124080820
An there is also this book from Trevor Martinhttp://www.amazon.com/Designers-Guide-Cortex-M-Processor-Family/dp/0080982964