Skip to content

Commit

Permalink
DFU - start
Browse files Browse the repository at this point in the history
  • Loading branch information
russeree committed Jan 9, 2024
1 parent dca9b43 commit eeb700a
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 400 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"usbd_ioreq.h": "c",
"tim.h": "c",
"nyan_temp_sensor.h": "c",
"nyan_bitcoin.h": "c"
"nyan_bitcoin.h": "c",
"usb_otg.h": "c"
},
"cSpell.words": [
"BINTERVAL",
Expand Down
4 changes: 2 additions & 2 deletions Composite/AL94.I-CUBE-USBD-COMPOSITE_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
Expand All @@ -27,7 +27,7 @@

/**
MiddleWare name : AL94.I-CUBE-USBD-COMPOSITE.1.0.3
MiddleWare fileName : ./AL94.I-CUBE-USBD-COMPOSITE_conf.h
MiddleWare fileName : AL94.I-CUBE-USBD-COMPOSITE_conf.h
MiddleWare version :
*/
/*---------- _USBD_USE_HS -----------*/
Expand Down
20 changes: 16 additions & 4 deletions Core/Inc/nyan_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "nyan_bitcoin.h"
#include "nyan_eeprom_map.h"

#include "usb_device.h"

#define _NYAN_WELCOME_GUARD_TIME 2 // Currently a multiple of TIM7 Period (.777 seconds)
#define _NYAN_CDC_CHANNEL 0
#define _NYAN_CDC_RX_BUF_SZ 512
Expand All @@ -19,17 +21,19 @@

#define _NYAN_NUM_COMMANDS (sizeof(nyan_commands) / sizeof(nyan_commands[0]))

extern Eeprom24xx nos_eeprom; // 24xx Based EEPROM
extern LatticeIceHX nos_fpga; // Lattice ICE40HX4k FPGA driver access
extern NyanBitcoin nyan_bitcoin; // Nyan Keys Background Bitcoin Miner
extern Eeprom24xx nos_eeprom; // 24xx Based EEPROM
extern LatticeIceHX nos_fpga; // Lattice ICE40HX4k FPGA driver access
extern NyanBitcoin nyan_bitcoin; // Nyan Keys Background Bitcoin Miner
extern USBD_HandleTypeDef hUsbDevice; // USB Device for DFU Reset

static const char* const nyan_commands[] = {
"help",
"getinfo",
"getperf",
"write-bitstream",
"set-owner",
"bitcoin-miner-set"
"bitcoin-miner-set",
"dfu-mode"
};

typedef enum {
Expand Down Expand Up @@ -66,6 +70,7 @@ typedef enum {
NYAN_EXE_WRITE_BITSTREAM, /**< Execute command to write a bitstream to FPGA. */
NYAN_EXE_SET_OWNER, /**< Execute command to set the owner of the system. */
NYAN_EXE_BITCOIN_MINER_SET, /**< Execute command to configure the Bitcoin miner. */
NYAN_EXE_DFU_MODE, /**< Execute command to make nyan keys enter DFU Mode: Board version > .9e*/
NYAN_EXE_COMMAND_NOT_SUPPORTED, /**< Indicator for an unsupported or unrecognized command. */
NYAN_EXE_IDLE /**< System is in an idle state, not currently executing any command. */
} NyanExe;
Expand Down Expand Up @@ -100,6 +105,8 @@ typedef struct {
typedef struct {
bool send_welcome_screen; /**< Flag to indicate if the welcome screen should be sent. Initialized to false. */
uint8_t send_welcome_screen_guard; /**< Timer value to prevent multiple welcome screens. */
bool dfu_mode; /**< Boolean representing if Nyan Keys should enter a DFU mode */
bool dfu_counter; /**< Number of counts to let capacitor charge up, to enable BOOT0 to go high */
char exe_char; /**< ASCII character that triggers command evaluation. */

Eeprom24xx *eeprom; /**< Pointer to NyanOS EEPROM driver. */
Expand Down Expand Up @@ -284,4 +291,9 @@ void FreeNyanCommandArgs(volatile NyanOS* nos);
*/
void FreeNyanString(NyanString* nyanString);

/**
* @brief Pulls pin E0 high to charge capacitor to let Nyan Keys enter th DFU mode
*/
NyanReturn NyanEnterDFUMode(volatile NyanOS* nos);

#endif // NYAN_OS_H
3 changes: 3 additions & 0 deletions Core/Inc/nyan_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ extern const uint8_t nyan_keys_write_bitcoin_miner_nbits[];
//COMMAND: bitcoin-miner-set nonce
extern const uint8_t nyan_keys_write_bitcoin_miner_nonce[];

//COMMAND: dfu-mode
extern const uint8_t nyan_keys_enter_dfu_mode_reboot_warning[];

#endif // _NYAN_STRINGS
5 changes: 3 additions & 2 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ int main(void)
MX_TIM7_Init();
MX_TIM6_Init();
MX_TIM1_Init();
MX_USB_OTG_HS_PCD_Init();
MX_RNG_Init();
MX_TIM8_Init();
MX_TIM14_Init();
MX_USB_OTG_HS_PCD_Init();
/* USER CODE BEGIN 2 */
// Activate the STM32F7 timer interrupts
HAL_TIM_Base_Start_IT(&htim1);
Expand All @@ -151,8 +151,9 @@ int main(void)
#ifdef BITCOIN_MINER_EN
NyanBitcoinInit(&nyan_bitcoin); // Load up the bitcoin miner, comment this out or delete to disable.
#endif
/* USER CODE END 2 */
bool keys_dma_started = false;
/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
Expand Down
18 changes: 17 additions & 1 deletion Core/Src/nyan_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "main.h"
#include "24xx_eeprom.h"
#include "tim.h"
#include "usbd_cdc_acm_if.h"
#include "nyan_os.h"
#include "nyan_sha256.h"
#include "nyan_strings.h"
Expand Down Expand Up @@ -269,6 +268,16 @@ NyanReturn NyanExecute(volatile NyanOS* nos) {
nos->exe = NYAN_EXE_IDLE;
HAL_TIM_OC_Start_IT(&htim8, TIM_CHANNEL_1);
return NOS_SUCCESS;

case NYAN_EXE_DFU_MODE:
HAL_TIM_OC_Stop_IT(&htim8, TIM_CHANNEL_1);
nos->exe_in_progress = true;
NyanEnterDFUMode(nos);
NyanPrint(nos, (char*)&nyan_keys_enter_dfu_mode_reboot_warning[0], strlen((char*)nyan_keys_enter_dfu_mode_reboot_warning));
nos->exe_in_progress = false;
nos->exe = NYAN_EXE_IDLE;
HAL_TIM_OC_Start_IT(&htim8, TIM_CHANNEL_1);
return NOS_SUCCESS;

case NYAN_EXE_IDLE :
return NOS_SUCCESS;
Expand All @@ -287,6 +296,13 @@ NyanReturn NyanExecute(volatile NyanOS* nos) {
}
}

NyanReturn NyanEnterDFUMode(volatile NyanOS* nos)
{
nos->dfu_counter = 0;
nos->dfu_mode = true;
return NOS_SUCCESS;
}

NyanReturn NyanDecodeArgs(volatile NyanOS* nos)
{
if (!nos) {
Expand Down
3 changes: 3 additions & 0 deletions Core/Src/nyan_strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ const uint8_t nyan_keys_write_bitcoin_miner_nbits[] = "Nyan BitCoin Miner nbits

//COMMAND: bitcoin-miner-set nonce
const uint8_t nyan_keys_write_bitcoin_miner_nonce[] = "Nyan BitCoin Miner nonce set successfully.\r\n";

//COMMAND: dfu-mode
const uint8_t nyan_keys_enter_dfu_mode_reboot_warning[] = "Nyan Keys entering DFU mode and rebooting\r\n";
14 changes: 14 additions & 0 deletions Core/Src/stm32f7xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,20 @@ void SPI2_IRQHandler(void)
/* USER CODE END SPI2_IRQn 1 */
}

/**
* @brief This function handles TIM8 update interrupt and TIM13 global interrupt.
*/
void TIM8_UP_TIM13_IRQHandler(void)
{
/* USER CODE BEGIN TIM8_UP_TIM13_IRQn 0 */

/* USER CODE END TIM8_UP_TIM13_IRQn 0 */
HAL_TIM_IRQHandler(&htim8);
/* USER CODE BEGIN TIM8_UP_TIM13_IRQn 1 */

/* USER CODE END TIM8_UP_TIM13_IRQn 1 */
}

/**
* @brief This function handles TIM8 trigger and commutation interrupts and TIM14 global interrupt.
*/
Expand Down
2 changes: 1 addition & 1 deletion Core/Src/usb_otg.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
Expand Down
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [4.1.0] date: [Mon Jan 08 23:03:23 PST 2024]
# File automatically-generated by tool: [projectgenerator] version: [4.1.0] date: [Tue Jan 09 08:35:57 PST 2024]
##########################################################################################################################

# ------------------------------------------------
Expand Down Expand Up @@ -76,7 +76,6 @@ Core/Src/iceuncompr.c \
Core/Src/lattice_ice_hx.c \
Core/Src/24xx_eeprom.c \
Core/Src/tim.c \
Core/Src/usb_otg.c \
Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/COMPOSITE/Src/usbd_composite.c \
Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/HID_KEYBOARD/Src/usbd_hid_keyboard.c \
Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Core/Src/usbd_core.c \
Expand All @@ -87,7 +86,8 @@ Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/App/usbd_desc.c \
Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Target/usbd_conf.c \
Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/CDC_ACM/Src/usbd_cdc_acm.c \
Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/App/usbd_cdc_acm_if.c \
Core/Src/dma.c
Core/Src/dma.c \
Core/Src/usb_otg.c

# ASM sources
ASM_SOURCES = \
Expand Down Expand Up @@ -152,10 +152,12 @@ C_INCLUDES = \
-IComposite \
-IMiddlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/COMPOSITE/Inc \
-IMiddlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/HID_KEYBOARD/Inc \
-IMiddlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/CDC_ACM/Inc \
-IMiddlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Core/Inc \
-IMiddlewares/Third_Party/AL94_USB_Composite/COMPOSITE/App \
-IMiddlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Target \
-IMiddlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/CDC_ACM/Inc
-IMiddlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Target \
-IMiddlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Target



# compile gcc flags
Expand Down
Loading

0 comments on commit eeb700a

Please sign in to comment.