aboutsummaryrefslogtreecommitdiffstats
path: root/src/fsm
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-01-24 19:02:36 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-01-24 19:02:36 +0100
commit81ebfdcc934473bd913e0be44c257481b8fd2876 (patch)
tree8b49e0fa574413c46360468d4ad036bce517e497 /src/fsm
parent34592857619fe7b87b84f8ff12a149c20aefbc10 (diff)
downloadglutte-o-matic-81ebfdcc934473bd913e0be44c257481b8fd2876.tar.gz
glutte-o-matic-81ebfdcc934473bd913e0be44c257481b8fd2876.tar.bz2
glutte-o-matic-81ebfdcc934473bd913e0be44c257481b8fd2876.zip
Move debug UART to USART2, audio broken
Diffstat (limited to 'src/fsm')
-rw-r--r--src/fsm/audio.c6
-rw-r--r--src/fsm/main.c17
-rw-r--r--src/fsm/pio.txt9
-rw-r--r--src/fsm/usart.c51
-rw-r--r--src/fsm/usart.h4
5 files changed, 52 insertions, 35 deletions
diff --git a/src/fsm/audio.c b/src/fsm/audio.c
index e74e93a..c1303b1 100644
--- a/src/fsm/audio.c
+++ b/src/fsm/audio.c
@@ -28,14 +28,16 @@ void InitializeAudio(int plln, int pllr, int i2sdiv, int i2sodd) {
DMARunning = false;
// Turn on peripherals.
- // Assume GPIOA,B,C,D already on
+ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
+ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
+ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
// Assume I2C is set up
// Configure reset pin.
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;;
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
diff --git a/src/fsm/main.c b/src/fsm/main.c
index 1712810..54fc485 100644
--- a/src/fsm/main.c
+++ b/src/fsm/main.c
@@ -72,7 +72,7 @@ void vApplicationStackOverflowHook( TaskHandle_t xTask,
int main(void) {
init();
usart_init();
- usart_debug_puts("glutt-o-matique version " GIT_VERSION "\n");
+ usart_debug_puts("glutt-o-matique version " GIT_VERSION "\r\n");
TaskHandle_t task_handle;
xTaskCreate(
@@ -123,6 +123,8 @@ static void launcher_task(void *pvParameters)
trigger_fault(FAULT_SOURCE_MAIN);
}
+ usart_debug_puts("8");
+
xTaskCreate(
exercise_fsm,
"TaskFSM",
@@ -135,6 +137,8 @@ static void launcher_task(void *pvParameters)
trigger_fault(FAULT_SOURCE_MAIN);
}
+ usart_debug_puts("9");
+
xTaskCreate(
gps_monit_task,
"TaskGPSMonit",
@@ -147,12 +151,15 @@ static void launcher_task(void *pvParameters)
trigger_fault(FAULT_SOURCE_MAIN);
}
+ usart_debug_puts("A");
+
InitializeAudio(Audio16000HzSettings);
+ usart_debug_puts("B");
SetAudioVolume(210);
- usart_debug_puts("7");
+ usart_debug_puts("C");
PlayAudioWithCallback(audio_callback, NULL);
- usart_debug_puts("8\n");
+ usart_debug_puts("D\r\n");
/* We are done now, suspend this task
@@ -185,7 +192,7 @@ static void detect_button_press(void *pvParameters)
if (pin_high_count == pin_high_thresh) {
tm_trigger = 1;
- usart_debug_puts("Bouton bleu\n");
+ usart_debug_puts("Bouton bleu\r\n");
}
else if (pin_high_count == 0) {
tm_trigger = 0;
@@ -241,7 +248,7 @@ static void gps_monit_task(void *pvParameters)
}
if (gps_time.sec % 30 == 0) {
- usart_debug("T_GPS %04d-%02d-%02d %02d:%02d\n",
+ usart_debug("T_GPS %04d-%02d-%02d %02d:%02d\r\n",
gps_time.year, gps_time.month, gps_time.day,
gps_time.hour, gps_time.min);
}
diff --git a/src/fsm/pio.txt b/src/fsm/pio.txt
index 72ff6ee..64f5b04 100644
--- a/src/fsm/pio.txt
+++ b/src/fsm/pio.txt
@@ -12,8 +12,8 @@ Orange in UART RX to GPS TX PD9
Debug USART
-----------
-- out UART TX to PC RX PA9
-- in UART RX to PC TX PA10
+- out UART TX to PC RX PA2
+- in UART RX to PC TX PA3
For the little test board with the 3 LEDs and switches
------------------------------------------------------
@@ -29,6 +29,11 @@ Green in D_n PC11
I2C to Audio Codec
------------------
+- o codec reset PD4
+- - I2S3 MCK PC7
+- - I2S3 CK PC10
+- - I2S3 SD PC12
+- - I2S3 WS PA4
- i/o SDA PB9
- i/o SCL PB6
diff --git a/src/fsm/usart.c b/src/fsm/usart.c
index 57194db..31c112e 100644
--- a/src/fsm/usart.c
+++ b/src/fsm/usart.c
@@ -39,9 +39,9 @@
const uint16_t GPIOD_PIN_USART3_TX = GPIO_Pin_8;
const uint16_t GPIOD_PIN_USART3_RX = GPIO_Pin_9;
-/* USART 3 on PA9 and PA10 */
-const uint16_t GPIOA_PIN_USART1_TX = GPIO_Pin_10;
-const uint16_t GPIOA_PIN_USART1_RX = GPIO_Pin_9;
+/* USART 2 on PA2 and PA3 */
+const uint16_t GPIOA_PIN_USART2_RX = GPIO_Pin_3;
+const uint16_t GPIOA_PIN_USART2_TX = GPIO_Pin_2;
// The ISR writes into this buffer
static char nmea_sentence[MAX_NMEA_SENTENCE_LEN];
@@ -54,21 +54,21 @@ static QueueHandle_t usart_nmea_queue;
void usart_init()
{
// ============== PC DEBUG USART ===========
- RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
+ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStruct;
- GPIO_InitStruct.GPIO_Pin = GPIOA_PIN_USART1_RX | GPIOA_PIN_USART1_TX;
+ GPIO_InitStruct.GPIO_Pin = GPIOA_PIN_USART2_RX | GPIOA_PIN_USART2_TX;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStruct);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);
- // Setup USART1 for 9600,8,N,1
+ // Setup USART2 for 9600,8,N,1
USART_InitTypeDef USART_InitStruct;
USART_InitStruct.USART_BaudRate = 9600;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
@@ -76,24 +76,22 @@ void usart_init()
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
- USART_Init(USART1, &USART_InitStruct);
+ USART_Init(USART2, &USART_InitStruct);
-#if 0
- // enable the USART1 receive interrupt
- USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
+ // enable the USART2 receive interrupt
+ USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 6;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
- NVIC_SetPriority(USART1_IRQn, 6);
+ NVIC_SetPriority(USART2_IRQn, 6);
- // finally this enables the complete USART1 peripheral
- USART_Cmd(USART1, ENABLE);
-#endif
+ // finally this enables the complete USART2 peripheral
+ USART_Cmd(USART2, ENABLE);
}
void usart_gps_init()
@@ -152,8 +150,8 @@ static void usart_puts(USART_TypeDef* USART, const char* str)
{
while(*str) {
// wait until data register is empty
- while ( !(USART->SR & 0x00000040) );
USART_SendData(USART, *str);
+ while(USART_GetFlagStatus(USART, USART_FLAG_TXE) == RESET) ;
str++;
}
}
@@ -171,13 +169,13 @@ void usart_debug(const char *format, ...)
va_list list;
va_start(list, format);
vsnprintf(usart_debug_message, MAX_MSG_LEN-1, format, list);
- usart_puts(USART1, usart_debug_message);
+ usart_puts(USART2, usart_debug_message);
va_end(list);
}
void usart_debug_puts(const char* str)
{
- usart_puts(USART1, str);
+ usart_puts(USART2, str);
}
int usart_get_nmea_sentence(char* nmea)
@@ -230,11 +228,16 @@ void USART3_IRQHandler(void)
}
}
-void USART1_IRQHandler(void)
+void USART2_IRQHandler(void)
{
- if (USART_GetITStatus(USART1, USART_IT_RXNE)) {
- char t = USART1->DR;
- (void)t; // ignore t
+ if (USART_GetITStatus(USART2, USART_IT_RXNE)) {
+ char t = USART2->DR;
+ if (t == 'h') {
+ usart_debug_puts("help: no commands supported yet!\r\n");
+ }
+ else {
+ usart_debug("Unknown command %c\r\n", t);
+ }
}
}
diff --git a/src/fsm/usart.h b/src/fsm/usart.h
index 7d4bfa9..9d9b59c 100644
--- a/src/fsm/usart.h
+++ b/src/fsm/usart.h
@@ -25,7 +25,7 @@
/* This handles the USART 3 to the GPS receiver, and fills a queue of
* NMEA messages.
*
- * It also handles the debug USART 1 and allows sending messages to the PC.
+ * It also handles the debug USART 2 and allows sending messages to the PC.
*/
#ifndef __USART_H_
@@ -33,7 +33,7 @@
#define MAX_NMEA_SENTENCE_LEN 256
-// Initialise USART1 for PC debugging
+// Initialise USART2 for PC debugging
void usart_init(void);
// Initialise USART3 for GPS and NMEA queue