Skip to content

Commit

Permalink
switch to f767 chip
Browse files Browse the repository at this point in the history
  • Loading branch information
trentgill committed Dec 21, 2023
1 parent 7027d29 commit 2558219
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 66 deletions.
29 changes: 8 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ FENNEL=fennel
# BIN=$(CP) -O ihex
BIN = $(TARGET).bin

DEFS = -DUSE_STDPERIPH_DRIVER -DSTM32F7XX -DARM_MATH_CM7 -DHSE_VALUE=8000000
DEFS += -DSTM32F722xx -DUSE_HAL_DRIVER
STARTUP = $(CUBE)/CMSIS/Device/ST/STM32F7xx/Source/Templates/gcc/startup_stm32f722xx.s
DEFS = -DUSE_STDPERIPH_DRIVER -DSTM32F7XX -DARM_MATH_CM7 -DHSE_VALUE=25000000
DEFS += -DSTM32F7xx -DUSE_HAL_DRIVER
STARTUP = $(CUBE)/CMSIS/Device/ST/STM32F7xx/Source/Templates/gcc/startup_stm32f767xx.s

MCFLAGS = -mthumb -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16
MCFLAGS = -mthumb -march=armv7e-m -mfloat-abi=hard -mfpu=fpv5-d16

STM32_INCLUDES = \
-I$(WRLIB)/ \
Expand Down Expand Up @@ -232,18 +232,17 @@ $(BIN): $(EXECUTABLE)
@echo "symbol table: $@.dmp"
@echo "Release: "$(R)
@$(GETSIZE) $(BIN) | grep 'Size'
@echo " ^ must be less than 384kB (384,000)"
# 512kb -64kb(bootloader) -128kb(scripts)
@echo " ^ must be less than 1MB (1,024,000)"

flash: $(BIN)
st-flash write $(BIN) 0x08020000
st-flash write $(BIN) 0x08000000

debug:
make flash TRACE=1
stlink-trace -c 216

dfu: $(BIN)
sudo dfu-util -a 0 -s 0x08020000 -R -D $(BIN) -d ,0483:df11
sudo dfu-util -a 0 -s 0x08000000 -R -D $(BIN) -d ,0483:df11

dfureset:
@stty -F /dev/ttyACM0 raw speed 115200
Expand All @@ -254,7 +253,7 @@ pydfu: $(TARGET).dfu $(BIN)
@python3 util/pydfu.py -u $<

$(TARGET).dfu: $(BIN)
python3 util/dfu.py -D 0x0483:0xDF11 -b 0x08020000:$^ $@
python3 util/dfu.py -D 0x0483:0xDF11 -b 0x08000000:$^ $@

boot:
cd $(BOOTLOADER) && \
Expand Down Expand Up @@ -303,21 +302,9 @@ Startup.o: $(STARTUP)
@$(CC) $(CFLAGS) -c $< -o $@
@echo $@

wav: fsk-wav

fsk-wav: $(BIN)
export PYTHONPATH=$$PYTHONPATH:'.' && \
cd .. && python stm-audio-bootloader/fsk/encoder.py \
-s 48000 -b 16 -n 8 -z 4 -p 256 -g 16384 -k 1800 \
$(PRJ_DIR)/$(BIN)

erase:
st-flash erase

norns:
lua util/ii_norns_actions.lua lua/ii/ $(NORNS_DIR)/lua/core/crow/ii_actions.lua
lua util/ii_norns_events.lua lua/ii/ $(NORNS_DIR)/lua/core/crow/ii_events.lua

.PHONY: clean
clean:
@rm -rf Startup.lst $(TARGET).elf.lst $(OBJS) $(AUTOGEN) \
Expand Down
5 changes: 3 additions & 2 deletions ll/debug_pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ void Debug_Pin_Init( void );
void Debug_Pin_Set( uint8_t state );

// Hardware Abstraction Defines
#define DBG_P_RCC_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
// this is the top most LED to the right of the uC
#define DBG_P_RCC_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define DBG_P_PIN GPIO_PIN_9
#define DBG_P_GPIO GPIOB
#define DBG_P_GPIO GPIOA
10 changes: 5 additions & 5 deletions ll/status_led.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <stdbool.h>

// LED on GPIO A15
// LED on GPIO A8 (second led from top)

static GPIO_InitTypeDef GPIO_IS;
static LED_SPEED fast_blink;
Expand All @@ -12,7 +12,7 @@ void status_led_init(void){
// activate peripheral clock
__HAL_RCC_GPIOA_CLK_ENABLE();
// set constant params of gpio init struct
GPIO_IS.Pin = GPIO_PIN_15;
GPIO_IS.Pin = GPIO_PIN_8;
GPIO_IS.Pull = GPIO_NOPULL;
GPIO_IS.Speed = GPIO_SPEED_LOW;
GPIO_IS.Mode = GPIO_MODE_OUTPUT_PP;
Expand All @@ -27,7 +27,7 @@ void status_led_tick(uint32_t time_now){
if(time_now > next_flip // time to animate timer
|| (do_flip && fast_blink)){ // xor event & USB connected
// status_led_xor();
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_15);
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_8);
next_flip = time_now + (fast_blink ? 2000 : 500);
do_flip = false;
}
Expand All @@ -38,10 +38,10 @@ void status_led_fast(LED_SPEED is_fast){
}

void status_led_set(uint8_t is_on){
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, is_on);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, is_on);
}

void status_led_xor(void){
// HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_15);
// HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_8);
do_flip = true;
}
30 changes: 26 additions & 4 deletions ll/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,43 @@ void system_print_identity(void)
}

// private definitions
/**
* @brief System Clock Configuration
* The system Clock is configured as follow :
* System Clock source = PLL (HSE)
* SYSCLK(Hz) = 216000000
* HCLK(Hz) = 216000000
* AHB Prescaler = 1
* APB1 Prescaler = 4
* APB2 Prescaler = 2
* HSE Frequency(Hz) = 25000000
* PLL_M = 25
* PLL_N = 432
* PLL_P = 2
* PLL_Q = 9
* PLL_R = 7
* VDD(V) = 3.3
* Main regulator output voltage = Scale1 mode
* Flash Latency(WS) = 7
* @param None
* @retval None
*/
static void Sys_Clk_Config(void)
{
__HAL_RCC_PWR_CLK_ENABLE();

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

static RCC_OscInitTypeDef osc;
osc.OscillatorType = RCC_OSCILLATORTYPE_HSE;
osc.HSEState = RCC_HSE_ON;
osc.PLL.PLLState = RCC_PLL_ON;
osc.PLL.PLLSource = RCC_PLLSOURCE_HSE;
osc.PLL.PLLM = 8;
osc.PLL.PLLM = 25;
osc.PLL.PLLN = 432;
osc.PLL.PLLP = RCC_PLLP_DIV2;
osc.PLL.PLLQ = 9;
osc.PLL.PLLR = 7;
if(HAL_RCC_OscConfig(&osc) != HAL_OK){ Error_Handler(); }

if(HAL_PWREx_EnableOverDrive() != HAL_OK) { Error_Handler(); }
Expand Down Expand Up @@ -86,7 +108,7 @@ static void MPU_Config(void)
// mpu.Enable = MPU_REGION_DISABLE;
// mpu.BaseAddress = 0x20020000;
mpu.BaseAddress = 0x20000000;
mpu.Size = MPU_REGION_SIZE_256KB;
mpu.Size = MPU_REGION_SIZE_512KB;
mpu.AccessPermission = MPU_REGION_FULL_ACCESS;
mpu.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
mpu.IsCacheable = MPU_ACCESS_CACHEABLE;
Expand Down Expand Up @@ -115,7 +137,7 @@ static void Error_Handler(void)

unsigned int getUID_Word( unsigned int offset )
{
const uint32_t base = 0x1FF07A10;
const uint32_t base = 0x1FF0F420;
//return (uint32_t)(READ_REG(*((uint32_t*)(UID_BASE + offset))));
//return (uint32_t)(READ_REG(UID_BASE + offset));
uint32_t* x = (uint32_t*)(base + offset);
Expand Down
18 changes: 12 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,28 @@ int main(void)

// Debugging
Debug_Pin_Init();
Debug_USART_Init(); // ignored in TRACE mode
//Debug_USART_Init(); // ignored in TRACE mode
// User-readable status led
status_led_init();
status_led_fast(LED_SLOW); // slow blink until USB connection goes live
status_led_set(1); // set status to ON to show sign of life straight away

printf("\n\nhi from crow!\n");
printf("\n\nhi from test platform!\n");

// Drivers
int max_timers = Timer_Init();
IO_Init( max_timers-2 ); // use second-last timer
IO_Start(); // must start IO before running lua init() script
// IO_Init( max_timers-2 ); // use second-last timer
// IO_Start(); // must start IO before running lua init() script
events_init();
Metro_Init( max_timers-2 ); // reserve 2 timers for USB & ADC
clock_init( 100 ); // TODO how to pass it the timer?

status_led_set(0); // set status to ON to show sign of life straight away

Caw_Init( max_timers-1 ); // use last timer
CDC_clear_buffers();

i2c_hw_pullups_init(); // enable GPIO for v1.1 hardware pullups
// i2c_hw_pullups_init(); // enable GPIO for v1.1 hardware pullups
ii_init( II_CROW );
Random_Init();

Expand All @@ -54,6 +57,7 @@ int main(void)
Lua_crowbegin();

uint32_t last_tick = HAL_GetTick();
int a = 0;
while(1){
CPU_count++;
U_PrintNow();
Expand All @@ -62,7 +66,7 @@ int main(void)
, Caw_get_read_len()
, Caw_send_luaerror
); break;
case C_boot: bootloader_enter(); break;
case C_boot: bootloader_enter(); break; // BROKEN ON TEST PLATFORM
case C_startupload: REPL_begin_upload(); break;
case C_endupload: REPL_upload(0); break;
case C_flashupload: REPL_upload(1); break;
Expand All @@ -85,5 +89,7 @@ int main(void)
event_next(); // check/execute single event
ii_leader_process();
Caw_send_queued();
Debug_Pin_Set(!a);
a ^= 1;
}
}
6 changes: 3 additions & 3 deletions stm32_flash.ld
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = 0x20040000; /* end of 256K RAM */
_estack = 0x20080000; /* end of 512K RAM */

/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x200; /* required amount of heap */
Expand All @@ -41,8 +41,8 @@ _Min_Stack_Size = 0x10000; /* required amount of stack */
MEMORY
{
/* FLASH (rx) : ORIGIN = 0x00200000, LENGTH = 512K */ /* ITCM interface */
FLASH (rx) : ORIGIN = 0x08020000, LENGTH = 384K /* AXIM interface */
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K /* AXIM interface. prob actually 2MB*/
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 512K
/* MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K */
/* CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K */
}
Expand Down
4 changes: 2 additions & 2 deletions stm32f7xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@
/* #define STM32F745xx */ /*!< STM32F745VE, STM32F745VG, STM32F745ZG, STM32F745ZE, STM32F745IE, STM32F745IG Devices */
/*#define STM32F765xx */ /*!< STM32F765BI, STM32F765BG, STM32F765NI, STM32F765NG, STM32F765II, STM32F765IG,
STM32F765ZI, STM32F765ZG, STM32F765VI, STM32F765VG Devices */
/* #define STM32F767xx */ /*!< STM32F767BG, STM32F767BI, STM32F767IG, STM32F767II, STM32F767NG, STM32F767NI,
#define STM32F767xx /*!< STM32F767BG, STM32F767BI, STM32F767IG, STM32F767II, STM32F767NG, STM32F767NI,
STM32F767VG, STM32F767VI, STM32F767ZG, STM32F767ZI Devices */
/*#define STM32F769xx*/ /*!< STM32F769AG, STM32F769AI, STM32F769BG, STM32F769BI, STM32F769IG, STM32F769II,
STM32F769NG, STM32F769NI, STM32F768AI Devices */
/* #define STM32F777xx */ /*!< STM32F777VI, STM32F777ZI, STM32F777II, STM32F777BI, STM32F777NI Devices */
/* #define STM32F779xx */ /*!< STM32F779II, STM32F779BI, STM32F779NI, STM32F779AI, STM32F778AI Devices */
#define STM32F722xx /*!< STM32F722IE, STM32F722ZE, STM32F722VE, STM32F722RE, STM32F722IC, STM32F722ZC,
/* #define STM32F722xx */ /*!< STM32F722IE, STM32F722ZE, STM32F722VE, STM32F722RE, STM32F722IC, STM32F722ZC,
STM32F722VC, STM32F722RC Devices */
/* #define STM32F723xx */ /*!< STM32F723IE, STM32F723ZE, STM32F723VE, STM32F723IC, STM32F723ZC, STM32F723VC Devices */
/* #define STM32F732xx */ /*!< STM32F732IE, STM32F732ZE, STM32F732VE, STM32F732RE Devices */
Expand Down
8 changes: 4 additions & 4 deletions stm32f7xx_hal_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
* @brief This is the list of modules to be used in the HAL driver
*/
#define HAL_MODULE_ENABLED
/*#define HAL_ADC_MODULE_ENABLED*/
#define HAL_ADC_MODULE_ENABLED
/*#define HAL_CAN_MODULE_ENABLED*/
/*#define HAL_CEC_MODULE_ENABLED*/
/*#define HAL_CRC_MODULE_ENABLED*/
/*#define HAL_CRYP_MODULE_ENABLED*/
/*#define HAL_DAC_MODULE_ENABLED*/
/*#define HAL_DCMI_MODULE_ENABLED*/
#define HAL_DMA_MODULE_ENABLED
#define HAL_DMA2D_MODULE_ENABLED
// #define HAL_DMA2D_MODULE_ENABLED
/*#define HAL_ETH_MODULE_ENABLED*/
#define HAL_FLASH_MODULE_ENABLED
/*#define HAL_NAND_MODULE_ENABLED*/
Expand All @@ -78,7 +78,7 @@
#define HAL_RCC_MODULE_ENABLED
#define HAL_RNG_MODULE_ENABLED
/*#define HAL_RTC_MODULE_ENABLED*/
/*#define HAL_SAI_MODULE_ENABLED*/
#define HAL_SAI_MODULE_ENABLED
/*#define HAL_SD_MODULE_ENABLED*/
/*#define HAL_SPDIFRX_MODULE_ENABLED*/
#define HAL_SPI_MODULE_ENABLED
Expand All @@ -104,7 +104,7 @@
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)8000000U) /*!< Value of the External oscillator in Hz */
#define HSE_VALUE ((uint32_t)25000000U) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */

#if !defined (HSE_STARTUP_TIMEOUT)
Expand Down
4 changes: 2 additions & 2 deletions system_stm32f7xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#include "stm32f7xx.h"

#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz */
#define HSE_VALUE ((uint32_t)25000000) /*!< Default value of the External oscillator in Hz */
#endif /* HSE_VALUE */

#if !defined (HSI_VALUE)
Expand Down Expand Up @@ -97,7 +97,7 @@
/*!< Uncomment the following line if you need to relocate your vector Table in
Internal SRAM. */
/* #define VECT_TAB_SRAM */
#define VECT_TAB_OFFSET 0x20000 /*!< Vector Table base offset field.
#define VECT_TAB_OFFSET 0x00000 /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
/******************************************************************************/

Expand Down
28 changes: 14 additions & 14 deletions usbd/usbd_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,21 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

if(hpcd->Init.vbus_sensing_enable == 1)
{
/* Configure VBUS Pin */
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
// if(hpcd->Init.vbus_sensing_enable == 1)
// {
// /* Configure VBUS Pin */
// GPIO_InitStruct.Pin = GPIO_PIN_9;
// GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
// GPIO_InitStruct.Pull = GPIO_NOPULL;
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// }

/* Configure ID pin */
GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// GPIO_InitStruct.Pin = GPIO_PIN_10;
// GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
// GPIO_InitStruct.Pull = GPIO_PULLUP;
// GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* Enable USB FS Clock */
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
Expand Down Expand Up @@ -396,7 +396,7 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
hpcd.Init.phy_itface = PCD_PHY_EMBEDDED;
hpcd.Init.Sof_enable = 0;
hpcd.Init.speed = PCD_SPEED_FULL;
hpcd.Init.vbus_sensing_enable = 1;
hpcd.Init.vbus_sensing_enable = 0;
hpcd.Init.lpm_enable = 0;

/* Link The driver to the stack */
Expand Down
10 changes: 7 additions & 3 deletions usbd/usbd_desc.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
// TODO: BIG NOTE: THIS IS REQUIRED FOR F722! FAILS W F756 or other device_id!!
#define DEVICE_ID1 (0x1FF07A10)
#define DEVICE_ID2 (0x1FF07A14)
#define DEVICE_ID3 (0x1FF07A18)
// #define DEVICE_ID1 (0x1FF07A10)
// #define DEVICE_ID2 (0x1FF07A14)
// #define DEVICE_ID3 (0x1FF07A18)
// these values for f769
#define DEVICE_ID1 (0x1FFF7A10)
#define DEVICE_ID2 (0x1FFF7A14)
#define DEVICE_ID3 (0x1FFF7A18)

#define USB_SIZ_STRING_SERIAL 0x1A
/* Exported macro ------------------------------------------------------------*/
Expand Down

0 comments on commit 2558219

Please sign in to comment.