Skip to content

Commit

Permalink
Got USART3_TX DMA working.
Browse files Browse the repository at this point in the history
  • Loading branch information
waynegramlich committed May 7, 2021
1 parent 52e3814 commit d96c7f2
Show file tree
Hide file tree
Showing 13 changed files with 335 additions and 18 deletions.
10 changes: 9 additions & 1 deletion bin/uros_nucleo_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,13 @@ echo "To flash the firmware to the microcontroller run the following commands:"
echo " cd $WS_DIR"
echo " source /opt/ros/foxy/setup.bash"
echo " source install/local_setup.bash"
echo " ros2 run micro_ros_setup flash_firmware."
echo " ros2 run micro_ros_setup flash_firmware.sh"
echo ""
echo "To start the agent:"
echo " cd $WS_DIR"
echo " source /opt/ros/foxy/setup.bash"
echo " source install/local_setup.bash"
echo " sudo adduser $(whoami) dailout # Only need to do once"
echo " # Logout log back in to get groups to stick. Verify with 'groups' command"
echo " ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyAMA0"
echo ""
Binary file added doc/stm32f7xxx_reference_manual.pdf
Binary file not shown.
41 changes: 39 additions & 2 deletions electrical/master_board/rev_a/issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,57 @@
24. The motor driver needs a .1µF capacitor between pin-11 (VCP) and pin-12 (VM).
25. The ESTOP LED is inverted. It should be ON for an ESTOP not OFF.
26. The RxD and TxD pins on U19 are swapped.
27. There is something weird going on with power coming in from the STLink USB connector
27. There is something weird going on with power coming in from the ST-Link USB connector
event when the Nucleo is powered by E5V jumper.
28. The right encoder is rotated 180 degrees along the Z-axis and is incompatible with the
associated encoder.
29. The labels on the encoder signals are swapped. LQUAD_A/LQUAD_B are connected to the
right motor/encoder and RQUAD_A/RQUAD_B are connected to the left encoder.
30. The serial port on the microcontroll is connected to the console pins on the RasPi4.
30. The serial port on the microcontroller is connected to the console pins on the RasPi4.
This is a mistake. Instead, use UART5 on the RasPi4.
31. The Motor controller will start with motors at full speed on power-up. Add pull-down/pull-up
resistors to the two CTL pins for each motor to force them into a known (and safe) state when
starting up. Likewise the SLEEP pin needs a power-up pull-up/down resistor to put it into a
known state on power up.
32. UART3 can be connected to either the ST-LINK or the Morpho Pins:
* STLK_TX (Nucleo Scehmatic Name):
* ST-Link:
* U2-Pin 12
* CN5:TX (Upper)
* Nucleo:
* PD9
* U8B-Pin 78
* USART3_RX
* SB6 Closed=>ST-Link <==== Open SB6
* SB4 Closed=>Morpho CN11-69
* Pi4
* TXD3: Pin 7
* STLK_RX (Nucleo Scehmatic Name):
* ST-Link:
* U2-Pin 13:
* CN5: RX (Lower)
* Nucleo:
* PD8
* U8B-Pin 77
* USART3_TX
* SB5 Closed=>ST-Link
* SB7 Closed=>Morpho CN12-10
* Pi 4
* RXD3 Pin 29

<!--
7: TXD3(Pi4) Avail
8: TXD0 or TXD1(Pi4) SBC_TX
10: RXD0 or RXD1(Pi4) SBC_RX
21: RXD4 (Pi4) Avail
24: TXD4 (Pi4) SBC_ALIVE
27: TXD2 (Pi4) ID_SDA
28: RXD2 (Pi4) ID_SCL
29: RXD3 (Pi4) Avail
32: TXD5 (Pi4) Avail (Wired to USART1)
33: RXD5 (Pi4) Avail (Wired to USART1)
RasPi4:
* Pin 8 => TXD1
* Pin 10 <= RXD1
Expand Down
1 change: 1 addition & 0 deletions software/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uros_ws/
103 changes: 103 additions & 0 deletions software/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2110,6 +2110,26 @@ Now run `stm33cubemx`:

This completes all of the steps needed to run the Blinky program.

<!--
To configure a Raspberry Pi 4 UART:
edit the `/boot/firmare/usercfg.txt`
#dtoverlay=uart1
#dtoverlay=uart2
#dtoverlay=uart3
#dtoverlay=uart4
#dtoverlay=uart5
dtoverlay=disable-bt
Remove the comment for the uarts you want enabled.
The are allocated as `/dev/ttyAMAx`, where `x` is is `0`, `1` in the order of the
the uarts enabled.
file `
..>
## Next steps:
### Microcode download
Expand Down Expand Up @@ -2273,4 +2293,87 @@ To copy an Eclipse project.
* Use the file browser to locate the empty directory you created and select it.
* Hit [OK] (or whatever it is called.)
* USART3
* Mode:
* Mode: Asynchronous
* Hardware Flow Control (RS232): Disable
* Configuration:
* Parameter Settings
* Basic Parameters
* Baud Rate: 115200
* Word Length 8 BIts (including Parity)
* Parity: None
* Stop Bits: 1
* Advanced Parameters:
* Data Direction: Receive and Transmit
* Oversampling: 16 Samples
* Single Sample: Disable
* Advance Features:
* Auto Baudrate: Disable
* TX Pin Active Level Inversion: Disable
* RX Pin Active Level Inversion: Disable
* Data Inversion: Disable
* TX and RX Pins Swapping: Disable
* Overrun: Enable
* DMA on RX Error: Enable
* MSB First: Disable
* User Constants:
* blank
* NVIC Settings:
* DMA stream 1 global interrupt:
* Enabled: False
* Preemption Priority: 5
* Sub-priority: 0
* DMA stream 1 global interrupt:
* Enabled: False
* Preemption Priority: 5
* Sub-priority: 0
* USART3 global interrupt
* Enabled: True
* Preemption Priority: 5
* Sub-priority: 0
* DMA Settings:
* USART3_TX:
* Stream: DMA1 Stream 3
* Direction: Memory To Peripheral
* Priority: Low
* DMA Request Settings:
* Mode: Normal
* Increment Address:
* Peripheral: Disable
* Memory: Enable
* Use Fifo: Disable
* Use Fifo: Disable
* Threshold: Not visible when fifo disabled
* Data Width:
* Peripheral: Byte
* Memory: Byte
* Burst Size:
* Peripheral: Not visible when fifo disabled
* Memory: Not visible when fifo disableda
* USART3_RX:
* Stream: DMA1 Stream 1
* Direction: Peripheral to Memory
* Priority: Low
* Datawidth:
* Peripheral: Byte
* Memory: Byte
* Use Fifo: Disable
* GPIO Settings:
* USART3_TX:
* Pin Name: PD8
* GPIO output level: n/a
* GPIO Mode: Alternate Function Pull Push
* GPIO Pull-up: No pull-up
* Maximum output speed: Very High
* User: Label: <blank>
* Modified True
* USART3_RX:
* Pin Name: PD9
* GPIO output level: n/a
* GPIO Mode: Alternate Function Pull Push
* GPIO Pull-up: No pull-up
* Maximum output speed: Very High
* User: Label: <blank>
* Modified True
-->
52 changes: 52 additions & 0 deletions software/hr2-usart3-test/Core/Inc/dma.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
******************************************************************************
* @file dma.h
* @brief This file contains all the function prototypes for
* the dma.c file
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __DMA_H__
#define __DMA_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* DMA memory to memory transfer handles -------------------------------------*/

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

void MX_DMA_Init(void);

/* USER CODE BEGIN Prototypes */

/* USER CODE END Prototypes */

#ifdef __cplusplus
}
#endif

#endif /* __DMA_H__ */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
1 change: 1 addition & 0 deletions software/hr2-usart3-test/Core/Inc/stm32f7xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void DMA1_Stream3_IRQHandler(void);
/* USER CODE BEGIN EFP */

/* USER CODE END EFP */
Expand Down
55 changes: 55 additions & 0 deletions software/hr2-usart3-test/Core/Src/dma.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
******************************************************************************
* @file dma.c
* @brief This file provides code for the configuration
* of all the requested memory to memory DMA transfers.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/

/* Includes ------------------------------------------------------------------*/
#include "dma.h"

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/*----------------------------------------------------------------------------*/
/* Configure DMA */
/*----------------------------------------------------------------------------*/

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/**
* Enable DMA controller clock
*/
void MX_DMA_Init(void)
{

/* DMA controller clock enable */
__HAL_RCC_DMA1_CLK_ENABLE();

/* DMA interrupt init */
/* DMA1_Stream3_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Stream3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Stream3_IRQn);

}

/* USER CODE BEGIN 2 */

/* USER CODE END 2 */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
18 changes: 14 additions & 4 deletions software/hr2-usart3-test/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "dma.h"
#include "lptim.h"
#include "tim.h"
#include "usart.h"
Expand Down Expand Up @@ -90,6 +91,7 @@ int main(void)

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_USART3_UART_Init();
MX_TIM8_Init();
MX_LPTIM1_Init();
Expand All @@ -103,15 +105,23 @@ int main(void)
HAL_TIM_Encoder_Start(&htim8,TIM_CHANNEL_ALL);
HAL_LPTIM_Encoder_Start(&hlptim1,65535L);
uint8_t c;
// uint8_t i = 0;
while (1)
{
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
// Read right and left encoder counts
HAL_UART_Receive(&huart3, &c, 1, 0xffffffff);
HAL_UART_Transmit(&huart3, &c, 1, 100);
HAL_UART_Transmit(&huart3, &c, 1, 100);
// Read right and left encoder counts
HAL_UART_Receive(&huart3, &c, 1, 0xffffffff);
HAL_GPIO_TogglePin(LD1_GPIO_Port, LD1_Pin);
HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
HAL_UART_Transmit(&huart3, &c, 1, 100);
HAL_UART_Transmit(&huart3, &c, 1, 100);
// c = (i == 0 ? '\r' : (i == 1 ? '\n' : ' ' + i));
// HAL_UART_Transmit(&huart3, &c, 1, 100);
// i = (i + 1) & 0x3f;
// HAL_Delay(100);
}
/* USER CODE END 3 */
}
Expand Down
16 changes: 15 additions & 1 deletion software/hr2-usart3-test/Core/Src/stm32f7xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
/* USER CODE END 0 */

/* External variables --------------------------------------------------------*/

extern DMA_HandleTypeDef hdma_usart3_tx;
/* USER CODE BEGIN EV */

/* USER CODE END EV */
Expand Down Expand Up @@ -199,6 +199,20 @@ void SysTick_Handler(void)
/* please refer to the startup file (startup_stm32f7xx.s). */
/******************************************************************************/

/**
* @brief This function handles DMA1 stream3 global interrupt.
*/
void DMA1_Stream3_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Stream3_IRQn 0 */

/* USER CODE END DMA1_Stream3_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_usart3_tx);
/* USER CODE BEGIN DMA1_Stream3_IRQn 1 */

/* USER CODE END DMA1_Stream3_IRQn 1 */
}

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */
Expand Down
Loading

0 comments on commit d96c7f2

Please sign in to comment.