Skip to content

Commit

Permalink
New usart
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKK committed Apr 13, 2014
1 parent ed26379 commit d0d4645
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 126 deletions.
165 changes: 47 additions & 118 deletions CORTEX_M4F_STM32F407ZG-SK/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/** @addtogroup Template
* @{
*/
Expand All @@ -41,12 +42,13 @@
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
extern uint8_t demoMode;

void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* USART2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* USART1 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* GPIOA clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
}
Expand All @@ -66,13 +68,13 @@ void GPIO_Configuration(void)
GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART2); // USART2_TX
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART2); // USART2_RX
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1); // USART1_TX
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1); // USART1_RX
}

/**************************************************************************************/

void USART2_Configuration(void)
void USART1_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;

Expand All @@ -91,137 +93,64 @@ void USART2_Configuration(void)
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(USART2, &USART_InitStructure);
USART_Cmd(USART2, ENABLE);
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
}

void USART2_puts(char* s)
void USART1_puts(char* s)
{
while(*s) {
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, *s);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, *s);
s++;
}
}

/**************************************************************************************/
/*int main(void)*/
/*{*/
/*RCC_Configuration();*/
/*GPIO_Configuration();*/
/*USART2_Configuration();*/

/*USART2_puts("Hello World!\r\n");*/
/*USART2_puts("Just for STM32F429I Discovery verify USART2 with USB TTL Cable\r\n");*/
/*while(1)*/
/*{*/
/*while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);*/
/*char t = USART_ReceiveData(USART2);*/
/*if ((t == '\r')) {*/
/*while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);*/
/*USART_SendData(USART2, t);*/
/*t = '\n';*/
/*}*/
/*while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);*/
/*USART_SendData(USART2, t);*/
/*}*/

/*while(1); // Don't want to exit*/
/*}*/

void busyloop( uint32_t delay )
static void main1( void *pvParameters )
{
while( delay ) delay--;
}

const TickType_t xDelay = 100 / portTICK_PERIOD_MS;
RCC_Configuration();
GPIO_Configuration();
USART1_Configuration();

static void UsartTask(void *pvParameters)
{
STM_EVAL_LEDInit( LED4 );
while( 1 ){
USART1_puts("Hello World!\r\n");
USART1_puts("Just for STM32F429I Discovery verify USART1 with USB TTL Cable\r\n");

for( ;; )
{
vTaskDelay( xDelay );
STM_EVAL_LEDToggle( LED4 );
}
vTaskDelay( 500 );
}
}

static void LEDTask( void *pvParameters)
int main (void)
{
STM_EVAL_LEDInit( LED3 );

for(;;){
STM_EVAL_LEDToggle(LED3);
vTaskDelay( xDelay );
}
xTaskCreate( main1, (signed char*) "main1", 128, NULL, tskIDLE_PRIORITY + 1, NULL );
vTaskStartScheduler();
}

static void ButtonTask( void *pvParameters )
{
STM_EVAL_LEDInit( LED3 );

while(1) {
if( STM_EVAL_PBGetState( BUTTON_USER ) ){
STM_EVAL_LEDOn( LED3 );
while( STM_EVAL_PBGetState( BUTTON_USER ) );
STM_EVAL_LEDOff( LED3 );
}
}
}
#ifdef USE_FULL_ASSERT

static void LCDTask( void *pvParameters )
{
LCD_Init();
LCD_LayerInit();
IOE_Config();
LTDC_Cmd( ENABLE );
LCD_SetLayer(LCD_FOREGROUND_LAYER);
LCD_Clear(LCD_COLOR_RED);
LCD_DrawLine( 0x50, 0x50, 0x50, 0x0000 );
LCD_DisplayStringLine(LCD_LINE_6,(uint8_t*)"Hello World");

while(1){

if( IOE_TP_GetState()->TouchDetected ){
LCD_Clear(LCD_COLOR_BLUE);
LCD_DisplayStringLine(LCD_LINE_6,(uint8_t*)"Foooo");
while( IOE_TP_GetState()->TouchDetected );
}
}
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

/* Infinite loop */
while (1)
{
}
}
#endif

static void LCDTaskX( void *pvParameters )
{
LCD_Init();
LCD_LayerInit();
IOE_Config();
LTDC_Cmd( ENABLE );
LCD_SetLayer(LCD_FOREGROUND_LAYER);
LCD_Clear(LCD_COLOR_MAGENTA);
LCD_DrawLine( 0x50, 0x50, 0x50, 0x0000 );
LCD_DisplayStringLine(LCD_LINE_6,(uint8_t*)"Kyoka!");

while(1){
}
}
/**
* @}
*/

//Main Function
int main(void)
{
STM_EVAL_PBInit( BUTTON_USER, BUTTON_MODE_GPIO );

if( STM_EVAL_PBGetState(BUTTON_USER) ){
xTaskCreate(LCDTaskX, (signed char*)"LCDTaskX", 128, NULL, tskIDLE_PRIORITY+1, NULL);
}
else{
//Create Task For USART
xTaskCreate(UsartTask, (signed char*)"UsartTask", 128, NULL, tskIDLE_PRIORITY+1, NULL);
/*xTaskCreate(LEDTask, (signed char*)"LEDTask", 128, NULL, tskIDLE_PRIORITY+1, NULL);*/
xTaskCreate(ButtonTask, (signed char*)"ButtonTask", 128, NULL, tskIDLE_PRIORITY+1, NULL);
xTaskCreate(LCDTask, (signed char*)"LCDTask", 128, NULL, tskIDLE_PRIORITY+1, NULL);
}

//Call Scheduler
vTaskStartScheduler();
}

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
2 changes: 0 additions & 2 deletions CORTEX_M4F_STM32F407ZG-SK/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

/* Includes ------------------------------------------------------------------*/
#include "stm32f429i_discovery.h"
#include "stm32f429i_discovery_lcd.h"
#include "stm32f429i_discovery_ioe.h"


/* Exported types ------------------------------------------------------------*/
Expand Down
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,7 @@ OBJS += \
$(PWD)/CORTEX_M4F_STM32F407ZG-SK/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dma.o \
$(PWD)/CORTEX_M4F_STM32F407ZG-SK/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_spi.o \
$(PWD)/CORTEX_M4F_STM32F407ZG-SK/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_exti.o \
$(PWD)/CORTEX_M4F_STM32F407ZG-SK/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dma2d.o \
$(PWD)/CORTEX_M4F_STM32F407ZG-SK/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_ltdc.o \
$(PWD)/CORTEX_M4F_STM32F407ZG-SK/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_fmc.o \
$(PWD)/Utilities/STM32F429I-Discovery/stm32f429i_discovery.o \
$(PWD)/Utilities/STM32F429I-Discovery/stm32f429i_discovery_sdram.o \
$(PWD)/Utilities/STM32F429I-Discovery/stm32f429i_discovery_lcd.o \
$(PWD)/Utilities/STM32F429I-Discovery/stm32f429i_discovery_ioe.o

CFLAGS += -DUSE_STDPERIPH_DRIVER
CFLAGS += -I $(PWD)/CORTEX_M4F_STM32F407ZG-SK \
Expand Down

0 comments on commit d0d4645

Please sign in to comment.