Skip to content
Snippets Groups Projects
Select Git revision
  • 2766e2f19f49f25b63164b9c7342e705fdc27a6f
  • master default protected
  • ws2812_docs_work
  • ws2812_module_work
  • genofire/ble-card10-timeread
  • schneider/fundamental-test
  • schneider/ble-buffers
  • ios-workarounds
  • schneider/maxim-sdk-update
  • rahix/simple_menu
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • koalo/wip/i2c-for-python
  • renze/safe_mode
  • renze/hatchery_apps
  • koalo/factory-reset
  • msgctl/gfx_rle
  • msgctl/faultscreen
  • msgctl/textbuffer_api
  • schneider/bonding
  • schneider/bootloader-update-9a0d158
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
30 results

flash-all.gdb

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    main.c 18.05 KiB
    #include <stm32f4xx.h>
    #include <stm32f4xx_rcc.h>
    #include <stm32f4xx_gpio.h>
    #include <stm_misc.h>
    #include "std.h"
    
    #include "misc.h"
    #include "systick.h"
    #include "led.h"
    #include "lcd.h"
    #include "storage.h"
    #include "usb.h"
    
    static void impl02_c_version() {
        int x = 0;
        while (x < 400) {
            int y = 0;
            while (y < 400) {
                volatile int z = 0;
                while (z < 400) {
                    z = z + 1;
                }
                y = y + 1;
            }
            x = x + 1;
        }
    }
    
    void set_bits(__IO uint32_t *addr, uint32_t shift, uint32_t mask, uint32_t value) {
        uint32_t x = *addr;
        x &= ~(mask << shift);
        x |= (value << shift);
        *addr = x;
    }
    
    void gpio_init() {
        RCC->AHB1ENR |= RCC_AHB1ENR_CCMDATARAMEN | RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOAEN;
    }
    
    /*
    void gpio_pin_af(GPIO_TypeDef *gpio, uint32_t pin, uint32_t af) {
        // set the AF bits for the given pin
        // pins 0-7 use low word of AFR, pins 8-15 use high word
        set_bits(&gpio->AFR[pin >> 3], 4 * (pin & 0x07), 0xf, af);
    }
    */
    
    static void mma_init() {
        // XXX
        RCC->APB1ENR |= RCC_APB1ENR_I2C1EN; // enable I2C1
        //gpio_pin_init(GPIOB, 6 /* B6 is SCL */, 2 /* AF mode */, 1 /* open drain output */, 1 /* 25 MHz */, 0 /* no pull up or pull down */);
        //gpio_pin_init(GPIOB, 7 /* B7 is SDA */, 2 /* AF mode */, 1 /* open drain output */, 1 /* 25 MHz */, 0 /* no pull up or pull down */);
        //gpio_pin_af(GPIOB, 6, 4 /* AF 4 for I2C1 */);
        //gpio_pin_af(GPIOB, 7, 4 /* AF 4 for I2C1 */);
    
        // get clock speeds
        RCC_ClocksTypeDef rcc_clocks;
        RCC_GetClocksFreq(&rcc_clocks);
    
        // disable the I2C peripheral before we configure it
        I2C1->CR1 &= ~I2C_CR1_PE;
    
        // program peripheral input clock
        I2C1->CR2 = 4; // no interrupts; 4 MHz (hopefully!) (could go up to 42MHz)
    
        // configure clock control reg
        uint32_t freq = rcc_clocks.PCLK1_Frequency / (100000 << 1); // want 100kHz, this is the formula for freq
        I2C1->CCR = freq; // standard mode (speed), freq calculated as above
    
        // configure rise time reg